aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/expressionsem.d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2023-10-29 16:39:05 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2023-10-29 16:41:29 +0100
commite773c6c7009bb35fa50da034f3537448fd36c7f0 (patch)
tree24b60531e9364c16eb2bfd6c2bfea5f287e6afab /gcc/d/dmd/expressionsem.d
parentc6929b085580cf00cbc52b0f5b0afe2b9caa2a22 (diff)
downloadgcc-e773c6c7009bb35fa50da034f3537448fd36c7f0.zip
gcc-e773c6c7009bb35fa50da034f3537448fd36c7f0.tar.gz
gcc-e773c6c7009bb35fa50da034f3537448fd36c7f0.tar.bz2
d: Merge upstream dmd, druntime e48bc0987d, phobos 2458e8f82.
D front-end changes: - Import dmd v2.106.0-beta.1. D runtime changes: - Import druntime v2.106.0-beta.1. Phobos changes: - Import phobos v2.106.0-beta.1. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd e48bc0987d. * expr.cc (ExprVisitor::visit (NewExp *)): Update for new front-end interface. * runtime.def (NEWARRAYT): Remove. (NEWARRAYIT): Remove. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime e48bc0987d. * src/MERGE: Merge upstream phobos 2458e8f82.
Diffstat (limited to 'gcc/d/dmd/expressionsem.d')
-rw-r--r--gcc/d/dmd/expressionsem.d53
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 3472f92..ac8e571 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -4406,6 +4406,58 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
(*exp.arguments)[i] = arg;
tb = tb.isTypeDArray().next.toBasetype();
}
+
+ if (nargs == 1)
+ {
+ if (global.params.betterC || !sc.needsCodegen())
+ goto LskipNewArrayLowering;
+
+ /* Class types may inherit base classes that have errors.
+ * This may leak errors from the base class to the derived one
+ * and then to the hook. Semantic analysis is performed eagerly
+ * to a void this.
+ */
+ if (auto tc = exp.type.nextOf.isTypeClass())
+ {
+ tc.sym.dsymbolSemantic(sc);
+ if (tc.sym.errors)
+ goto LskipNewArrayLowering;
+ }
+
+ auto hook = global.params.tracegc ? Id._d_newarrayTTrace : Id._d_newarrayT;
+ if (!verifyHookExist(exp.loc, *sc, hook, "new array"))
+ goto LskipNewArrayLowering;
+
+ /* Lower the memory allocation and initialization of `new T[n]`
+ * to `_d_newarrayT!T(n)`.
+ */
+ Expression lowering = new IdentifierExp(exp.loc, Id.empty);
+ lowering = new DotIdExp(exp.loc, lowering, Id.object);
+ auto tiargs = new Objects();
+ /* Remove `inout`, `const`, `immutable` and `shared` to reduce
+ * the number of generated `_d_newarrayT` instances.
+ */
+ const isShared = exp.type.nextOf.isShared();
+ auto t = exp.type.nextOf.unqualify(MODFlags.wild | MODFlags.const_ |
+ MODFlags.immutable_ | MODFlags.shared_);
+ tiargs.push(t);
+ lowering = new DotTemplateInstanceExp(exp.loc, lowering, hook, tiargs);
+
+ auto arguments = new Expressions();
+ if (global.params.tracegc)
+ {
+ auto funcname = (sc.callsc && sc.callsc.func) ?
+ sc.callsc.func.toPrettyChars() : sc.func.toPrettyChars();
+ arguments.push(new StringExp(exp.loc, exp.loc.filename.toDString()));
+ arguments.push(new IntegerExp(exp.loc, exp.loc.linnum, Type.tint32));
+ arguments.push(new StringExp(exp.loc, funcname.toDString()));
+ }
+ arguments.push((*exp.arguments)[0]);
+ arguments.push(new IntegerExp(exp.loc, isShared, Type.tbool));
+
+ lowering = new CallExp(exp.loc, lowering, arguments);
+ exp.lowering = lowering.expressionSemantic(sc);
+ }
}
else if (tb.isscalar())
{
@@ -4447,6 +4499,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
}
+ LskipNewArrayLowering:
//printf("NewExp: '%s'\n", toChars());
//printf("NewExp:type '%s'\n", type.toChars());
semanticTypeInfo(sc, exp.type);