https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128673
Bug ID: 128673
Summary: [14 Regression] ICE in
aarch64_lookup_shared_state_flags with [[nodiscard]]
class template and abi_tag argument
Product: gcc
Version: 14.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: jur.zikmund at gmail dot com
Target Milestone: ---
Host: aarch64-linux-gnu
Target: aarch64-linux-gnu
Build: aarch64-linux-gnu
Created attachment 66140
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66140&action=edit
Preprocessed testcase (-save-temps)
The following valid C++17 code makes cc1plus segfault on aarch64 with
GCC 14.4.0. It compiles without warnings (-Wall -Wextra) with GCC 13.5.0,
15.3.0 and 16.2.0 on aarch64, and with GCC 14.4.0 on x86_64.
The testcase includes no headers; the preprocessed file is attached.
$ cat t.cpp
struct [[gnu::abi_tag("t")]] Tagged {};
template <class T> struct [[nodiscard]] Base {};
template <class T> struct Outer {
struct Derived : Base<T> {
const Derived* cast(const Base<T>* p) { return static_cast<const
Derived*>(p); }
};
};
template struct Outer<Tagged>::Derived;
$ g++ -std=c++17 -Wall -Wextra -c t.cpp
t.cpp: In instantiation of 'const Outer<T>::Derived*
Outer<T>::Derived::cast(const Base<T>*) [with T = Tagged]':
t.cpp:11:32: required from here
11 | template struct Outer<Tagged>::Derived;
| ^~~~~~~
t.cpp:7:52: internal compiler error: Segmentation fault
7 | const Derived* cast(const Base<T>* p) { return
static_cast<const Derived*>(p); }
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x1d12547 internal_error(char const*, ...)
???:0
0x9b12d3 comp_type_attributes(tree_node const*, tree_node const*)
???:0
0x7aebcb perform_direct_initialization_if_possible(tree_node*, tree_node*,
bool, int)
???:0
0x99f2df build_static_cast(unsigned int, tree_node*, tree_node*, int)
???:0
0x93479f tsubst_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x93f5b3 instantiate_decl(tree_node*, bool, bool)
???:0
0x952ee7 instantiate_pending_templates(int)
???:0
0x83b357 c_parse_final_cleanups()
???:0
0xa0ae6f c_common_parse_file()
???:0
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.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/aarch64-linux-gnu/14.4.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: /usr/src/gcc/configure --build=aarch64-linux-gnu
--disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.4.0 (GCC)
This is the official Docker Hub gcc:14 image (built from the release
tarball): docker run --platform linux/arm64 gcc:14
Results (same command line):
14.4.0 aarch64 ICE
13.5.0 aarch64 OK
15.3.0 aarch64 OK
16.2.0 aarch64 OK
14.4.0 x86_64 OK
Any one of these changes makes it compile on 14.4.0 aarch64:
- removing [[nodiscard]]
- replacing [[nodiscard]] with [[gnu::warn_unused]]
- removing the abi_tag
- moving Derived out of Outer to namespace scope
In real code this shows up with GoogleTest 1.18 (for context only; the
testcase above is the self-contained reproducer):
#include <string>
#include <gtest/gtest.h>
class P : public testing::TestWithParam<std::string> {};
TEST_P(P, X) {}
INSTANTIATE_TEST_SUITE_P(I, P, testing::Values(std::string("a")));
GoogleTest 1.18 marks ParamIteratorInterface [[nodiscard]], and
std::string carries the cxx11 abi_tag. Red Hat's GCC 14.3.1 (14.3.1-4,
Rocky Linux 10) on aarch64 crashes the same way.
A gdb backtrace of the Rocky Linux 10 cc1plus shows the segfault one
level below the frame GCC prints:
aarch64_lookup_shared_state_flags <- SIGSEGV
aarch64_comp_type_attributes
comp_type_attributes
structural_comptypes
standard_conversion
implicit_conversion
perform_direct_initialization_if_possible
build_static_cast_1
build_static_cast
...
Possibly related:
aarch64_lookup_shared_state_flags in GCC 14 reads the namespace of every
C++11-style attribute:
if (!cxx11_attribute_p (attr))
continue;
auto ns = IDENTIFIER_POINTER (TREE_PURPOSE (TREE_PURPOSE (attr)));
[[nodiscard]] has no namespace, which could explain a NULL dereference
here. PR116598 found the same assumption with C23 [[reproducible]]
("aarch64_lookup_shared_state_flags does NOT handle attributes in the
global namespace"), and r15-3517 fixed it on trunk using
is_attribute_namespace_p and get_attribute_name. That change is not on
releases/gcc-14, perhaps because those C23 attributes don't exist in
GCC 14; [[nodiscard]] would be a GCC 14 trigger.
I have not verified that r15-3517 fixes this testcase, and I don't know
why the abi_tag and the nested class are needed to reach this path.
The aarch64 runs above were under QEMU user emulation; the same ICE
occurs on native aarch64 GitHub Actions runners (Rocky Linux 10).