https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123369
Bug ID: 123369
Summary: ICE: error reporting routines re-entered when
instantiating template with overaligned array elements
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 522024330006 at smail dot nju.edu.cn
Target Milestone: ---
Reproducer: https://godbolt.org/z/vPnWG7P5K
GCC crashes instead of providing a standard error message when a template is
instantiated with a function pointer involving an overaligned typedef, and that
template contains an array of the same overaligned type.
The error "alignment of array elements is greater than element size" may
trigger a recursive call in the diagnostic formatter when it attempts to print
the template argument (F), leading to "error reporting routines re-entered".
Code:
```
#include <functional>
typedef int myint __attribute__ ((__aligned__ (16)));
using FuncPtr = void (*)(myint*);
template <typename F>
void call_template_func(F& func) {
myint data[1];
func(&data);
}
void outer_arr_caller(FuncPtr cbp) {
call_template_func(cbp);
}
```
Part of the traceback:
```
error: alignment of array elements is greater than element size
[-Wtemplate-body]
11 | myint data[1];
| ^
internal compiler error: error reporting routines re-entered.
0x5da0e75 error(char const*, ...)
/workspace/install/gcc/src/gcc/gcc/diagnostic-global-context.cc:397
0x27134ce layout_type(tree_node*)
/workspace/install/gcc/src/gcc/gcc/stor-layout.cc:2753
0x163cf96 build_cplus_array_type(tree_node*, tree_node*, int)
/workspace/install/gcc/src/gcc/gcc/cp/tree.cc:1199
0x164061e strip_typedefs(tree_node*, bool*, unsigned int)
/workspace/install/gcc/src/gcc/gcc/cp/tree.cc:1706
0x163fef8 strip_typedefs(tree_node*, bool*, unsigned int)
/workspace/install/gcc/src/gcc/gcc/cp/tree.cc:1681
0x117b567 type_to_string
/workspace/install/gcc/src/gcc/gcc/cp/error.cc:3582
0x1181df9 cxx_format_postprocessor::handle(pretty_printer*)
/workspace/install/gcc/src/gcc/gcc/cp/error.cc:4598
0x5df4577 pretty_printer::format(text_info&)
/workspace/install/gcc/src/gcc/gcc/pretty-print.cc:1716
0x18ac446 pp_format(pretty_printer*, text_info*)
/workspace/install/gcc/src/gcc/gcc/pretty-print.h:594
0x5d3e8a4 diagnostic_context::report_diagnostic(diagnostic_info*)
/workspace/install/gcc/src/gcc/gcc/diagnostic.cc:1505
0x5d3f2b7 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
/workspace/install/gcc/src/gcc/gcc/diagnostic.cc:1641
0x5da1431 error_at(rich_location*, char const*, ...)
/workspace/install/gcc/src/gcc/gcc/diagnostic-global-context.cc:439
0x16d8f0f convert_for_assignment
/workspace/install/gcc/src/gcc/gcc/cp/typeck.cc:10601
0x16da994 convert_for_initialization(tree_node*, tree_node*, tree_node*, int,
impl_conv_rhs, tree_node*, int, int)
/workspace/install/gcc/src/gcc/gcc/cp/typeck.cc:10785
0x16af8c9 convert_arguments
/workspace/install/gcc/src/gcc/gcc/cp/typeck.cc:4794
0x16ae8e8 cp_build_function_call_vec(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int, tree_node*)
/workspace/install/gcc/src/gcc/gcc/cp/typeck.cc:4623
0x15cce11 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
bool, bool, int)
/workspace/install/gcc/src/gcc/gcc/cp/semantics.cc:3529
0x152b165 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
/workspace/install/gcc/src/gcc/gcc/cp/pt.cc:21632
0x151d8fd tsubst_stmt
/workspace/install/gcc/src/gcc/gcc/cp/pt.cc:20049
0x150f0b8 tsubst_stmt
/workspace/install/gcc/src/gcc/gcc/cp/pt.cc:18920
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
```