* [Bug c++/105774] Bogus overflow in constant expression
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
@ 2022-05-30 14:39 ` klaus.doldinger64 at googlemail dot com
2022-06-01 11:40 ` rguenth at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: klaus.doldinger64 at googlemail dot com @ 2022-05-30 14:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #1 from Wilhelm M <klaus.doldinger64 at googlemail dot com> ---
To make it more clear make the type of x *signed char`.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
2022-05-30 14:39 ` [Bug c++/105774] " klaus.doldinger64 at googlemail dot com
@ 2022-06-01 11:40 ` rguenth at gcc dot gnu.org
2022-10-22 20:55 ` [Bug c++/105774] Bogus overflow in constant expression with signed char++ pinskia at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-01 11:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |rejects-valid
Last reconfirmed| |2022-06-01
Ever confirmed|0 |1
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
2022-05-30 14:39 ` [Bug c++/105774] " klaus.doldinger64 at googlemail dot com
2022-06-01 11:40 ` rguenth at gcc dot gnu.org
@ 2022-10-22 20:55 ` pinskia at gcc dot gnu.org
2022-10-22 20:56 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 20:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Bogus overflow in constant |Bogus overflow in constant
|expression with char++ |expression with signed
| |char++
Known to fail| |5.1.0
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a C++14 testcase (lambdas were not constexpr in C++14) which shows the
issue has been there since GCC 5 (which didn't have C++17 support):
constexpr signed char f(void){
signed char x = 127;
return ++x;
}
int main() {
constexpr auto _ = f();
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (2 preceding siblings ...)
2022-10-22 20:55 ` [Bug c++/105774] Bogus overflow in constant expression with signed char++ pinskia at gcc dot gnu.org
@ 2022-10-22 20:56 ` pinskia at gcc dot gnu.org
2022-10-23 16:46 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 20:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
And one for short:
constexpr signed short f(void){
signed short x = 0x7fff;
return ++x;
}
int main() {
constexpr auto _ = f();
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (3 preceding siblings ...)
2022-10-22 20:56 ` pinskia at gcc dot gnu.org
@ 2022-10-23 16:46 ` jakub at gcc dot gnu.org
2022-10-24 14:26 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-23 16:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 53763
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53763&action=edit
gcc13-pr105774.patch
Untested fix.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (4 preceding siblings ...)
2022-10-23 16:46 ` jakub at gcc dot gnu.org
@ 2022-10-24 14:26 ` cvs-commit at gcc dot gnu.org
2022-10-25 9:05 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-24 14:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:da8c362c4c18cff2f2dfd5c4706bdda7576899a4
commit r13-3458-gda8c362c4c18cff2f2dfd5c4706bdda7576899a4
Author: Jakub Jelinek <jakub@redhat.com>
Date: Mon Oct 24 16:25:29 2022 +0200
c++: Fix up constexpr handling of char/signed char/short pre/post
inc/decrement [PR105774]
signed char, char or short int pre/post inc/decrement are represented by
normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification
ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those
types:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
{
tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
{
if (!TYPE_OVERFLOW_WRAPS (type))
type = unsigned_type_for (type);
return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
}
break;
}
This means during constant evaluation we need to do it similarly (either
using unsigned_type_for or using widening to integer_type_node).
The following patch does the latter.
2022-10-24 Jakub Jelinek <jakub@redhat.com>
PR c++/105774
* constexpr.cc (cxx_eval_increment_expression): For signed types
that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type.
* g++.dg/cpp1y/constexpr-105774.C: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (5 preceding siblings ...)
2022-10-24 14:26 ` cvs-commit at gcc dot gnu.org
@ 2022-10-25 9:05 ` jakub at gcc dot gnu.org
2022-11-03 0:23 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-25 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (6 preceding siblings ...)
2022-10-25 9:05 ` jakub at gcc dot gnu.org
@ 2022-11-03 0:23 ` cvs-commit at gcc dot gnu.org
2022-11-04 8:31 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-03 0:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:20ef7d7c578dab0585d70fbea571a74e8e8d4b47
commit r12-8888-g20ef7d7c578dab0585d70fbea571a74e8e8d4b47
Author: Jakub Jelinek <jakub@redhat.com>
Date: Mon Oct 24 16:25:29 2022 +0200
c++: Fix up constexpr handling of char/signed char/short pre/post
inc/decrement [PR105774]
signed char, char or short int pre/post inc/decrement are represented by
normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification
ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those
types:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
{
tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
{
if (!TYPE_OVERFLOW_WRAPS (type))
type = unsigned_type_for (type);
return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
}
break;
}
This means during constant evaluation we need to do it similarly (either
using unsigned_type_for or using widening to integer_type_node).
The following patch does the latter.
2022-10-24 Jakub Jelinek <jakub@redhat.com>
PR c++/105774
* constexpr.cc (cxx_eval_increment_expression): For signed types
that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type.
* g++.dg/cpp1y/constexpr-105774.C: New test.
(cherry picked from commit da8c362c4c18cff2f2dfd5c4706bdda7576899a4)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (7 preceding siblings ...)
2022-11-03 0:23 ` cvs-commit at gcc dot gnu.org
@ 2022-11-04 8:31 ` cvs-commit at gcc dot gnu.org
2023-05-03 15:19 ` cvs-commit at gcc dot gnu.org
2023-05-04 7:17 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-04 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:11a37955860f8573570aaf8d9fb0b6e02a3d4d5a
commit r11-10362-g11a37955860f8573570aaf8d9fb0b6e02a3d4d5a
Author: Jakub Jelinek <jakub@redhat.com>
Date: Mon Oct 24 16:25:29 2022 +0200
c++: Fix up constexpr handling of char/signed char/short pre/post
inc/decrement [PR105774]
signed char, char or short int pre/post inc/decrement are represented by
normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification
ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those
types:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
{
tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
{
if (!TYPE_OVERFLOW_WRAPS (type))
type = unsigned_type_for (type);
return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
}
break;
}
This means during constant evaluation we need to do it similarly (either
using unsigned_type_for or using widening to integer_type_node).
The following patch does the latter.
2022-10-24 Jakub Jelinek <jakub@redhat.com>
PR c++/105774
* constexpr.c (cxx_eval_increment_expression): For signed types
that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type.
* g++.dg/cpp1y/constexpr-105774.C: New test.
(cherry picked from commit da8c362c4c18cff2f2dfd5c4706bdda7576899a4)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (8 preceding siblings ...)
2022-11-04 8:31 ` cvs-commit at gcc dot gnu.org
@ 2023-05-03 15:19 ` cvs-commit at gcc dot gnu.org
2023-05-04 7:17 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-03 15:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:11bf3345c74139c05c405d3e5bc73ee8d9e7d6a6
commit r10-11340-g11bf3345c74139c05c405d3e5bc73ee8d9e7d6a6
Author: Jakub Jelinek <jakub@redhat.com>
Date: Mon Oct 24 16:25:29 2022 +0200
c++: Fix up constexpr handling of char/signed char/short pre/post
inc/decrement [PR105774]
signed char, char or short int pre/post inc/decrement are represented by
normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification
ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those
types:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
{
tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
{
if (!TYPE_OVERFLOW_WRAPS (type))
type = unsigned_type_for (type);
return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
}
break;
}
This means during constant evaluation we need to do it similarly (either
using unsigned_type_for or using widening to integer_type_node).
The following patch does the latter.
2022-10-24 Jakub Jelinek <jakub@redhat.com>
PR c++/105774
* constexpr.c (cxx_eval_increment_expression): For signed types
that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type.
* g++.dg/cpp1y/constexpr-105774.C: New test.
(cherry picked from commit da8c362c4c18cff2f2dfd5c4706bdda7576899a4)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/105774] Bogus overflow in constant expression with signed char++
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
` (9 preceding siblings ...)
2023-05-03 15:19 ` cvs-commit at gcc dot gnu.org
@ 2023-05-04 7:17 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-04 7:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 10.5 too.
^ permalink raw reply [flat|nested] 12+ messages in thread