* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
@ 2024-02-08 16:48 ` ivan.lazaric.gcc at gmail dot com
2024-02-09 0:15 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ivan.lazaric.gcc at gmail dot com @ 2024-02-08 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #1 from Ivan Lazaric <ivan.lazaric.gcc at gmail dot com> ---
Created attachment 57362
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57362&action=edit
Preprocessed file generated by `-freport-bug`
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
@ 2024-02-09 0:15 ` pinskia at gcc dot gnu.org
2024-02-09 2:49 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09 0:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reducing, this looks like an ICE after an error ...
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
2024-02-09 0:15 ` pinskia at gcc dot gnu.org
@ 2024-02-09 2:49 ` pinskia at gcc dot gnu.org
2024-02-09 7:02 ` [Bug c++/113834] [14 Regression] " pinskia at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09 2:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
template <typename... _Elements> class tuple{};
template <unsigned long __i, typename... _Elements>
__type_pack_element<__i, _Elements...> &get(tuple<_Elements...> &__t) noexcept;
tuple<int,int> data;
template <unsigned long Level>
unsigned take_impl(unsigned idx) {
if constexpr (Level != -1){
return take_impl<Level - 1>(get<Level - 1>(data));
}
return 0;
}
int main() {
take_impl<2>(0);
}
```
Note I think this is invalid code ...
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (2 preceding siblings ...)
2024-02-09 2:49 ` pinskia at gcc dot gnu.org
@ 2024-02-09 7:02 ` pinskia at gcc dot gnu.org
2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09 7:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2024-02-09
Summary|internal compiler error: in |[14 Regression] internal
|tree_to_shwi, at |compiler error: in
|tree.cc:6461 |tree_to_shwi, at
| |tree.cc:6461
CC| |ppalka at gcc dot gnu.org
Target Milestone|--- |14.0
Keywords|needs-bisection |
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
__type_pack_element support was introduced in r14-92-g58b7dbf865b146 .
So yes this is visual regression in that using the libstdc++ headers in GCC 13
will not ICE but using them in GCC 14+, there will be an ICE.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (3 preceding siblings ...)
2024-02-09 7:02 ` [Bug c++/113834] [14 Regression] " pinskia at gcc dot gnu.org
@ 2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
To fix the ICE we could do:
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4644,7 +4644,9 @@ static tree
finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
{
idx = maybe_constant_value (idx);
- if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
+ if (TREE_CODE (idx) != INTEGER_CST
+ || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
+ || !tree_fits_shwi_p (idx))
{
if (complain & tf_error)
error ("%<__type_pack_element%> index is not an integral constant");
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (4 preceding siblings ...)
2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
2024-02-09 13:37 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (5 preceding siblings ...)
2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:37 ` jakub at gcc dot gnu.org
2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-09 13:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #5)
> To fix the ICE we could do:
>
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -4644,7 +4644,9 @@ static tree
> finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
> {
> idx = maybe_constant_value (idx);
> - if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
> + if (TREE_CODE (idx) != INTEGER_CST
> + || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
> + || !tree_fits_shwi_p (idx))
> {
> if (complain & tf_error)
> error ("%<__type_pack_element%> index is not an integral constant");
But then the diagnostics is confusing.
Perhaps use tree_int_cst_sgn (idx) < 0 instead of tree_to_shwi + val < 0,
wi::to_widest (idx) >= TREE_VEC_LENGTH (types) for out of range and
only use tree_to_shwi after those checks?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (6 preceding siblings ...)
2024-02-09 13:37 ` jakub at gcc dot gnu.org
@ 2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
2024-02-09 13:53 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #6)
> (In reply to Marek Polacek from comment #5)
> > To fix the ICE we could do:
> >
> > --- a/gcc/cp/semantics.cc
> > +++ b/gcc/cp/semantics.cc
> > @@ -4644,7 +4644,9 @@ static tree
> > finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
> > {
> > idx = maybe_constant_value (idx);
> > - if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
> > + if (TREE_CODE (idx) != INTEGER_CST
> > + || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
> > + || !tree_fits_shwi_p (idx))
> > {
> > if (complain & tf_error)
> > error ("%<__type_pack_element%> index is not an integral constant");
>
> But then the diagnostics is confusing.
There's a lot of places where we do exactly that:
handle_assume_aligned_attribute, ...
> Perhaps use tree_int_cst_sgn (idx) < 0 instead of tree_to_shwi + val < 0,
> wi::to_widest (idx) >= TREE_VEC_LENGTH (types) for out of range and
> only use tree_to_shwi after those checks?
That sounds good too though, I can do that instead.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (7 preceding siblings ...)
2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:53 ` jakub at gcc dot gnu.org
2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-09 13:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #7)
> > But then the diagnostics is confusing.
>
> There's a lot of places where we do exactly that:
> handle_assume_aligned_attribute, ...
Sure, I know. In some cases it is from assumption that one uses reasonable
types and values for say alignments or sizes etc., in other cases laziness,
diagnose something and if it in the corner cases diagnoses something slightly
different, user can figure it out.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (8 preceding siblings ...)
2024-02-09 13:53 ` jakub at gcc dot gnu.org
@ 2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-09 21:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:f29f7f86935e29786bf9f976ec99d7639b381b14
commit r14-8904-gf29f7f86935e29786bf9f976ec99d7639b381b14
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Feb 9 12:03:50 2024 -0500
c++: fix ICE with __type_pack_element [PR113834]
Here we crash on this invalid code because we seem to infinitely recurse
and end up with __type_pack_element with index that doesn't
tree_fits_shwi_p
which then crashes on tree_to_shwi.
Thanks to Jakub for suggesting a nicer fix than my original one.
PR c++/113834
gcc/cp/ChangeLog:
* semantics.cc (finish_type_pack_element): Perform range checking
before tree_to_shwi.
gcc/testsuite/ChangeLog:
* g++.dg/ext/type_pack_element4.C: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
` (9 preceding siblings ...)
2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
@ 2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 12+ messages in thread