[Bug c/111059] [11/12/13/14 Regression] ICE: in gimplify_expr, at gimplify.cc:17253

2024-01-30 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111059

--- Comment #6 from GCC Commits  ---
The master branch has been updated by Joseph Myers :

https://gcc.gnu.org/g:35de88e2ed0aa78f6e3306c8560cd6bb15ce0ffe

commit r14-8641-g35de88e2ed0aa78f6e3306c8560cd6bb15ce0ffe
Author: Joseph Myers 
Date:   Wed Jan 31 01:24:21 2024 +

c: Fix ICEs casting expressions with integer constant operands to bool
[PR111059, PR111911]

C front-end bugs 111059 and 111911 both report ICEs with conversions
to boolean of expressions with integer constant operands that can
appear in an integer constant expression as long as they are not
evaluated (such as division by zero).

The issue is a nested C_MAYBE_CONST_EXPR, with the inner one generated
in build_binary_op to indicate that a subexpression has been fully
folded and should not be folded again, and the outer one in
build_c_cast to indicate that the expression has integer constant
operands.  To avoid the inner one from build_binary_op,
c_objc_common_truthvalue_conversion should be given an argument
properly marked as having integer constant operands rather than that
information having been removed by the caller - but because c_convert
would then also wrap a C_MAYBE_CONST_EXPR with a NOP_EXPR converting
to boolean, it seems most convenient to have
c_objc_common_truthvalue_conversion produce the NE_EXPR directly in
the desired type (boolean in this case), before generating any
C_MAYBE_CONST_EXPR there, rather than it always producing a comparison
in integer_type_node and doing a conversion to boolean in the caller.

The same issue as in those PRs also applies for conversion to enums
with a boolean fixed underlying type; that case is also fixed and
tests added for it.  Note that not all the tests added failed before
the patch (in particular, the issue was specific to casts and did not
apply for implicit conversions, but some tests of those are added as
well).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/111059
PR c/111911

gcc/c/
* c-tree.h (c_objc_common_truthvalue_conversion): Add third
argument.
* c-convert.cc (c_convert): For conversions to boolean, pass third
argument to c_objc_common_truthvalue_conversion rather than
converting here.
* c-typeck.cc (build_c_cast): Ensure arguments with integer
operands are marked as such for conversion to boolean.
(c_objc_common_truthvalue_conversion): Add third argument TYPE.

gcc/testsuite/
* gcc.c-torture/compile/pr111059-1.c,
gcc.c-torture/compile/pr111059-2.c,
gcc.c-torture/compile/pr111059-3.c,
gcc.c-torture/compile/pr111059-4.c,
gcc.c-torture/compile/pr111059-5.c,
gcc.c-torture/compile/pr111059-6.c,
gcc.c-torture/compile/pr111059-7.c,
gcc.c-torture/compile/pr111059-8.c,
gcc.c-torture/compile/pr111059-9.c,
gcc.c-torture/compile/pr111059-10.c,
gcc.c-torture/compile/pr111059-11.c,
gcc.c-torture/compile/pr111059-12.c,
gcc.c-torture/compile/pr111911-1.c,
gcc.c-torture/compile/pr111911-2.c: New tests.

[Bug c/111059] [11/12/13/14 Regression] ICE: in gimplify_expr, at gimplify.cc:17253

2024-01-30 Thread jsm28 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111059

Joseph S. Myers  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jsm28 at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #5 from Joseph S. Myers  ---
Testing a patch.

[Bug c/111059] [11/12/13/14 Regression] ICE: in gimplify_expr, at gimplify.cc:17253

2023-08-28 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111059

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
void f() {
  (_Bool) (0 / 0);
}
ICEs too, so I think the problem is elsewhere.

[Bug c/111059] [11/12/13/14 Regression] ICE: in gimplify_expr, at gimplify.cc:17253

2023-08-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111059

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=96929

--- Comment #3 from Andrew Pinski  ---
I have a feeling this was caused by r11-5271-g4866b2f5db117f9e89f8 and the
similar handling of negative shifts need to be added to the C front-end as the
C++ front-end too.

[Bug c/111059] [11/12/13/14 Regression] ICE: in gimplify_expr, at gimplify.cc:17253

2023-08-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111059

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2023-08-18
  Known to work||10.5.0
Summary|ICE: in gimplify_expr, at   |[11/12/13/14 Regression]
   |gimplify.cc:17253   |ICE: in gimplify_expr, at
   ||gimplify.cc:17253
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Keywords||ice-on-valid-code
   Target Milestone|--- |11.5

--- Comment #2 from Andrew Pinski  ---
Confirmed. Reduced testcase:
```
void f() {
  (_Bool) (1 << -1);
}
```