https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92333
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2019-11-02 Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The otherwise untested change below changes the output to: gcc -O2 -S -Wall pr92333.c pr92333.c: In function ‘g’: pr92333.c:9:3: warning: writing 20 bytes into a region of size 5 [-Wstringop-overflow=] 9 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr92333.c:8:8: note: at offset 0 to object ‘vla.10’ with size 5 declared here 8 | char vla[nelts]; | ^~~ pr92333.c: In function ‘h’: pr92333.c:18:3: warning: array subscript 2 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr92333.c:17:8: note: while referencing ‘vla.12’ 17 | char vla[nelts]; | ^~~ pr92333.c:18:3: warning: array subscript 3 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr92333.c:17:8: note: while referencing ‘vla.12’ 17 | char vla[nelts]; | ^~~ pr92333.c:18:3: warning: array subscript 4 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr92333.c:17:8: note: while referencing ‘vla.12’ 17 | char vla[nelts]; | ^~~ pr92333.c:18:3: warning: writing 4 bytes into a region of size 1 [-Wstringop-overflow=] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr92333.c:17:8: note: at offset 0 to object ‘vla.12’ with size 5 declared here 17 | char vla[nelts]; | ^~~ diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index a8d0738fbb0..567aef8bc26 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -2222,7 +2222,25 @@ fold_builtin_alloca_with_align (gimple *stmt) elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1); n_elem = size * 8 / BITS_PER_UNIT; array_type = build_array_type_nelts (elem_type, n_elem); - var = create_tmp_var (array_type); + + if (tree ssa_name = SSA_NAME_IDENTIFIER (lhs)) + { + /* Give the temporary a name derived from the name of the VLA + declaration so it can be referenced in diagnostics. */ + const char *name = IDENTIFIER_POINTER (ssa_name); + var = create_tmp_var (array_type, name); + } + else + var = create_tmp_var (array_type); + + if (gimple *lhsdef = SSA_NAME_DEF_STMT (lhs)) + { + /* Set the temporary's location to that of the VLA declaration + so it can be pointed to in diagnostics. */ + location_t loc = gimple_location (lhsdef); + DECL_SOURCE_LOCATION (var) = loc; + } + SET_DECL_ALIGN (var, TREE_INT_CST_LOW (gimple_call_arg (stmt, 1))); if (uid != 0) SET_DECL_PT_UID (var, uid);