Hi, This patch fixes an ICE in the D compiler, where certain kinds of lowered code mean the address of a CALL_EXPR is required. When that happens, use a TARGET_EXPR to hold the result, and take the address of that instead.
Bootstrapped and regression tested on x86_64-linux-gnu. Committed to trunk as r274253. -- Iain --- gcc/d/ChangeLog: PR d/91238 * d-codegen.cc (build_address): If taking the address of a CALL_EXPR, wrap it in a TARGET_EXPR. gcc/testsuite/ChangeLog: PR d/91238 * gdc.dg/pr91238.d: New test. ---
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 1971064e334..cf50693b2f5 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -651,9 +651,11 @@ build_address (tree exp) if (TREE_CODE (exp) == CONST_DECL) exp = DECL_INITIAL (exp); - /* Some expression lowering may request an address of a compile-time constant. - Make sure it is assigned to a location we can reference. */ - if (CONSTANT_CLASS_P (exp) && TREE_CODE (exp) != STRING_CST) + /* Some expression lowering may request an address of a compile-time constant, + or other non-lvalue expression. Make sure it is assigned to a location we + can reference. */ + if ((CONSTANT_CLASS_P (exp) && TREE_CODE (exp) != STRING_CST) + || TREE_CODE (exp) == CALL_EXPR) exp = force_target_expr (exp); d_mark_addressable (exp); diff --git a/gcc/testsuite/gdc.dg/pr91238.d b/gcc/testsuite/gdc.dg/pr91238.d new file mode 100644 index 00000000000..26efb906212 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr91238.d @@ -0,0 +1,18 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91238 +// { dg-do compile } + +alias T = const(char)*; + +T name() +{ + return ""; +} + +void collect(ref T) +{ +} + +void configure(T[T] targets) +{ + collect(targets[name]); +}