[Bug c++/106152] New: New ICE compiling template expressions

2022-06-30 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106152

Bug ID: 106152
   Summary: New ICE compiling template expressions
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: byteslice at airmail dot cc
  Target Milestone: ---

Created attachment 53229
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53229=edit
Reduced example

Compile with -std=gnu++20. No ICE on 12.

g++ (f35dbc02092fbcd3d814fcd9fe8e871c3f741fd, binutils-2.38) 13.0.0 20220626

--

: In instantiation of 'struct invert_typelist_impl >':
:20:75:   required from 'struct invert_typelist >'
:22:11:   required from here
:15:21: internal compiler error: in iterative_hash_template_arg, at
cp/pt.cc:1819
   15 |   static const long last_idx;
  | ^~~~
0x2212db9 internal_error(char const*, ...)
???:0
0x74a531 fancy_abort(char const*, int, char const*)
???:0
0x9a2397 iterative_hash_template_arg(tree_node*, unsigned int)
???:0
0x9a16bd iterative_hash_template_arg(tree_node*, unsigned int)
???:0
0x9cb387 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x9f7d56 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x9caeea tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x9e6987 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
???:0
0x9f7fd2 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x9cb0e9 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x9cb387 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xa118b1 instantiate_class_template(tree_node*)
???:0
0xa11b27 instantiate_class_template(tree_node*)
???:0
0xa87f8b complete_type_or_maybe_complain(tree_node*, tree_node*, int)
???:0
0x9b8750 process_template_parm(tree_node*, unsigned int, tree_node*, bool,
bool)
???:0
0x993a5d c_parse_file()
???:0
0xb2a161 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  for instructions.

[Bug tree-optimization/105420] Bogus -Warray-bounds with non-compile time-constant variable

2022-04-29 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105420

--- Comment #2 from Liam White  ---
Created attachment 52906
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52906=edit
Preprocessed source

The first attachment is automatically and manually reduced from the following
source:

ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr
user_stack_top, s32 prio,
   s32 virt_core, KProcess* owner, ThreadType type)
{
// Assert parameters are valid.
ASSERT((type == ThreadType::Main) || (type == ThreadType::Dummy) ||
   (Svc::HighestThreadPriority <= prio && prio <=
Svc::LowestThreadPriority));
ASSERT((owner != nullptr) || (type != ThreadType::User));
ASSERT(0 <= virt_core && virt_core <
static_cast(Common::BitSize()));

// Convert the virtual core to a physical core.
const s32 phys_core = Core::Hardware::VirtualToPhysicalCoreMap[virt_core];
ASSERT(0 <= phys_core && phys_core <
static_cast(Core::Hardware::NUM_CPU_CORES));

// ...
}

And it produces this compiler error (compile this preprocessed source with -O2
-Werror=array-bounds -std=gnu++20):

In static member function ‘static constexpr _Tp& std::__array_traits<_Tp,
_Nm>::_S_ref(const _Tp (&)[_Nm], std::size_t) [with _Tp = int; long unsigned
int _Nm = 64]’,
inlined from ‘constexpr const std::array<_Tp, _Nm>::value_type&
std::array<_Tp, _Nm>::operator[](size_type) const [with _Tp = int; long
unsigned int _Nm = 64]’ at k_thread.cpp:59748:25,
inlined from ‘ResultCode
Kernel::KThread::Initialize(Kernel::KThreadFunction, uintptr_t, VAddr, s32,
s32, Kernel::KProcess*, Kernel::ThreadType)’ at k_thread.cpp:102280:77:
k_thread.cpp:59638:36: error: array subscript 64 is above array bounds of
‘std::__array_traits::_Type’ {aka ‘const int [64]’}
[-Werror=array-bounds]
59638 |   { return const_cast<_Tp&>(__t[__n]); }
  | ~~~^
