www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 573] New: Segfault from version(release) statement

reply d-bugmail puremagic.com writes:
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.


-- 
Nov 19 2006
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<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.
Nov 19 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=573


daekharel gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





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.


-- 
Nov 20 2006
prev sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=573






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.  


-- 
Nov 20 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
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.
Nov 20 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
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
Nov 21 2006