Bug 13434 – [ICE] indexing array with empty tuple causes dmd segfault

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-09-07T01:54:00Z
Last change time
2015-02-18T03:36:38Z
Keywords
ice, patch, pull
Assigned to
nobody
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2014-09-07T01:54:34Z
Code: ------ alias tuple(A...) = A; void main() { float[] arr; arr[tuple!()] = 0.0; } ------ Indexing with a tuple of 1 integral element works correctly, and indexing with a tuple of more than 1 element correctly generates an error message about non-convertibility to ulong. Indexing with an empty tuple should also generate an error message, rather than crash.
Comment #1 by hsteoh — 2014-09-07T02:03:44Z
This patch fixes it: ------- diff --git a/src/expression.c b/src/expression.c index 9b8b80b..650f67a 100644 --- a/src/expression.c +++ b/src/expression.c @@ -10336,8 +10336,11 @@ Expression *IndexExp::semantic(Scope *sc) if (t1->ty == Ttuple) sc = sc->endCTFE(); if (e2->type == Type::terror) return new ErrorExp(); - if (e2->type->ty == Ttuple && ((TupleExp *)e2)->exps->dim == 1) // bug 4444 fix + if (e2->type->ty == Ttuple && ((TupleExp *)e2)->exps && + ((TupleExp *)e2)->exps->dim == 1) // bug 4444 fix + { e2 = (*((TupleExp *)e2)->exps)[0]; + } if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple) sc = sc->pop(); ------- Will submit this as a PR on Monday once internet connectivity from my home PC is restored.
Comment #2 by hsteoh — 2014-09-09T16:37:41Z
Comment #3 by github-bugzilla — 2014-09-09T17:43:08Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/930f0bd6d9b9fc56766c91fb7ff00e005945dccc Merge pull request #3969 from quickfur/ice_emptytuple Fix issue 13434: segfault on indexing array with empty tuple
Comment #4 by github-bugzilla — 2015-02-18T03:36:38Z