https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112830
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ebotcazou at gcc dot gnu.org --- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- I'm struggling in creating test coverage for the *VLA = {} gimplification to memset. If I convince the C frontend to accept void bar (int n, __seg_fs void *p) { typedef struct { char t[n]; } T; *(__seg_fs T *)p = (T) {}; } with diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index df9a07928b5..a94270b6065 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -12223,12 +12223,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, || (scspecs && scspecs->storage_class == csc_static) || constexpr_p), constexpr_p, &richloc); type = groktypename (type_name, &type_expr, &type_expr_const); - if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) - { - error_at (type_loc, "compound literal has variable size"); - type = error_mark_node; - } - else if (TREE_CODE (type) == FUNCTION_TYPE) + if (TREE_CODE (type) == FUNCTION_TYPE) { error_at (type_loc, "compound literal has function type"); type = error_mark_node; @@ -12257,6 +12252,13 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, finish_init (); maybe_warn_string_init (type_loc, type, init); + if (type != error_mark_node + && C_TYPE_VARIABLE_SIZE (type) + && CONSTRUCTOR_NELTS (init.value) != 0) + { + error_at (type_loc, "compound literal has variable size"); + type = error_mark_node; + } if (type != error_mark_node && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) && current_function_decl) then I see the gimplifier fails to wrap the CONSTRUCTOR inside a WITH_SIZE_EXPR which could be fixed with diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index a1d5ee28cbe..ae339c4a82a 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -5787,6 +5787,7 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, tree rhs = TREE_OPERAND (*expr_p, 1); if (want_value && object == lhs) lhs = unshare_expr (lhs); + maybe_with_size_expr (&rhs); gassign *init = gimple_build_assign (lhs, rhs); gimplify_seq_add_stmt (pre_p, init); } diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index a075fa38fba..e81b3f6ba72 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -3363,7 +3363,10 @@ verify_types_in_gimple_reference (tree expr, bool require_lvalue) } if (!require_lvalue - && (is_gimple_reg (expr) || is_gimple_min_invariant (expr))) + && (is_gimple_reg (expr) + || is_gimple_min_invariant (expr) + || (TREE_CODE (expr) == CONSTRUCTOR + && CONSTRUCTOR_NELTS (expr) == 0))) return false; if (TREE_CODE (expr) != SSA_NAME && is_gimple_id (expr)) but then of course RTL expansion isn't prepared for this - we run into store_expr expanding the CTOR but it would require special-casing such RHS to eventually either call store_constructor or clear_storage_hints directly. Does Ada have support for address-spaces and is there a way to construct a testcase that requires clearing of a VLA object in another address-space?