5676 – [CTFE] segfault using tuple containing struct that has opAssign

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5676 - [CTFE] segfault using tuple containing struct that has opAssign
Summary: [CTFE] segfault using tuple containing struct that has opAssign
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
Reported: 2011年03月01日 10:50 UTC by David Nadlinger
Modified: 2011年06月26日 17:30 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 David Nadlinger 2011年03月01日 10:50:58 UTC
Trying to compile the following program crashes DMD (from current Git, a47637):
---
import std.typecons;
enum foo = tuple("foo", tuple("bar"));
---
The backtrace from GDB:
---
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000011
0x00087246 in expandTuples ()
(gdb) bt
#0 0x00087246 in expandTuples ()
#1 0x0012c6a9 in TupleExp::interpret ()
#2 0x0012963d in ExpStatement::interpret ()
#3 0x00129696 in CompoundStatement::interpret ()
#4 0x00129696 in CompoundStatement::interpret ()
#5 0x0012f44a in FuncDeclaration::interpret ()
#6 0x0012fb73 in CallExp::interpret ()
#7 0x000dfcc7 in CallExp::optimize ()
#8 0x000b7c28 in ExpInitializer::semantic ()
#9 0x000574b1 in VarDeclaration::semantic2 ()
#10 0x000c6912 in Module::semantic2 ()
#11 0x000c4388 in main ()
---
The above backtrace seems to indicate a bug in CTFE. Indeed, if the value isn't computed at compile time, everything works fine:
---
import std.stdio;
import std.typecons;
void main() {
 auto foo = tuple("foo", tuple("bar"));
 writeln(foo); // prints Tuple!(string,Tuple!(string))(foo, Tuple!(string)(bar)).
}
---
Comment 1 Don 2011年06月24日 01:56:04 UTC
Reduced test case. It happens with compile time assignment to a tuple which contains an object with an opAssign. Not a regression, failed in 2.040 as well.
struct S5676
{
 int x;
 void opAssign(S5676 rhs) { x = rhs.x;}
}
struct Tup5676(E...)
{
 E g;
 void foo(E values) { g = values; }
}
bool ice5676()
{
 Tup5676!(S5676) q;
 q.foo( S5676(3) );
 assert( q.g[0].x == 3); // crashes here
 return true;
}
static assert(ice5676());


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