digitalmars.D - a short null dereference story
- Basile B. (10/12) Dec 05 Just wake up this morning with the idea to run my test suite with
- Adam D. Ruppe (3/5) Dec 05 OpenD has had this for about 5 months now:
- Basile B. (6/11) Dec 07 Yes this is more or less the same.
- Richard (Rikki) Andrew Cattermole (1/1) Dec 05 https://github.com/dlang/dmd/pull/22040
- Walter Bright (35/36) Dec 07 ```d
- Basile B. (6/22) Dec 07 Yes but the code instrumentation approach gives the opportunity
Just wake up this morning with the idea to run my test suite with an optimized compiler. Turn out that it was impossible to compile the optimized version of the compiler. That gave mesrc/styx/ast/visitor.sx:137:18: runtime error, member read with null `this`bounds checks are nice but when you are still with dealing objects allocated on the heap that kind of verification help a lot. So for D the equivalent would be to generate a check on each DotVarExp. Have a nice week-end. Baz.
Dec 05
On Friday, 5 December 2025 at 20:58:32 UTC, Basile B. wrote:So for D the equivalent would be to generate a check on each DotVarExp.OpenD has had this for about 5 months now: https://dpldocs.info/this-week-in-d/Blog.Posted_2025_06_09.html
Dec 05
On Friday, 5 December 2025 at 21:03:00 UTC, Adam D. Ruppe wrote:On Friday, 5 December 2025 at 20:58:32 UTC, Basile B. wrote:Yes this is more or less the same. I read that you mentioned the low **runtime** cost... what I've observed, over the years, is that the check is very costly **to generate**. I've mitigated the problem by adding a [` plain` attribute](https://styx-lang.gitlab.io/styx/attribute.html#plainattribute).So for D the equivalent would be to generate a check on each DotVarExp.OpenD has had this for about 5 months now: https://dpldocs.info/this-week-in-d/Blog.Posted_2025_06_09.html
Dec 07
On 12/5/2025 12:58 PM, Basile B. wrote:So for D the equivalent would be to generate a check on each DotVarExp.```d struct S { int a; } int main() { S* s = null; return s.a; } ``` compile: dmd test.d -g run: gdb test GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from test...done. (gdb) run Starting program: /home/walter/forks/dmd/compiler/src/bug2/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. D main () at ./test.d:8 8 return s.a;
Dec 07
On Monday, 8 December 2025 at 02:58:48 UTC, Walter Bright wrote:On 12/5/2025 12:58 PM, Basile B. wrote:Yes but the code instrumentation approach gives the opportunity to fix the invalid read without running in the debugger. Also note that the runtime error indicates the column. GDB is not that precise (DWARF attrib DW_AT_decl_column is never used), so for `x.s.a` you have to evaluate `x` then `s` to be sure.So for D the equivalent would be to generate a check on each DotVarExp.```d struct S { int a; } int main() { S* s = null; return s.a; } ``` compile: [...] Program received signal SIGSEGV, Segmentation fault. D main () at ./test.d:8 8 return s.a;
Dec 07









Basile B. <b2.temp gmx.com> 