https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80659
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #6)
> Marek, can you please take a look why the VAR_DECL built from the expr_stmt
> is not assigned in a BIND_EXPR?
In C, non-static compound literals aren't pushed into any scope, so the
BIND_EXPR doesn't have that VAR_DECL. But instead of pushing such complits
into any scope we might just mark it as an artificial decl; I noticed
1647 if (!DECL_ARTIFICIAL (decl) && gimplify_ctxp->live_switch_vars)
1648 gimplify_ctxp->live_switch_vars->add (decl);
1649 }
so I think this should fix it:
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5265,6 +5265,7 @@ build_compound_literal (location_t loc, tree type, tree
init, bool non_const)
TREE_READONLY (decl) = (TYPE_READONLY (type)
|| (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_READONLY (TREE_TYPE (type))));
+ DECL_ARTIFICIAL (decl) = 1;
store_init_value (loc, decl, init, NULL_TREE);
if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
@@ -5297,7 +5298,6 @@ build_compound_literal (location_t loc, tree type, tree
init, bool non_const)
set_compound_literal_name (decl);
DECL_DEFER_OUTPUT (decl) = 1;
DECL_COMDAT (decl) = 1;
- DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
pushdecl (decl);
rest_of_decl_compilation (decl, 1, 0);