Bug 15302 – DMD -O optimizing out meaningful code

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2015-11-08T15:50:00Z
Last change time
2016-03-25T07:27:41Z
Keywords
wrong-code
Assigned to
nobody
Creator
ketmar

Comments

Comment #0 by ketmar — 2015-11-08T15:50:20Z
compiling the following code with "dmd -O" leading to failed assert. seems that dmd optimized out "lineNumber++;", failing to see that it is used in "catch" part. === class XException : Exception { this (string msg, size_t lineNumber, string file=__FILE__, size_t line=__LINE__, Throwable next=null) pure nothrow @safe { super(msg, file, line, next); _lineNumber = lineNumber; } @nogc @safe size_t lineNumber() const nothrow { return _lineNumber; } private: size_t _lineNumber; } void foo (string[] lines) { size_t lineNumber = 0; try { foreach (line; lines) { lineNumber++; if (line == "Line3") throw new Exception("!"); } } catch (Exception e) { throw new XException(e.msg, lineNumber, e.file, e.line, e.next); } } void main () { try { foo(["Line", "AnotherLine", "Line3"]); } catch (XException e) { assert(e.lineNumber == 3); } }
Comment #1 by ketmar — 2015-11-08T15:51:07Z
p.s. bug found by FreeSlave and posted in IRC channel.
Comment #2 by yebblies — 2016-03-25T07:27:41Z
Looks like the same issue with missing successors on catch blocks *** This issue has been marked as a duplicate of issue 10966 ***