@@ -3068,6 +3068,16 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
result = build_call_array_loc (loc, TREE_TYPE (fntype),
function, nargs, argarray);
+ /* In this improbable scenario, a nested function returns a VM type.
+ Create a TARGET_EXPR so that the call always has a LHS, much as
+ what the C++ FE does for functions returning non-PODs. */
+ if (variably_modified_type_p (TREE_TYPE (fntype), NULL_TREE))
+ {
+ tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
+ result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
+ NULL_TREE, NULL_TREE);
+ }
+
if (VOID_TYPE_P (TREE_TYPE (result)))
{
if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
@@ -1708,7 +1708,9 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
/* Build call to the function being thunked. */
if (!VOID_TYPE_P (restype)
- && (!alias_is_noreturn || TREE_ADDRESSABLE (restype)))
+ && (!alias_is_noreturn
+ || TREE_ADDRESSABLE (restype)
+ || TREE_CODE (TYPE_SIZE_UNIT (restype)) != INTEGER_CST))
{
if (DECL_BY_REFERENCE (resdecl))
{
@@ -4838,7 +4838,8 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
}
notice_special_calls (call_stmt);
if (!gimple_call_noreturn_p (call_stmt)
- || TREE_ADDRESSABLE (TREE_TYPE (*to_p)))
+ || TREE_ADDRESSABLE (TREE_TYPE (*to_p))
+ || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p))) != INTEGER_CST)
gimple_call_set_lhs (call_stmt, *to_p);
assign = call_stmt;
}
@@ -0,0 +1,49 @@
+/* PR c/70093 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo (int n)
+{
+ struct S { int a[n]; };
+
+ struct S __attribute__((noreturn))
+ fn (void)
+ {
+ __builtin_abort ();
+ }
+
+ auto struct S __attribute__((noreturn))
+ fn2 (void)
+ {
+ __builtin_abort ();
+ }
+
+ switch (n)
+ {
+ case 42:;
+ struct S x;
+ fn ();
+ fn2 ();
+ x = fn ();
+
+ if (x.a[0] != 42)
+ __builtin_abort ();
+
+ if (fn ().a[0] != 42)
+ __builtin_abort ();
+
+ __typeof__ (fn ()) *p = &x;
+ if (p->a[0] != 42)
+ __builtin_abort ();
+
+ if (fn2 ().a[0] != 42)
+ __builtin_abort ();
+ }
+}
+
+int
+main (void)
+{
+ foo (1);
+}
@@ -0,0 +1,47 @@
+/* PR c/70093 */
+/* { dg-do run } */
+/* { dg-options "" } */
+
+void
+foo (int n)
+{
+ struct S { int a[n]; };
+
+ struct S
+ fn (void)
+ {
+ struct S s;
+ s.a[0] = 42;
+ return s;
+ }
+
+ auto struct S
+ fn2 (void)
+ {
+ return fn ();
+ }
+
+ struct S x;
+ fn ();
+ fn2 ();
+ x = fn ();
+
+ if (x.a[0] != 42)
+ __builtin_abort ();
+
+ if (fn ().a[0] != 42)
+ __builtin_abort ();
+
+ __typeof__ (fn ()) *p = &x;
+ if (p->a[0] != 42)
+ __builtin_abort ();
+
+ if (fn2 ().a[0] != 42)
+ __builtin_abort ();
+}
+
+int
+main (void)
+{
+ foo (1);
+}