2923 – -O generates bad code for ?:

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2923 - -O generates bad code for ?:
Summary: -O generates bad code for ?:
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2009年05月02日 13:45 UTC by xurux1-mail
Modified: 2014年04月18日 09:12 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
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 によって変換されたページ (->オリジナル) /