{
/* Do not store variables we cannot take the address of,
but keep the values for purposes of debugging. */
- if (!d->type->isscalar ())
+ if (d->type->isscalar () && !d->type->hasPointers ())
{
tree decl = get_symbol_decl (d);
d_pushdecl (decl);
return decl->csym;
}
+ if (VarDeclaration *vd = decl->isVarDeclaration ())
+ {
+ /* CONST_DECL was initially intended for enumerals and may be used for
+ scalars in general, but not for aggregates. Here a non-constant
+ value is generated anyway so as its value can be used. */
+ if (!vd->canTakeAddressOf () && !vd->type->isscalar ())
+ {
+ gcc_assert (vd->_init && !vd->_init->isVoidInitializer ());
+ Expression *ie = initializerToExpression (vd->_init);
+ decl->csym = build_expr (ie, false);
+ return decl->csym;
+ }
+ }
+
/* Build the tree for the symbol. */
FuncDeclaration *fd = decl->isFuncDeclaration ();
if (fd)
if (vd->storage_class & STCextern)
DECL_EXTERNAL (decl->csym) = 1;
- /* CONST_DECL was initially intended for enumerals and may be used for
- scalars in general, but not for aggregates. Here a non-constant
- value is generated anyway so as the CONST_DECL only serves as a
- placeholder for the value, however the DECL itself should never be
- referenced in any generated code, or passed to the back-end. */
- if (vd->storage_class & STCmanifest)
+ if (!vd->canTakeAddressOf ())
{
/* Cannot make an expression out of a void initializer. */
- if (vd->_init && !vd->_init->isVoidInitializer ())
- {
- Expression *ie = initializerToExpression (vd->_init);
+ gcc_assert (vd->_init && !vd->_init->isVoidInitializer ());
+ /* Non-scalar manifest constants have already been dealt with. */
+ gcc_assert (vd->type->isscalar ());
- if (!vd->type->isscalar ())
- DECL_INITIAL (decl->csym) = build_expr (ie, false);
- else
- DECL_INITIAL (decl->csym) = build_expr (ie, true);
- }
+ Expression *ie = initializerToExpression (vd->_init);
+ DECL_INITIAL (decl->csym) = build_expr (ie, true);
}
/* [type-qualifiers/const-and-immutable]
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
{