Bug 15629 – [REG2.066.0] wrong code with '-O -inline' but correct with '-O'
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-30T15:01:00Z
Last change time
2016-04-17T16:07:25Z
Keywords
wrong-code
Assigned to
nobody
Creator
gassa
Comments
Comment #0 by gassa — 2016-01-30T15:01:53Z
Here is the reduced test case.
testmodule.d:
-----
import std.math;
import std.stdio;
void main ()
{
int [] a = [3];
int [] b = [9];
int value = abs (a[0]);
if (a[0] != 3)
{
writeln (value, " ", a, " ", b);
assert (false);
}
}
-----
DMD 2.066.1 through the latest DMD 2.070.0:
- "dmd -O testmodule.d" works,
- "dmd -O -inline testmodule.d" writes "3 [3] [9]" and runs into assert (false).
DMD 2.063.2:
- both work as expected.
So, technically, this is a regression somewhere between 2.063.2 and 2.066.1.
Dustmited case code:
void main()
{
int[] a = [3];
int value = abs(a[0]);
assert(a[0] == 3);
writeln(value, " ", a);
}
Num abs(Num)(Num x)
{
return x >= 0 ? x : -x;
}
struct File
{
struct LockingTextWriter
{
this(File) {}
~this() @trusted {}
}
auto lockingTextWriter()
{
return LockingTextWriter();
}
}
File stdout;
void writeln(T...)(T args)
{
stdout.lockingTextWriter;
}
Comment #4 by k.hara.pg — 2016-02-08T11:08:16Z
(In reply to Kenji Hara from comment #3)
> Dustmited case code:
Sorry, the reduced code cannot reproduce exactly same regression with the original.
I'll open one more issue for that.
Correct minimized code is:
void main()
{
int[] a = [3];
int value = abs(a[0]);
assert(a[0] == 3);
writeln(value, " ", a);
}
Num abs(Num)(Num x)
{
return x >= 0 ? x : -x;
}
struct File
{
struct LockingTextWriter
{
this(File) {}
~this() @trusted {}
}
auto lockingTextWriter()
{
return LockingTextWriter();
}
}
File stdout;
void writeln(T...)(T args)
{
stdout.lockingTextWriter();
}
Introduced in:
https://github.com/D-Programming-Language/dmd/pull/3620
and its fixup PR:
https://github.com/D-Programming-Language/dmd/pull/3656
So this is a regression from 2.066.0.
Comment #5 by k.hara.pg — 2016-02-08T11:21:38Z
(In reply to Kenji Hara from comment #4)
> Sorry, the reduced code cannot reproduce exactly same regression with the
> original.
> I'll open one more issue for that.
Ah, I got understanding. The reduced case in comment#3 has generated wrong code with -inline, since the change by PR#4474:
https://github.com/D-Programming-Language/dmd/pull/4474
However, comment#3 and comment#4 are essentially same. The only one difference is the parenthesis on stdout.lockingTextWriter(); in writeln template function.
So, this wrong-code issue in the comment#3 case was hidden by issue 14264, and it's *fixed* by PR#4474. Therefore the two cases can hit this issue with current master.
Comment #6 by bugzilla — 2016-04-14T05:27:02Z
Comment 3 further reduces to:
void main() {
int[] a = [3];
int value = a[0] >= 0 ? a[0] : -a[0];
assert(a[0] == 3);
writeln(value, a);
}
void writeln(int v, int[] a) {
}
and only -O is needed (not -inline).