diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-07-09 22:08:36 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-07-09 22:08:36 +0200 |
commit | 3b007164b3ef114c3c86c42ca2455f8f2696fb0d (patch) | |
tree | 340037c67d4a2a57774103d54fa103390611f6e5 /gcc/d/expr.cc | |
parent | d6c1d7c4009bfe759719675ce3bc03ca503b9bf4 (diff) | |
download | gcc-3b007164b3ef114c3c86c42ca2455f8f2696fb0d.zip gcc-3b007164b3ef114c3c86c42ca2455f8f2696fb0d.tar.gz gcc-3b007164b3ef114c3c86c42ca2455f8f2696fb0d.tar.bz2 |
d: Merge upstream dmd, druntime 28a3b24c2e, phobos 8ab95ded5.
D front-end changes:
- Import dmd v2.104.0-beta.1.
- Better error message when attribute inference fails down the
call stack.
- Using `;' as an empty statement has been turned into an error.
- Using `in' parameters with non- `extern(D)' or `extern(C++)'
functions is deprecated.
- `in ref' on parameters has been deprecated in favor of
`-preview=in'.
- Throwing `immutable', `const', `inout', and `shared' qualified
objects is now deprecated.
- User Defined Attributes now parse Template Arguments.
D runtime changes:
- Import druntime v2.104.0-beta.1.
Phobos changes:
- Import phobos v2.104.0-beta.1.
- Better static assert messages when instantiating
`std.algorithm.comparison.clamp' with wrong inputs.
- `std.typecons.Rebindable' now supports all types.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 28a3b24c2e.
* dmd/VERSION: Bump version to v2.104.0-beta.1.
* d-codegen.cc (build_bounds_slice_condition): Update for new
front-end interface.
* d-lang.cc (d_init_options): Likewise.
(d_handle_option): Likewise.
(d_post_options): Initialize global.compileEnv.
* expr.cc (ExprVisitor::visit (CatExp *)): Replace code generation
with new front-end lowering.
(ExprVisitor::visit (LoweredAssignExp *)): New method.
(ExprVisitor::visit (StructLiteralExp *)): Don't generate static
initializer symbols for structs defined in C sources.
* runtime.def (ARRAYCATT): Remove.
(ARRAYCATNTX): Remove.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime 28a3b24c2e.
* src/MERGE: Merge upstream phobos 8ab95ded5.
gcc/testsuite/ChangeLog:
* gdc.dg/rtti1.d: Move array concat testcase to ...
* gdc.dg/nogc1.d: ... here. New test.
Diffstat (limited to 'gcc/d/expr.cc')
-rw-r--r-- | gcc/d/expr.cc | 91 |
1 files changed, 21 insertions, 70 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index aeafe43..23f2f0b 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -693,78 +693,22 @@ public: void visit (CatExp *e) final override { - Type *tb1 = e->e1->type->toBasetype (); - Type *tb2 = e->e2->type->toBasetype (); - Type *etype; - - if (tb1->ty == TY::Tarray || tb1->ty == TY::Tsarray) - etype = tb1->nextOf (); - else - etype = tb2->nextOf (); - - tree result; - - if (e->e1->op == EXP::concatenate) + /* This error is only emitted during the code generation pass because + concatentation is allowed in CTFE. */ + if (global.params.betterC) { - /* Flatten multiple concatenations to an array. - So the expression ((a ~ b) ~ c) becomes [a, b, c] */ - int ndims = 2; - - for (Expression *ex = e->e1; ex->op == EXP::concatenate;) - { - if (ex->op == EXP::concatenate) - { - ex = ex->isCatExp ()->e1; - ndims++; - } - } - - /* Store all concatenation args to a temporary byte[][ndims] array. */ - Type *targselem = Type::tint8->arrayOf (); - tree var = build_local_temp (make_array_type (targselem, ndims)); - - /* Loop through each concatenation from right to left. */ - vec <constructor_elt, va_gc> *elms = NULL; - CatExp *ce = e; - int dim = ndims - 1; - - for (Expression *oe = ce->e2; oe != NULL; - (ce->e1->op != EXP::concatenate - ? (oe = ce->e1) - : (ce = ce->e1->isCatExp (), oe = ce->e2))) - { - tree arg = d_array_convert (etype, oe); - tree index = size_int (dim); - CONSTRUCTOR_APPEND_ELT (elms, index, d_save_expr (arg)); - - /* Finished pushing all arrays. */ - if (oe == ce->e1) - break; - - dim -= 1; - } - - /* Check there is no logic bug in constructing byte[][] of arrays. */ - gcc_assert (dim == 0); - tree init = build_constructor (TREE_TYPE (var), elms); - var = compound_expr (modify_expr (var, init), var); - - tree arrs = d_array_value (build_ctype (targselem->arrayOf ()), - size_int (ndims), build_address (var)); - - result = build_libcall (LIBCALL_ARRAYCATNTX, e->type, 2, - build_typeinfo (e, e->type), arrs); - } - else - { - /* Handle single concatenation (a ~ b). */ - result = build_libcall (LIBCALL_ARRAYCATT, e->type, 3, - build_typeinfo (e, e->type), - d_array_convert (etype, e->e1), - d_array_convert (etype, e->e2)); + error_at (make_location_t (e->loc), + "array concatenation of expression %qs requires the GC and " + "cannot be used with %<-fno-druntime%>", e->toChars ()); + this->result_ = error_mark_node; + return; } - this->result_ = result; + /* All concat expressions should have been rewritten to `_d_arraycatnTX` in + the semantic phase. */ + gcc_assert (e->lowering); + + this->result_ = build_expr (e->lowering); } /* Build an assignment operator expression. The right operand is implicitly @@ -1150,6 +1094,13 @@ public: this->result_ = build_assign (modifycode, t1, t2); } + /* Build an assignment expression that has been lowered in the front-end. */ + + void visit (LoweredAssignExp *e) final override + { + this->result_ = build_expr (e->lowering); + } + /* Build a throw expression. */ void visit (ThrowExp *e) final override @@ -2828,7 +2779,7 @@ public: /* Building sinit trees are delayed until after frontend semantic processing has complete. Build the static initializer now. */ - if (e->useStaticInit && !this->constp_) + if (e->useStaticInit && !this->constp_ && !e->sd->isCsymbol ()) { tree init = aggregate_initializer_decl (e->sd); |