diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-12-01 10:56:52 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-12-01 10:56:52 +0100 |
commit | b1fe98dee21773b9d908469effe2580567b903fb (patch) | |
tree | 17b23e82291d4f52830078f713bd33c95de5d1b1 /gcc | |
parent | 9bfebcb1b7ae4e7160644f2104424d6bab4a23f7 (diff) | |
download | gcc-b1fe98dee21773b9d908469effe2580567b903fb.zip gcc-b1fe98dee21773b9d908469effe2580567b903fb.tar.gz gcc-b1fe98dee21773b9d908469effe2580567b903fb.tar.bz2 |
lower-bitint: Fix lowering of middle sized _BitInt operations which can throw [PR112770]
The middle kind _BitInt lowering is mostly done by casting the BITINT_TYPE
operands (if any) to a signed/unsigned integer type which has larger/equal
precision, using such integer type also for the lhs (if BITINT_TYPE) and
and adding a cast after the statement from that new lhs to the old
(BITINT_TYPE) lhs. Note, for middle kind this isn't done for GIMPLE_CALLs.
Most of the time that works nicely, the exception as the following testcase
shows is -fnon-call-exceptions and some operations which can trap. Because
inserting the cast to a new lhs after the statement results in a trapping
statement in the middle of a basic block.
The following patch fixes that by emitting the cast on the fallthru edge
instead.
2023-12-01 Jakub Jelinek <jakub@redhat.com>
PR middle-end/112770
* gimple-lower-bitint.cc (gimple_lower_bitint): When adjusting
lhs of middle _BitInt setter which ends bb, insert cast on
the fallthru edge rather than after stmt.
* gcc.dg/bitint-45.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/gimple-lower-bitint.cc | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/bitint-45.c | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index d0e24cb..6de869f 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -6336,7 +6336,13 @@ gimple_lower_bitint (void) type = build_nonstandard_integer_type (prec, uns); tree lhs2 = make_ssa_name (type); gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); - gsi_insert_after (&gsi, g, GSI_SAME_STMT); + if (stmt_ends_bb_p (stmt)) + { + edge e = find_fallthru_edge (gsi_bb (gsi)->succs); + gsi_insert_on_edge_immediate (e, g); + } + else + gsi_insert_after (&gsi, g, GSI_SAME_STMT); gimple_set_lhs (stmt, lhs2); } unsigned int nops = gimple_num_ops (stmt); diff --git a/gcc/testsuite/gcc.dg/bitint-45.c b/gcc/testsuite/gcc.dg/bitint-45.c new file mode 100644 index 0000000..4dfb92d --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-45.c @@ -0,0 +1,11 @@ +/* PR middle-end/112770 */ +/* { dg-do compile { target bitint128 } } */ +/* { dg-options "-std=c23 -fnon-call-exceptions" } */ + +void +foo (void) +{ + _BitInt(128) a = 0; + a /= 0; /* { dg-warning "division by zero" } */ + &a; +} |