www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - a short null dereference story

reply Basile B. <b2.temp gmx.com> writes:
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 me

 src/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
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
parent Basile B. <b2.temp gmx.com> writes:
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:
 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
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).
Dec 07
prev sibling next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
https://github.com/dlang/dmd/pull/22040
Dec 05
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
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
parent Basile B. <b2.temp gmx.com> writes:
On Monday, 8 December 2025 at 02:58:48 UTC, Walter Bright wrote:
 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: [...] Program received signal SIGSEGV, Segmentation fault. D main () at ./test.d:8 8 return s.a;
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.
Dec 07