[gcc r13-10062] d: Fix internal compiler error: in visit, at d/decl.cc:838 [PR119799]
Iain Buclaw
ibuclaw@gcc.gnu.org
Wed Jan 28 22:57:37 GMT 2026
https://gcc.gnu.org/g:7cd6ed0768932b7776c41c70ca0145d6b8c17cc4
commit r13-10062-g7cd6ed0768932b7776c41c70ca0145d6b8c17cc4
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Wed Jan 28 23:51:35 2026 +0100
d: Fix internal compiler error: in visit, at d/decl.cc:838 [PR119799]
This was caused by a check in the D front-end disallowing static
VAR_DECLs with a size `0'.
While empty structs in D are give the size `1', the same symbol coming
from ImportC modules do infact have no size, so allow C variables to
pass the check as well as array objects.
PR d/119799
gcc/d/ChangeLog:
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Check front-end
type size before building the VAR_DECL. Allow C symbols to have a
size of `0'.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr119799.d: New test.
* gdc.dg/torture/imports/pr119799c.c: New test.
(cherry picked from commit 074b2b0f91f948fe3488ada91ec6a8576c684dea)
Diff:
---
gcc/d/decl.cc | 15 ++++++++++-----
gcc/testsuite/gdc.dg/torture/imports/pr119799c.c | 4 ++++
gcc/testsuite/gdc.dg/torture/pr119799.d | 9 +++++++++
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 945f075cd44e..58097925468c 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -781,6 +781,12 @@ public:
}
else if (d->isDataseg ())
{
+ /* When the front-end type size is invalid, an error has already been
+ given for the declaration or type. */
+ dinteger_t size = d->type->size (d->loc);
+ if (size == SIZE_INVALID)
+ return;
+
tree decl = get_symbol_decl (d);
/* Only need to build the VAR_DECL for extern declarations. */
@@ -794,9 +800,7 @@ public:
return;
/* How big a symbol can be should depend on back-end. */
- tree size = build_integer_cst (d->type->size (d->loc),
- build_ctype (Type::tsize_t));
- if (!valid_constant_size_p (size))
+ if (!valid_constant_size_p (build_integer_cst (size, size_type_node)))
{
error_at (make_location_t (d->loc), "size is too large");
return;
@@ -824,8 +828,9 @@ public:
}
/* Frontend should have already caught this. */
- gcc_assert (!integer_zerop (size)
- || d->type->toBasetype ()->isTypeSArray ());
+ gcc_assert ((size != 0 && size != SIZE_INVALID)
+ || d->type->toBasetype ()->isTypeSArray ()
+ || d->isCsymbol ());
d_finish_decl (decl);
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr119799c.c b/gcc/testsuite/gdc.dg/torture/imports/pr119799c.c
new file mode 100644
index 000000000000..0a97a772c8f7
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr119799c.c
@@ -0,0 +1,4 @@
+inline void fn119799()
+{
+ static struct {} s119799;
+}
diff --git a/gcc/testsuite/gdc.dg/torture/pr119799.d b/gcc/testsuite/gdc.dg/torture/pr119799.d
new file mode 100644
index 000000000000..f66aee8234d4
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr119799.d
@@ -0,0 +1,9 @@
+// { dg-do compile }
+// { dg-additional-files "imports/pr119799c.c" }
+// { dg-additional-options "-I[srcdir]" }
+import imports.pr119799c;
+
+void test()
+{
+ fn119799;
+}
More information about the Gcc-cvs
mailing list