Overflows in Phobos

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 26 23:49:19 PDT 2016


On 27/07/16 08:50, Walter Bright wrote:
> On 7/26/2016 10:24 PM, Shachar Shemesh wrote:
>> Most D programmers, however, expect the program not to continue
>> executing past
>> an assert(false). They might see it as a bug. Hence my question
>> whether that
>> means D is not meant for programming in privileged mode.
>
> Obviously, HALT means any instruction of sequence of instructions that
> stops the program from running. Some machines don't even have a HLT
> instruction. Do you want to make a stab at writing this for the spec?
>

Current text (after the strange copying corruption):
> The expression assert(0) is a special case; it signies that it is unreachable code. Either
> AssertError is thrown at runtime if it is reachable, or the execution is halted (on the x86 processor,
> a HLT instruction can be used to halt execution). The optimization and code generation phases of
> compilation may assume that it is unreachable code.

Proposed text:
The expression assert(0) is a special case; it signifies code that 
should be unreachable. Either AssertError is thrown at runtime if 
reached, or the assert message printed to stderr and execution 
terminated. The optimization and code generation phases of the 
compilation may assume that any code after the assert(0) is unreachable.

Main differences:
* Some phrasing improvements
* Change the confusing "is unreachable" (so why bother?) with "should be 
unreachable", which stresses it's usefulness (and avoids the opinion, 
expressed in this thread, that reaching it is UB)
* Remove the recommendation to use HLT on X86, which, as discussed, is 
plainly wrong
* Define the behavior symptomatically, allowing both more certainty for 
programmers relying on the specs to know what will happen, and for 
compiler implementers more freedom to choose the correct way to achieve 
this effect and handle resulting bugs.
* Add the requirement that the assert message be printed for assert(0)

Shachar


More information about the Digitalmars-d mailing list