https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105287

--- Comment #2 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to David Malcolm from comment #1)
> Confirmed; it's an assertion failing in
> ana::frame_region::get_region_for_local, due to a variable having NULL for
> its DECL_CONTEXT:
> 
> (gdb) list
> 869           case SSA_NAME:
> 870             {
> 871               if (tree var = SSA_NAME_VAR (expr))
> 872                 {
> 873                   if (DECL_P (var))
> 874                     gcc_assert (DECL_CONTEXT (var) == m_fun->decl);
> 875                 }
> 
> This is probably benign if assertions are disabled (perhaps the analyzer is
> being more fussy than the rest of the middle-end?)
> 
> (gdb) call debug_tree(var)
>  <var_decl 0x7fffea7c8750 D.2381
>     type <boolean_type 0x7fffea665b28 bool sizes-gimplified public unsigned
> type_6 QI
>         size <integer_cst 0x7fffea667048 constant 8>
>         unit-size <integer_cst 0x7fffea667060 constant 1>
>         align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
> 0x7fffea665b28 precision:1 min <integer_cst 0x7fffea6672a0 0> max
> <integer_cst 0x7fffea6672d0 1>
>         pointer_to_this <pointer_type 0x7fffea7bddc8>>
>     unsigned QI ../../src/gcc/testsuite/g++.dg/analyzer/pr105287.C:35:73
> size <integer_cst 0x7fffea667048 8> unit-size <integer_cst 0x7fffea667060 1>
>     align:8 warn_if_not_align:0>
> (gdb) p var.decl_minimal.context 
> $2 = <tree 0x0>
> 
> 
> The var_decl is "cond_var" created here in the C++ FE:
> 
> #4  0x0000000000b30ec2 in flatten_await_stmt (n=0x317b9b0,
> promoted=0x7fffffffcc40, temps_used=0x7fffffffcc70, replace_in=<optimized
> out>)
>     at ../../src/gcc/cp/coroutines.cc:2792
> 2792                tree cond_var  = build_lang_decl (VAR_DECL, NULL_TREE,
> cond_type);
> (gdb) list
> 2787            /* If the condition contains an await expression, then we 
> need to
> 2788               set that first and use a separate var.  */
> 2789            if (cp_walk_tree (&cond, find_any_await, &found, NULL))
> 2790              {
> 2791                tree cond_type = TREE_TYPE (cond);
> 2792                tree cond_var  = build_lang_decl (VAR_DECL, NULL_TREE,
> cond_type);
> 2793                DECL_ARTIFICIAL (cond_var) = true;
> 2794                layout_decl (cond_var, 0);
> 2795                gcc_checking_assert (!TYPE_NEEDS_CONSTRUCTING 
> (cond_type));
> 2796                cond = build2 (INIT_EXPR, cond_type, cond_var, cond);
> 2797                var_nest_node *ins
> 2798                  = new var_nest_node (cond_var, cond, n->prev, n);
> 2799                COND_EXPR_COND (n->init) = cond_var;
> 2800                flatten_await_stmt (ins, promoted, temps_used, NULL);
> 2801              }
> 
> Iain: shouldn't the DECL_CONTEXT be being set on var_decls created here?

I'd expect so; does build_lang_decl() not add them to the current context? [I
didn't look at the code, and memory might be faulty there].  If it doesn't then
I need to take a pass through and add the appropriate one.

Reply via email to