]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix internal compiler error: in visit, at d/imports.cc:72 (PR108050)
authorIain Buclaw <ibuclaw@gdcproject.org>
Sat, 10 Dec 2022 18:12:43 +0000 (19:12 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sun, 11 Dec 2022 17:53:31 +0000 (18:53 +0100)
The visitor for lowering IMPORTED_DECLs did not have an override for
dealing with importing OverloadSet symbols.  This has now been
implemented in the code generator.

PR d/108050

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (Import *)): Handle build_import_decl
returning a TREE_LIST.
* imports.cc (ImportVisitor::visit (OverloadSet *)): New override.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr108050/mod1.d: New.
* gdc.dg/imports/pr108050/mod2.d: New.
* gdc.dg/imports/pr108050/package.d: New.
* gdc.dg/pr108050.d: New test.

(cherry picked from commit d9d8c9674ad3ad3aa38419d24b1aaaffe31f5d3f)

gcc/d/decl.cc
gcc/d/imports.cc
gcc/testsuite/gdc.dg/imports/pr108050/mod1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/imports/pr108050/mod2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/imports/pr108050/package.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr108050.d [new file with mode: 0644]

index 0f1dad95ba38c4e67afcaf2e4c3a75800e2dccc5..e62be0c580aeb12560edbd173d0c762367de240a 100644 (file)
@@ -197,8 +197,16 @@ public:
            tree name = (alias != NULL)
              ? get_identifier (alias->toChars ()) : NULL_TREE;
 
-           debug_hooks->imported_module_or_decl (decl, name, context,
-                                                 false, false);
+           if (TREE_CODE (decl) != TREE_LIST)
+             debug_hooks->imported_module_or_decl (decl, name, context,
+                                                   false, false);
+           else
+             {
+               /* Overload sets return a list of imported decls.  */
+               for (; decl != NULL_TREE; decl = TREE_CHAIN (decl))
+                 debug_hooks->imported_module_or_decl (TREE_VALUE (decl), name,
+                                                       context, false, false);
+             }
          }
       }
     else
index 6747ee5df27a459bd772b4246f655e23c1b48b06..4ce6f026b299cf4dac7f95d6e6c2da96be35076a 100644 (file)
@@ -160,6 +160,20 @@ public:
       d->aliassym->accept (this);
   }
 
+  /* Build IMPORTED_DECLs for all overloads in a set.  */
+  void visit (OverloadSet *d) final override
+  {
+    vec<tree, va_gc> *tset = NULL;
+
+    vec_alloc (tset, d->a.length);
+
+    for (size_t i = 0; i < d->a.length; i++)
+      vec_safe_push (tset, build_import_decl (d->a[i]));
+
+    this->result_ = build_tree_list_vec (tset);
+    tset->truncate (0);
+  }
+
   /* Function aliases are the same as alias symbols.  */
   void visit (FuncAliasDeclaration *d)
   {
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/mod1.d b/gcc/testsuite/gdc.dg/imports/pr108050/mod1.d
new file mode 100644 (file)
index 0000000..f27a13d
--- /dev/null
@@ -0,0 +1,2 @@
+module imports.pr108050.mod1;
+string[] split() { return null; }
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/mod2.d b/gcc/testsuite/gdc.dg/imports/pr108050/mod2.d
new file mode 100644 (file)
index 0000000..29d8aa8
--- /dev/null
@@ -0,0 +1,2 @@
+module imports.pr108050.mod2;
+string[] split() { return null; }
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/package.d b/gcc/testsuite/gdc.dg/imports/pr108050/package.d
new file mode 100644 (file)
index 0000000..b8b03b8
--- /dev/null
@@ -0,0 +1,2 @@
+module imports.pr108050;
+public import imports.pr108050.mod1, imports.pr108050.mod2;
diff --git a/gcc/testsuite/gdc.dg/pr108050.d b/gcc/testsuite/gdc.dg/pr108050.d
new file mode 100644 (file)
index 0000000..69134e7
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr108050/package.d imports/pr108050/mod1.d imports/pr108050/mod2.d" }
+// { dg-options "-g" }
+import imports.pr108050 : split;