k_thread.cpp: In member function ‘ResultCode
Kernel::KThread::Initialize(Kernel::KThreadFunction, uintptr_t, VAddr, s32,
s32, Kernel::KProcess*, Kernel::ThreadType)’:
k_thread.cpp:77557:51: note: while referencing
‘Core::Hardware::VirtualToPhysicalCoreMap’
77557 | constexpr std::array()>
VirtualToPhysicalCoreMap{
  |  
^~~~
cc1plus: some warnings being treated as errors

I generally believe that this is a bug in the compiler as the array is
similarly never accessed with the constant value 64.

[Bug tree-optimization/105423] Bogus -Werror=maybe-uninitialized with definitely initialized variable

2022-04-29 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105423

--- Comment #2 from Liam White  ---
My bad, use -std=c++20 as well for this example. Then you should reproduce the
issue.

[Bug middle-end/105424] Bogus -Wstringop-overread with non-overread condition

2022-04-28 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105424

--- Comment #3 from Liam White  ---
Compile with c++ -std=gnu++20 -O1 -Werror=stringop-overread to reproduce.

[Bug middle-end/105424] Bogus -Wstringop-overread with non-overread condition

2022-04-28 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105424

Liam White  changed:

   What|Removed |Added

  Attachment #52897|0   |1
is obsolete||

--- Comment #2 from Liam White  ---
Created attachment 52901
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52901=edit
Preprocessed source

[Bug c++/105424] New: Bogus -Wstringop-overread with non-overread condition

2022-04-28 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105424

Bug ID: 105424
   Summary: Bogus -Wstringop-overread with non-overread condition
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: byteslice at airmail dot cc
  Target Milestone: ---

Created attachment 52897
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52897=edit
Cvised example

On gcc 12.0.1 20220413 (Fedora 36 Beta), with c++ -std=c++20 -O1
-Werror=stringop-overread, the attachment fails to compile, with the following
message:

In function 'void boost::memmove(I, F) [with I = move_iterator; F =
int]',
inlined from 'F boost::uninitialized_copy_alloc(Allocator, I, F) [with
Allocator = vector_alloc_holder; I = move_iterator; F = int]' at
:67:10,
inlined from 'void
boost::vector::priv_uninitialized_construct_at_end(InpIt, InpIt) [with InpIt =
boost::move_iterator]' at :91:45,
inlined from 'void boost::vector::assign(FwdIt, FwdIt) [with FwdIt =
boost::move_iterator]' at :87:42,
inlined from 'boost::small_vector::small_vector(boost::small_vector&&)' at
:106:11,
inlined from 'Stack::Stack(Stack&&)' at :113:8,
inlined from 'pair<_T2>::pair(_U1, _U2) [with _U1 = int; _U2 = Stack; _T2 =
Stack]' at :5:24,
inlined from 'pair Stack::Pop() const' at :118:67:
:63:14: error: 'void* memmove(void*, const void*, long unsigned int)'
reading 9 or more bytes from a region of size 4 [-Werror=stringop-overread]
   63 | ::memmove(dest_raw, beg_raw, n);
  | ~^~
: In member function 'pair Stack::Pop() const':
:103:9: note: source object '__trans_tmp_4' of size 4
  103 | int __trans_tmp_4;
  | ^
cc1plus: some warnings being treated as errors
Compiler returned: 1

This warning is bogus because the memmove is guarded by a condition that
prevents the size from being more than 4. The bogus warning does not appear in
older versions of GCC.

Adding -fno-inline to options allows compilation to succeed.

[Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable

2022-04-28 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105423

Bug ID: 105423
   Summary: Bogus -Werror=maybe-uninitialized with definitely
initialized variable
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: byteslice at airmail dot cc
  Target Milestone: ---

Created attachment 52896
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52896=edit
Cvised example

On gcc 12.0.1 20220413 (Fedora 36 Beta), with c++ -O1
-Werror=maybe-uninitialized, the attachment fails to compile, with the
following message:

In member function 'void std::Trans_NS___cxx11_basic_string<_CharT,
,  >::_S_copy(_CharT*) [with
_CharT = char; _Traits = std::char_traits;  = char]',
inlined from 'constexpr std::Trans_NS___cxx11_basic_string<_CharT, _Traits,
_Alloc>& std::Trans_NS___cxx11_basic_string<_CharT, ,
 >::_M_replace(const _CharT*, long int) [with _CharT =
char; _Traits = std::char_traits;  = char]' at
:49:12,
inlined from 'void std::Trans_NS___cxx11_basic_string<_CharT,
,  >::operator=(const _CharT*)
[with _CharT = char; _Traits = std::char_traits;  =
char]' at :40:15,
inlined from 'void Shuffle()' at :55:8:
:36:46: error: '((char*)((char*) +
offsetof(std::Trans_NS___cxx11_basic_string,std::Trans_NS___cxx11_basic_string::)))[2]' may be used uninitialized [-Werror=maybe-uninitialized]
   36 |   void _S_copy(_CharT *__s) { _Traits::assign(_S_copy___d, *__s); }
  |   ~~~^~~
: In function 'void Shuffle()':
:54:44: note: 'mask' declared here
   54 |   std::Trans_NS___cxx11_basic_string mask{};
  |^~~~
In member function 'void std::Trans_NS___cxx11_basic_string<_CharT,
,  >::_S_copy(_CharT*) [with
_CharT = char; _Traits = std::char_traits;  = char]',
inlined from 'constexpr std::Trans_NS___cxx11_basic_string<_CharT, _Traits,
_Alloc>& std::Trans_NS___cxx11_basic_string<_CharT, ,
 >::_M_replace(const _CharT*, long int) [with _CharT =
char; _Traits = std::char_traits;  = char]' at
:49:12,
inlined from 'void std::Trans_NS___cxx11_basic_string<_CharT,
,  >::operator=(const _CharT*)
[with _CharT = char; _Traits = std::char_traits;  =
char]' at :40:15,
inlined from 'void Shuffle()' at :55:8:
:36:47: error:
'mask.std::Trans_NS___cxx11_basic_string::_S_copy___d' may be used
uninitialized [-Werror=maybe-uninitialized]
   36 |   void _S_copy(_CharT *__s) { _Traits::assign(_S_copy___d, *__s); }
  |   ^~~
: In function 'void Shuffle()':
:54:44: note: 'mask' declared here
   54 |   std::Trans_NS___cxx11_basic_string mask{};
  |^~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1

This warning is bogus because the variable mask is default brace-initialized
and thus its member _S_copy___d is also initialized. The bogus warning does not
appear in older versions of GCC.

Adding -fno-inline to options allows compilation to succeed.

[Bug tree-optimization/105420] New: Bogus -Warray-bounds with non-compile time-constant variable

2022-04-28 Thread byteslice at airmail dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105420

Bug ID: 105420
   Summary: Bogus -Warray-bounds with non-compile time-constant
variable
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: byteslice at airmail dot cc
  Target Milestone: ---

Created attachment 52894
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52894=edit
Reduced example

On gcc 12.0.1 20220413 (Fedora 36 Beta), with c++ -O1 -fexpensive-optimizations
-ftree-vrp -Werror=array-bounds, the attachment fails to compile, with the
following message:

: In function 'void Initialize(int)':
:9:53: error: array subscript -1 is below array bounds of 'int [8]'
[-Werror=array-bounds]
9 |   int phys_core = VirtualToPhysicalCoreMap[virt_core];
  |   ~~^
:2:5: note: while referencing 'VirtualToPhysicalCoreMap'
2 | int VirtualToPhysicalCoreMap[8];
  | ^~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1

virt_core does not have a compile time-constant evaluation, so this warning is
bogus. The bogus warning does not appear in older versions of GCC.

Removing either -fexpensive-optimizations or -ftree-vrp allows compilation to
succeed.