checkedint call removal
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 28 06:17:03 PDT 2014
On Monday, 28 July 2014 at 12:53:20 UTC, John Colvin wrote:
>> int c;
>>
>> void foo(int a)
>> {
>> if(a < 0) c++;
>> assert(a > 0);
>> }
>>
>> I presume that cannot be optimised away entirely to:
>>
>> void foo(int a) {}
>>
>> ?
>
> sorry, I mean
>
> void foo(int a)
> {
> assert(a > 0);
> }
>
> of course you can't optimise away the check.
Please guys, you should not change code-gen based on asserts.
They are not proofs, they are candidates for formal verification
of correctness. They are in essence embedded break-point checks.
If you allow asserts to affect codegen then it becomes a very
unsafe feature. It's like having a undetected bug in a unit-test
introduce bugs in the released program. 8-I
Anyway, without a barrier, you probably could do code motion if
you know that you will reach HALT and that is considered illegal.
For system programming language reaching HALT should probably be
considered legal and you cannot do code motion based on that. In
essence, when and where you can move code depends on barriers…
But since you don't actually get HALT from assert() in release
mode, it makes no sense to argue the point either…
More information about the Digitalmars-d
mailing list