[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 Andrew Pinski 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 --- 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(); }
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #4 from Andrew Pinski --- And one for short: constexpr signed short f(void){ signed short x = 0x7fff; return ++x; } int main() { constexpr auto _ = f(); }
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 Jakub Jelinek 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 --- Created attachment 53763 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53763&action=edit gcc13-pr105774.patch Untested fix.
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #6 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:da8c362c4c18cff2f2dfd5c4706bdda7576899a4 commit r13-3458-gda8c362c4c18cff2f2dfd5c4706bdda7576899a4 Author: Jakub Jelinek 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 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.
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #7 from Jakub Jelinek --- Fixed on the trunk so far.
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #8 from CVS Commits --- The releases/gcc-12 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:20ef7d7c578dab0585d70fbea571a74e8e8d4b47 commit r12--g20ef7d7c578dab0585d70fbea571a74e8e8d4b47 Author: Jakub Jelinek 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 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)
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #9 from CVS Commits --- The releases/gcc-11 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:11a37955860f8573570aaf8d9fb0b6e02a3d4d5a commit r11-10362-g11a37955860f8573570aaf8d9fb0b6e02a3d4d5a Author: Jakub Jelinek 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 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)
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 --- Comment #10 from CVS Commits --- The releases/gcc-10 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:11bf3345c74139c05c405d3e5bc73ee8d9e7d6a6 commit r10-11340-g11bf3345c74139c05c405d3e5bc73ee8d9e7d6a6 Author: Jakub Jelinek 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 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)
[Bug c++/105774] Bogus overflow in constant expression with signed char++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105774 Jakub Jelinek changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #11 from Jakub Jelinek --- Fixed for 10.5 too.