What's the deal with -boundscheck?
Brad Anderson via Digitalmars-d
digitalmars-d at puremagic.com
Sun Apr 5 23:25:12 PDT 2015
On Monday, 6 April 2015 at 05:15:43 UTC, Walter Bright wrote:
> On 4/5/2015 7:13 PM, Andrei Alexandrescu wrote:
>> I've spent the better part of yesterday and today debugging a
>> complex matter
>> involving pointers, reduced to this:
>>
>> ../dmd/src/dmd -conf= -I../druntime/import -w -dip25 -m64 -O
>> -release -main
>> -unittest generated/osx/release/64/libphobos2.a -defaultlib=
>> -debuglib= -L-lcurl
>> -run std/experimental/allocator/kernighan_ritchie.d
>>
>> In this configuration, surprisingly there's no bounds checks
>> inserted. I need to
>> explicitly add -boundcheck=on.
>>
>> Why the change? I've fought tooth and nail for keeping bounds
>> checking in
>> release mode and with optimizations on, precisely because I
>> think it's a check
>> that's valuable enough to warrant explicit disabling.
>>
>> Could someone please explain. This is a shame.
>
> I read the code to figure out what was happening.
>
> At some point, -release was changed so that bounds checking was
> turned off for all but @safe code.
You made that change back in 2009.
https://issues.dlang.org/show_bug.cgi?id=3407
-release used to turn off all bounds checking. Andrei wanted it
to stay in safe code at least so you added -noboundscheck to
appease those that wanted it off even in safe code then you made
it do bounds checking by default in safe code even if -release
was specified. There was never an option to turn on bounds
checking for all code in release mode (not until -boundscheck=on
was added). Whenever we'd discuss -noboundcheck on the forums
you'd have 5 people with 5 different ideas about what that option
did. It was very confusing.
> A new switch was added, -boundscheck=[on|safeonly|off]. It took
> me a while to find it at:
>
> http://dlang.org/dmd-linux.html
>
> because whoever added it didn't realize that the list was
> alphabetized and stuck it in there after -map.
>
Yep, I didn't notice that.
> I don't know why the change was made.
Several reasons which I'll reproduce here from bugzilla[1]:
---
1. What -noboundscheck actually does is confusing. Its purpose is
to turn off bounds checking in @safe code (and all other code)
which comes as a surprise to a lot of people. -release turns off
bounds checking in non- at safe code (which also surprises some
people) but leaves it on for @safe code.
2. There is currently no way to turn on bounds checking for
release builds currently.
3. There is currently no way to turn off bounds checking for
non- at safe code without pulling in everything -release does (or
turning off bounds checking for @safe code too).
---
No bounds checking defaults were affected by my change (or
shouldn't have been, if they were it's a bug). What Andrei wants
couldn't be done before this option was added.
1. https://issues.dlang.org/show_bug.cgi?id=12550
More information about the Digitalmars-d
mailing list