Bug 573 – Segfault from version(release) statement
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-11-19T16:34:00Z
Last change time
2014-02-15T13:20:17Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
daekharel
Comments
Comment #0 by daekharel — 2006-11-19T16:34:39Z
void main() { version (release) {} else { assert(0); } }
-------
The above throws an AssertError, as it should, when compiled & linked normally and run. However, when compiled with the "-release" flag, it segfaults when run instead of doing nothing, as it should. Strangely, if it is compiled with "-v=release", it runs without error.
Comment #1 by daekharel — 2006-11-20T17:11:12Z
Whoops. Looks like I misinterpreted what -release does: it doesn't switch the "release" version flag, and it removes assertions (or at least simple ones like assert(0)), replacing them by stuff that causes segfaults.
I'll assume there's a good reason for the segfault behavior (probably has something to do with assert(0) signifying unreachable code), but in any case, this bug is invalid.
Comment #2 by jarrett.billingsley — 2006-11-20T18:43:39Z
Ah, sorry, I guess I should have posted my reply here instead of on the newsgroups.
assert(0) is treated as a special case, and when
compiled in release mode, they are left in and execute an illegal
instruction.
Comment #3 by afb — 2006-11-21T08:20:27Z
Walter Bright wrote:
>> assert(0) is treated as a special case, and when compiled in release
>> mode, they are left in and execute an illegal instruction.
>
> Not precisely an illegal instruction, but a HLT (or equivalent)
> instruction, which works like a break point when running it under a
> debugger.
On PowerPC it does a "trap" instruction which also has that effect:
Program received signal SIGTRAP, Trace/breakpoint trap.
_Dmain () at halt.d:3
3 assert(0);
(gdb)
--anders