D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.

Issue 2923

Summary: -O generates bad code for ?:
Product: D Reporter: xurux1-mail
Component: dmdAssignee: No Owner <nobody>
Status: RESOLVED FIXED
Severity: regression CC: bugzilla, clugdbug
Priority: P2 Keywords: wrong-code
Version: D1 (retired)
Hardware: x86
OS: Windows

Description xurux1-mail 2009年05月02日 13:45:37 UTC
adding the -inline option produces wrong output, both with
Digital Mars D Compiler v1.043,
Digital Mars D Compiler v2.029
on windows.
import std.stdio; //writefln
int my_abs(int i) {
 return i<0 ? -i : i;
}
void main(char[][] args) {
 int rows=9;
 int mid=5;
 for (int j=0; j<rows; j++) {
 int leadSpaces=my_abs((mid-1)-j);
 for (int i=0; i<leadSpaces; i++)
 writef("-"); 
 //writefln("%d:%d",j,leadSpaces);
 writefln("!");
 }
}
/*
CORRECT:
C:\dev\d>dmd -release -O -run compiler_bug1.d
----!
---!
--!
-!
!
-!
--!
---!
----!
WRONG:
C:\dev\d>dmd -release -O -inline -run compiler_bug1.d
!
!
!
!
!
!
!
!
!
*/
Comment 1 Don 2009年05月15日 08:40:41 UTC
Reduced test case:
dmd bug.d //OK
dmd -O bug.d // fails.
Raising severity -- this is a VERY nasty bug. All the outer for loop does is prevent constant folding. With -O enabled, the wrong branch of ?: gets taken.
void main() {
 for (int j=1; j<2; j++) {
 int x = (j<0) ? -j : j;
 int q=0;
 for (int i=0; i<x; i++) ++q;
 assert(q!=0);
 }
}
Comment 2 Walter Bright 2009年07月09日 02:49:09 UTC
Fixed dmd 1.046 and 2.031

AltStyle によって変換されたページ (->オリジナル) /