diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-07-07 21:06:07 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-07-07 21:19:14 +0200 |
commit | f934c5753849f7c48c6a3abfcd73b8f6008e8371 (patch) | |
tree | 0eec803efd5cca9f8a8646c933468802f75aeed3 /gcc/d/imports.cc | |
parent | bb3b9c1c3ba8228387ea8a94f3638190d1696324 (diff) | |
download | gcc-f934c5753849f7c48c6a3abfcd73b8f6008e8371.zip gcc-f934c5753849f7c48c6a3abfcd73b8f6008e8371.tar.gz gcc-f934c5753849f7c48c6a3abfcd73b8f6008e8371.tar.bz2 |
d: Fix PR 108842: Cannot use enum array with -fno-druntime
Restrict the generating of CONST_DECLs for D manifest constants to just
scalars without pointers. It shouldn't happen that a reference to a
manifest constant has not been expanded within a function body during
codegen, but it has been found to occur in older versions of the D
front-end (PR98277), so if the decl of a non-scalar constant is
requested, just return its initializer as an expression.
PR d/108842
gcc/d/ChangeLog:
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Only emit scalar
manifest constants.
(get_symbol_decl): Don't generate CONST_DECL for non-scalar manifest
constants.
* imports.cc (ImportVisitor::visit (VarDeclaration *)): New method.
gcc/testsuite/ChangeLog:
* gdc.dg/pr98277.d: Add more tests.
* gdc.dg/pr108842.d: New test.
Diffstat (limited to 'gcc/d/imports.cc')
-rw-r--r-- | gcc/d/imports.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc index 2efef4e..3172b79 100644 --- a/gcc/d/imports.cc +++ b/gcc/d/imports.cc @@ -127,6 +127,15 @@ public: this->result_ = this->make_import (TYPE_STUB_DECL (type)); } + void visit (VarDeclaration *d) final override + { + /* Not all kinds of manifest constants create a CONST_DECL. */ + if (!d->canTakeAddressOf () && !d->type->isscalar ()) + return; + + visit ((Declaration *) d); + } + /* For now, ignore importing other kinds of dsymbols. */ void visit (ScopeDsymbol *) final override { |