[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

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

--- Comment #7 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/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

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

Joseph S. Myers  changed:

   What|Removed |Added

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

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

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-11-22 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

Jakub Jelinek  changed:

   What|Removed |Added

   Keywords|needs-bisection |
 CC||jakub at gcc dot gnu.org,
   ||jsm28 at gcc dot gnu.org
   Priority|P3  |P2

--- Comment #5 from Jakub Jelinek  ---
Started with r10-5922-g3d77686d2eddf76d3498169d0ca5653db45a8662

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-10-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

--- Comment #4 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #3)
> I suspect it started with PR 93241 (and is very similar to PR 93348).

(_Bool) <<< Unknown tree: c_maybe_const_expr

  1 >>> == 0)


So maybe remove_c_maybe_const_expr needs to be called always instead of just on
"argument with integer operands".

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-10-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||needs-bisection
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=93348,
   ||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=93241

--- Comment #3 from Andrew Pinski  ---
I suspect it started with PR 93241 (and is very similar to PR 93348).

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-10-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

--- Comment #2 from Andrew Pinski  ---
A c_maybe_const_expr is there still for this.

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-10-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2023-10-22
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
.

[Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool

2023-10-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111911

Andrew Pinski  changed:

   What|Removed |Added

  Known to fail||10.1.0, 11.1.0, 8.4.0,
   ||9.3.0, 9.4.0
   Target Milestone|--- |11.5
   Keywords||ice-on-valid-code
  Known to work||7.1.0, 8.3.0, 9.1.0, 9.2.0
Summary|GCC: 14: internal compiler  |[11/12/13/14 Regression]
   |error: internal compiler|ICE with integer overflow
   |error: in gimplify_expr, at |converting to _Bool
   |gimplify.cc:17510   |