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. ***
Comment #6 by clugdbug — 2012-12-04T07:24:21Z
Comment #7 by github-bugzilla — 2012-12-04T18:21:18Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/72dc992d114765cdb5aa9a2ea2357e6990bb6be2 Fix issue 7602 [CTFE] Segmentation fault when using array.keys on a null AA The return type was set incorrectly (or not at all!).
Comment #8 by github-bugzilla — 2012-12-11T09:50:24Z
Commits pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f2af1f5831941d6d7ff0f2df610f409879040eff Fix issue 7602 [CTFE] Segmentation fault when using array.keys on a null AA The return type was set incorrectly (or not at all!). https://github.com/D-Programming-Language/dmd/commit/df8a7db18b1e1ad5d3ec4457fa13f2308c57c942 Merge pull request #1360 from donc/d1merge7602_7890 D1: Merge fixes for CTFE AA bugs 7602 and 7890