-
- Downloads
Fix handling of overflow in C casts in integer constant expressions (PR c/93241).
Bug 93241 reports a case where certain C expressions involving casts, that would not be valid in an evaluated part of an integer constant expression (because of e.g. involving integer overflow), are wrongly rejected in an unevaluated part of an integer constant expression even though all the operands and operations are ones that are valid in that context. This is a rejects-valid regression in GCC 4.5 and later relative to 4.4 (for some testcases; the one in the bug uses _Static_assert which isn't supported in those older releases). The rule in the C front end is that an expression with those properties (valid in an unevaluated part of an integer constant expression but not an evaluated part) must be represented either as an INTEGER_CST with TREE_OVERFLOW set or as a C_MAYBE_CONST_EXPR with C_MAYBE_CONST_EXPR_INT_OPERANDS set. This patch fixes build_c_cast to check for that case and call note_integer_operands as needed. Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/93241 gcc/c: * c-typeck.c (build_c_cast): Check for expressions with integer operands that can occur in an unevaluated part of an integer constant expression and call note_integer_operands as needed. gcc/testsuite: * gcc.dg/c11-static-assert-10.c, gcc.dg/c99-const-expr-15.c: New tests.
Showing
- gcc/c/ChangeLog 7 additions, 0 deletionsgcc/c/ChangeLog
- gcc/c/c-typeck.c 10 additions, 0 deletionsgcc/c/c-typeck.c
- gcc/testsuite/ChangeLog 6 additions, 0 deletionsgcc/testsuite/ChangeLog
- gcc/testsuite/gcc.dg/c11-static-assert-10.c 9 additions, 0 deletionsgcc/testsuite/gcc.dg/c11-static-assert-10.c
- gcc/testsuite/gcc.dg/c99-const-expr-15.c 9 additions, 0 deletionsgcc/testsuite/gcc.dg/c99-const-expr-15.c
Loading
Please register or sign in to comment