Bug 7602 – [CTFE] Segmentation fault when using array.keys on a null AA
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-27T12:20:00Z
Last change time
2015-06-09T05:12:01Z
Keywords
CTFE, ice, pull
Assigned to
nobody
Creator
robert
Comments
Comment #0 by robert — 2012-02-27T12:20:08Z
The following code:
----
string[] test()
{
int[string] array;
return array.keys;
}
enum str = test();
----
Gives a segmentation fault with dmd 2.058 and dmd master.
Comment #1 by clugdbug — 2012-02-29T00:44:42Z
It's because in interpretAA_keys, the type is missing from NullExp.
That's simple. But the problem is, that function is returning the wrong type (the spec says it should return a dynamic array, it returns a static one).
If I change it to the correct type, then my inlining hack fails.
The solution is to add yet another hack to CTFE, to work around the hopelessly broken D2 AAs.
Yet another reason to roll the implementation back.
Comment #2 by hsteoh — 2012-03-18T22:30:42Z
OK, this is a very serious bug. Something is BADLY broken with CTFE:
struct AssociativeArray
{
int *impl;
int f()
{
if (impl !is null)
auto x = *impl; // this is line 7
return 1;
}
}
void main() {
int test()
{
AssociativeArray aa;
return aa.f;
}
enum str = test();
}
This is not a fully minimized test case, but I've tried my best to reduce it as much as possible. With the latest dmd from git, this gives:
test.d(7): Error: dereference of invalid pointer 'AssociativeArray(null)'
test.d(15): called from here: aa.f()
test.d(17): called from here: test()
This is a VERY serious bug because apparently the condition (impl !is null) actually passes, even though impl is null!
This appears to be related to the current AssociativeArray magic (renaming the struct in the above code makes the bug go away). I'm going to bump the severity of this bug.
Comment #3 by clugdbug — 2012-03-19T05:25:40Z
(In reply to comment #2)
> OK, this is a very serious bug. Something is BADLY broken with CTFE:
>
> struct AssociativeArray
[snip]
That test case is unrelated to the original bug. Please open a new bug report,
changing the severity of both bugs if required.
Comment #4 by hsteoh — 2012-03-19T07:57:25Z
OK, opened new issue bug 7732. Downgrading this bug back to original severity.
Comment #5 by clugdbug — 2012-12-03T03:58:01Z
*** Issue 8568 has been marked as a duplicate of this issue. ***