aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/d-codegen.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-03-29 16:57:10 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2022-04-02 23:56:52 +0200
commit235d5a96cb8dad0b4c427602346fcf966a4ec914 (patch)
treeca19c774a19ad923e5d6f09d43ee8d89c275a96e /gcc/d/d-codegen.cc
parentbe07535d0f43390b8906826cc119473dea514b54 (diff)
downloadgcc-235d5a96cb8dad0b4c427602346fcf966a4ec914.zip
gcc-235d5a96cb8dad0b4c427602346fcf966a4ec914.tar.gz
gcc-235d5a96cb8dad0b4c427602346fcf966a4ec914.tar.bz2
d: Merge upstream dmd 47871363d, druntime, c52e28b7, phobos 99e9c1b77.
D front-end changes: - Import dmd v2.099.1-beta.1. - The address of NRVO variables is now stored in scoped closures when they have nested references. - Using `__traits(parameters)' in foreach loops now always returns the parameters to the function the foreach appears within. Previously, when used inside a `foreach' using an overloaded `opApply', the trait would yield the parameters to the delegate. - The deprecation period of unannotated `asm' blocks has been ended. - The `inout' attribute no longer implies the `return' attribute. - Added new `D_PreConditions', `D_PostConditions', and `D_Invariants' version identifiers. D runtime changes: - Import druntime v2.099.1-beta.1. Phobos changes: - Import phobos v2.099.1-beta.1. - `Nullable' in `std.typecons' can now act as a range. - std.experimental.logger default level changed to `info' instead of `warning'. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 47871363d. * d-builtins.cc (d_init_versions): Add predefined version identifiers D_PreConditions, D_PostConditions, and D_Invariants. * d-codegen.cc (d_build_call): Update for new front-end interface. (build_frame_type): Generate reference field for NRVO variables with nested references. (build_closure): Generate assignment of return address to closure. * d-tree.h (DECL_INSTANTIATED): Use DECL_LANG_FLAG_2. (bind_expr): Remove. * decl.cc (DeclVisitor::visit (FuncDeclaration *)): Update for new front-end interface. (get_symbol_decl): Likewise. (get_decl_tree): Check DECL_LANG_FRAME_FIELD before DECL_LANG_NRVO. Dereference the field when both are set. * expr.cc (ExprVisitor::visit (DeleteExp *)): Update for new front-end interface. * modules.cc (get_internal_fn): Likewise. * toir.cc (IRVisitor::visit (ReturnStatement *)): Likewise. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime c52e28b7. * libdruntime/Makefile.am (DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/pwd.d. * libdruntime/Makefile.in: Regenerate. * src/MERGE: Merge upstream phobos 99e9c1b77. * testsuite/libphobos.exceptions/message_with_null.d: New test. gcc/testsuite/ChangeLog: * gdc.dg/nrvo1.d: New test.
Diffstat (limited to 'gcc/d/d-codegen.cc')
-rw-r--r--gcc/d/d-codegen.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 3206edd..bb96b2f 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2207,9 +2207,9 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
build_address (targ));
}
- /* Type `noreturn` is a terminator, as no other arguments can possibly
- be evaluated after it. */
- if (TREE_TYPE (targ) == noreturn_type_node)
+ /* Type `noreturn` is a terminator, as no other arguments can possibly
+ be evaluated after it. */
+ if (TREE_TYPE (targ) == noreturn_type_node)
noreturn_call = true;
vec_safe_push (args, targ);
@@ -2690,9 +2690,15 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (vsym);
TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (vsym);
- /* Can't do nrvo if the variable is put in a frame. */
- if (fd->nrvo_can && fd->nrvo_var == v)
- fd->nrvo_can = 0;
+ if (DECL_LANG_NRVO (vsym))
+ {
+ /* Store the nrvo variable in the frame by reference. */
+ TREE_TYPE (field) = build_reference_type (TREE_TYPE (field));
+
+ /* Can't do nrvo if the variable is put in a closure, since what the
+ return slot points to may no longer exist. */
+ gcc_assert (!FRAMEINFO_IS_CLOSURE (ffi));
+ }
if (FRAMEINFO_IS_CLOSURE (ffi))
{
@@ -2769,13 +2775,17 @@ build_closure (FuncDeclaration *fd)
for (size_t i = 0; i < fd->closureVars.length; i++)
{
VarDeclaration *v = fd->closureVars[i];
+ tree vsym = get_symbol_decl (v);
- if (!v->isParameter ())
+ if (TREE_CODE (vsym) != PARM_DECL && !DECL_LANG_NRVO (vsym))
continue;
- tree vsym = get_symbol_decl (v);
-
tree field = component_ref (decl_ref, DECL_LANG_FRAME_FIELD (vsym));
+
+ /* Variable is an alias for the NRVO slot, store the reference. */
+ if (DECL_LANG_NRVO (vsym))
+ vsym = build_address (DECL_LANG_NRVO (vsym));
+
tree expr = modify_expr (field, vsym);
add_stmt (expr);
}