Skip to content

Commit 9cf3a26

Browse files
authored
Fix dlang/dmd!21247 - DMD hangs in CTFE (dlang/dmd!21248)
Fixes dlang/dmd#21247 An infinite loop was introduced by a previous refactoring. Ensure the loop properly terminates and add tests cases.
1 parent e3ce49e commit 9cf3a26

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

dmd/expressionsem.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6978,10 +6978,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
69786978
while (1)
69796979
{
69806980
AttribDeclaration ad = s.isAttribDeclaration();
6981-
if (!ad)
6982-
break;
6983-
if (ad.decl && ad.decl.length == 1)
6981+
if (ad && ad.decl && ad.decl.length == 1)
69846982
s = (*ad.decl)[0];
6983+
else
6984+
break;
69856985
}
69866986

69876987
//printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/test21247.d(13): Error: anonymous union can only be a part of an aggregate, not function `hang_dmd`
5+
fail_compilation/test21247.d(17): Error: undefined identifier `u`
6+
fail_compilation/test21247.d(18): Error: undefined identifier `b`
7+
fail_compilation/test21247.d(20): called from here: `hang_dmd(0u)`
8+
---
9+
*/
10+
// https://github.com/dlang/dmd/issues/21247
11+
ubyte[4] hang_dmd(uint a)
12+
{
13+
union {
14+
uint u = void;
15+
ubyte[4] b;
16+
}
17+
u = a;
18+
return b;
19+
}
20+
enum T = hang_dmd(0);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/test21247b.d(10): Error: anonymous union can only be a part of an aggregate, not function `test21247`
5+
---
6+
*/
7+
// https://github.com/dlang/dmd/issues/21247
8+
void test21247()
9+
{
10+
union {
11+
uint u = void;
12+
ubyte[4] b;
13+
}
14+
}

0 commit comments

Comments
 (0)