Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 19, 2006 [Issue 573] New: Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=573 Summary: Segfault from version(release) statement Product: D Version: 0.174 Platform: PC OS/Version: Linux Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: daekharel@gmail.com 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. -- |
November 20, 2006 Re: [Issue 573] New: Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | <d-bugmail@puremagic.com> wrote in message news:bug-573-3@http.d.puremagic.com/issues/... > http://d.puremagic.com/issues/show_bug.cgi?id=573 > > Summary: Segfault from version(release) statement > Product: D > Version: 0.174 > Platform: PC > OS/Version: Linux > Status: NEW > Keywords: wrong-code > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: bugzilla@digitalmars.com > ReportedBy: daekharel@gmail.com > > > 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. You sure about that? assert(0) is treated as a special case, and when compiled in release mode, they are left in and execute an illegal instruction. > Strangely, if it is compiled with > "-v=release", it runs without error. AFAIK there is no "release" version defined when you use the -release flag. Therefore, the code is doing exactly as it should -- it compiles in the "else" clause in release mode, causing an exception when the program is run. But when you manually define the "release" version, it skips the "else" and leaves the assert out. |
November 20, 2006 [Issue 573] Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=573 daekharel@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from daekharel@gmail.com 2006-11-20 17:11 ------- 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. -- |
November 21, 2006 [Issue 573] Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=573 ------- Comment #2 from jarrett.billingsley@gmail.com 2006-11-20 18:43 ------- 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. -- |
November 21, 2006 Re: [Issue 573] Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | d-bugmail@puremagic.com 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.
|
November 21, 2006 Re: [Issue 573] Segfault from version(release) statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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
|
Copyright © 1999-2021 by the D Language Foundation