aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/decl.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-06-23 14:45:50 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2020-06-25 17:02:45 +0200
commiteacfafbc3534fb32782934d765d21855dff32e56 (patch)
treec9e74913d431bb17f6a2b581d415849d60e4b2ac /gcc/d/decl.cc
parent6948c7c3d29bf5892299550a19ce615a85ef9b2b (diff)
downloadgcc-eacfafbc3534fb32782934d765d21855dff32e56.zip
gcc-eacfafbc3534fb32782934d765d21855dff32e56.tar.gz
gcc-eacfafbc3534fb32782934d765d21855dff32e56.tar.bz2
d: Don't set DECL_INITIAL if initializer is 'void'.
Declarations initialized with `= void` were being default initialized. That is not really the intent, and misses the small optimization that should have been gained from using void initializations. gcc/d/ChangeLog: * decl.cc (DeclVisitor::visit (VarDeclaration *)): Don't set DECL_INITIAL if initializer is 'void'. gcc/testsuite/ChangeLog: * gdc.dg/init1.d: New test.
Diffstat (limited to 'gcc/d/decl.cc')
-rw-r--r--gcc/d/decl.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index ea6614f..77144fe 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -697,13 +697,18 @@ public:
return;
}
- if (d->_init && !d->_init->isVoidInitializer ())
+ if (d->_init)
{
- Expression *e = initializerToExpression (d->_init, d->type);
- DECL_INITIAL (decl) = build_expr (e, true);
+ /* Use the explicit initializer, this includes `void`. */
+ if (!d->_init->isVoidInitializer ())
+ {
+ Expression *e = initializerToExpression (d->_init, d->type);
+ DECL_INITIAL (decl) = build_expr (e, true);
+ }
}
else
{
+ /* Use default initializer for the type. */
if (TypeStruct *ts = d->type->isTypeStruct ())
DECL_INITIAL (decl) = layout_struct_initializer (ts->sym);
else