https://gcc.gnu.org/g:0eae20c899e327aec0e48b9ff2d856aba44b2639

commit r15-9544-g0eae20c899e327aec0e48b9ff2d856aba44b2639
Author: Iain Buclaw <ibuc...@gdcproject.org>
Date:   Thu Apr 17 08:21:40 2025 +0200

    d: Fix infinite loop regression in CTFE
    
    An infinite loop was introduced by a previous refactoring in the
    semantic pass for DeclarationExp nodes. Ensure the loop properly
    terminates and add tests cases.
    
    gcc/d/ChangeLog:
    
            * dmd/MERGE: Merge upstream dmd 956e73d64e.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.test/fail_compilation/test21247.d: New test.
            * gdc.test/fail_compilation/test21247b.d: New test.
    
    Reviewed-on: https://github.com/dlang/dmd/pull/21248

Diff:
---
 gcc/d/dmd/MERGE                                      |  2 +-
 gcc/d/dmd/expressionsem.d                            |  6 +++---
 gcc/testsuite/gdc.test/fail_compilation/test21247.d  | 20 ++++++++++++++++++++
 gcc/testsuite/gdc.test/fail_compilation/test21247b.d | 14 ++++++++++++++
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index ee5eb853284b..58d19b4e951d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-1b34fea4788136b54ec77c6ed9678754d109fc79
+956e73d64e532a68213970316c2590c572ec03f3
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 19111e31baa0..b02f6ea64102 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -6978,10 +6978,10 @@ private extern (C++) final class 
ExpressionSemanticVisitor : Visitor
         while (1)
         {
             AttribDeclaration ad = s.isAttribDeclaration();
-            if (!ad)
-                break;
-            if (ad.decl && ad.decl.length == 1)
+            if (ad && ad.decl && ad.decl.length == 1)
                 s = (*ad.decl)[0];
+            else
+                break;
         }
 
         //printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21247.d 
b/gcc/testsuite/gdc.test/fail_compilation/test21247.d
new file mode 100644
index 000000000000..c3e4105a05c3
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test21247.d
@@ -0,0 +1,20 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21247.d(13): Error: anonymous union can only be a part of 
an aggregate, not function `hang_dmd`
+fail_compilation/test21247.d(17): Error: undefined identifier `u`
+fail_compilation/test21247.d(18): Error: undefined identifier `b`
+fail_compilation/test21247.d(20):        called from here: `hang_dmd(0u)`
+---
+ */
+// https://github.com/dlang/dmd/issues/21247
+ubyte[4] hang_dmd(uint a)
+{
+    union {
+        uint u = void;
+        ubyte[4] b;
+    }
+    u = a;
+    return b;
+}
+enum T = hang_dmd(0);
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21247b.d 
b/gcc/testsuite/gdc.test/fail_compilation/test21247b.d
new file mode 100644
index 000000000000..ecd4603c064b
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test21247b.d
@@ -0,0 +1,14 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21247b.d(10): Error: anonymous union can only be a part 
of an aggregate, not function `test21247`
+---
+ */
+// https://github.com/dlang/dmd/issues/21247
+void test21247()
+{
+    union {
+        uint u = void;
+        ubyte[4] b;
+    }
+}

Reply via email to