https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118775
Bug ID: 118775
Summary: ICE in tree_to_uhwi
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nickooo314 at gmail dot com
Target Milestone: ---
I am getting an internal compiler error when compiling the following code:
#include<memory>
int a;
int main() {
std::unique_ptr<char[]> p = std::make_unique<char[]>((uint64_t)&a);
return 0;
}
$ /gcc-install/bin/g++ -std=c++23 crash-test.cpp
In file included from /gcc-install/include/c++/15.0.1/memory:80,
from crash-test.cpp:1:
/gcc-install/include/c++/15.0.1/bits/unique_ptr.h: In function ‘int main()’:
crash-test.cpp:6:57: in ‘constexpr’ expansion of ‘std::make_unique<char
[]>(((uint64_t)(& a)))’
/gcc-install/include/c++/15.0.1/bits/unique_ptr.h:1092:30: internal compiler
error: in tree_to_uhwi, at tree.cc:6530
1092 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x29dd59f internal_error(char const*, ...)
/gcc-build/../gcc/gcc/diagnostic-global-context.cc:517
0xb02eef fancy_abort(char const*, int, char const*)
/gcc-build/../gcc/gcc/diagnostic.cc:1722
0xa11d85 tree_to_uhwi(tree_node const*)
/gcc-build/../gcc/gcc/tree.cc:6530
0xa11d85 tree_to_uhwi(tree_node const*)
/gcc-build/../gcc/gcc/tree.cc:6528
0xb691f7 cxx_eval_call_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:2913
0xb6ac97 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7688
0xb6ccf9 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7814
0xb6abd1 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:8055
0xb6a85a cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:8248
0xb67a88 cxx_bind_parameters_in_call
/gcc-build/../gcc/gcc/cp/constexpr.cc:1907
0xb67a88 cxx_eval_call_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:3059
0xb6ac97 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7688
0xb711c0 cxx_eval_store_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:6784
0xb6a5cc cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7841
0xb6b8ae cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7853
0xb6ae16 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7915
0xb68e7b cxx_eval_call_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:3312
0xb6ac97 cxx_eval_constant_expression
/gcc-build/../gcc/gcc/cp/constexpr.cc:7688
0xb77b02 cxx_eval_outermost_constant_expr
/gcc-build/../gcc/gcc/cp/constexpr.cc:8983
0xb7cf76 maybe_constant_value(tree_node*, tree_node*, mce_value)
/gcc-build/../gcc/gcc/cp/constexpr.cc:9278
The issue seems reproduceable in all GCC versions from 12 onward only when
using the -std=c++23 flag. It also only seems to work when 'a' is a global
variable.