https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70488
Bug ID: 70488
Summary: ICE in tree.c:7345 triggered by warning of placement
new too small
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: samschetgcc at gmail dot com
Target Milestone: ---
GCC built from revision 234633 fails with an ICE when trying to warn that the
buffer provided by placement new is too small if the array is a variable length
array on the stack:
when compiling this code:
struct failure_case {size_t s;};
void break_func(unsigned int s) {
char temp_buffer[sizeof(failure_case) + s];
failure_case *f = new (temp_buffer) failure_case;
};
$ ~/test_bin/bin/g++ repr_bug.cc
repr_bug.cc: In function ‘void break_func(int)’:
repr_bug.cc:16:41: internal compiler error: in tree_to_uhwi, at tree.c:7345
failure_case *f = new (temp_buffer) failure_case;
^~~~~~~~~~~~
0xf79502 tree_to_uhwi(tree_node const*)
../../trunk/gcc/tree.c:7345
0x763a8a warn_placement_new_too_small
../../trunk/gcc/cp/init.c:2438
0x763a8a build_new_1
../../trunk/gcc/cp/init.c:2994
0x765095 build_new(vec<tree_node*, va_gc, vl_embed>**, tree_node*, tree_node*,
vec<tree_node*, va_gc, vl_embed>**, int, int)
../../trunk/gcc/cp/init.c:3449
0x6fd366 cp_parser_new_expression
../../trunk/gcc/cp/parser.c:8140
0x6fd967 cp_parser_unary_expression
../../trunk/gcc/cp/parser.c:7848
0x707957 cp_parser_cast_expression
../../trunk/gcc/cp/parser.c:8665
0x707eed cp_parser_binary_expression
../../trunk/gcc/cp/parser.c:8766
0x7087b0 cp_parser_assignment_expression
../../trunk/gcc/cp/parser.c:9053
0x708bc7 cp_parser_constant_expression
../../trunk/gcc/cp/parser.c:9323
0x7093b4 cp_parser_initializer_clause
../../trunk/gcc/cp/parser.c:20791
0x70abab cp_parser_initializer
../../trunk/gcc/cp/parser.c:20734
0x71c71d cp_parser_init_declarator
../../trunk/gcc/cp/parser.c:18604
0x71d070 cp_parser_simple_declaration
../../trunk/gcc/cp/parser.c:12372
0x71d3aa cp_parser_block_declaration
../../trunk/gcc/cp/parser.c:12248
0x71deb9 cp_parser_declaration_statement
../../trunk/gcc/cp/parser.c:11860
0x71aa93 cp_parser_statement
../../trunk/gcc/cp/parser.c:10528
0x71b4a4 cp_parser_statement_seq_opt
../../trunk/gcc/cp/parser.c:10806
0x71b5af cp_parser_compound_statement
../../trunk/gcc/cp/parser.c:10760
0x71b70d cp_parser_function_body
../../trunk/gcc/cp/parser.c:20653
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
When removing the parameter addition, no warning is emitted and the code
compiles fine. Also, using a static size that is too small simply generates a
warning.
As a side note, the warning in this case could be considered spurious (although
overflow *could* generate too small of a buffer).