* [PATCH] fold-const: Fix up fold_truth_andor_1 shift handling [PR103813]
@ 2021-12-28 10:27 Jakub Jelinek
2021-12-28 15:21 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-12-28 10:27 UTC (permalink / raw)
To: Richard Biener, Jeff Law; +Cc: gcc-patches
Hi!
Some time ago I've changed const_binop -> wide_int_binop, so that it punts
on shifts by negative count. fold_truth_andor_1 doesn't check the results
of const_binop (?SHIFT_EXPR, ) though and assumes they will be always
non-NULL, which is no longer the case.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
for trunk?
2021-12-28 Jakub Jelinek <jakub@redhat.com>
PR middle-end/103813
* fold-const.c (fold_truth_andor_1): Punt of const_binop LSHIFT_EXPR
or RSHIFT_EXPR returns NULL. Formatting fix.
* gcc.c-torture/compile/pr103813.c: New test.
--- gcc/fold-const.c.jj 2021-12-02 19:41:52.606553108 +0100
+++ gcc/fold-const.c 2021-12-27 17:43:38.315971936 +0100
@@ -6454,15 +6454,19 @@ fold_truth_andor_1 (location_t loc, enum
size_int (xll_bitpos));
rl_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, rl_mask),
size_int (xrl_bitpos));
+ if (ll_mask == NULL_TREE || rl_mask == NULL_TREE)
+ return 0;
if (l_const)
{
l_const = fold_convert_loc (loc, lntype, l_const);
l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos));
+ if (l_const == NULL_TREE)
+ return 0;
if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
fold_build1_loc (loc, BIT_NOT_EXPR,
- lntype, ll_mask))))
+ lntype, ll_mask))))
{
warning (0, "comparison is always %d", wanted_code == NE_EXPR);
@@ -6474,9 +6478,11 @@ fold_truth_andor_1 (location_t loc, enum
r_const = fold_convert_loc (loc, lntype, r_const);
r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos));
+ if (r_const == NULL_TREE)
+ return 0;
if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
fold_build1_loc (loc, BIT_NOT_EXPR,
- lntype, rl_mask))))
+ lntype, rl_mask))))
{
warning (0, "comparison is always %d", wanted_code == NE_EXPR);
@@ -6521,6 +6527,8 @@ fold_truth_andor_1 (location_t loc, enum
rr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc,
rntype, rr_mask),
size_int (xrr_bitpos));
+ if (lr_mask == NULL_TREE || rr_mask == NULL_TREE)
+ return 0;
/* Make a mask that corresponds to both fields being compared.
Do this for both items being compared. If the operands are the
@@ -6580,6 +6588,8 @@ fold_truth_andor_1 (location_t loc, enum
size_int (MIN (xll_bitpos, xrl_bitpos)));
lr_mask = const_binop (RSHIFT_EXPR, lr_mask,
size_int (MIN (xlr_bitpos, xrr_bitpos)));
+ if (ll_mask == NULL_TREE || lr_mask == NULL_TREE)
+ return 0;
/* Convert to the smaller type before masking out unwanted bits. */
type = lntype;
--- gcc/testsuite/gcc.c-torture/compile/pr103813.c.jj 2021-12-27 17:45:28.737380460 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr103813.c 2021-12-27 17:44:45.388005245 +0100
@@ -0,0 +1,10 @@
+/* PR middle-end/103813 */
+
+struct A { char b; char c[0x21000000]; };
+struct A d;
+
+int
+foo ()
+{
+ return d.c[0x20000000] || d.c[1];
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fold-const: Fix up fold_truth_andor_1 shift handling [PR103813]
2021-12-28 10:27 [PATCH] fold-const: Fix up fold_truth_andor_1 shift handling [PR103813] Jakub Jelinek
@ 2021-12-28 15:21 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-12-28 15:21 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches
On 12/28/2021 3:27 AM, Jakub Jelinek wrote:
> Hi!
>
> Some time ago I've changed const_binop -> wide_int_binop, so that it punts
> on shifts by negative count. fold_truth_andor_1 doesn't check the results
> of const_binop (?SHIFT_EXPR, ) though and assumes they will be always
> non-NULL, which is no longer the case.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
> for trunk?
>
> 2021-12-28 Jakub Jelinek <jakub@redhat.com>
>
> PR middle-end/103813
> * fold-const.c (fold_truth_andor_1): Punt of const_binop LSHIFT_EXPR
> or RSHIFT_EXPR returns NULL. Formatting fix.
>
> * gcc.c-torture/compile/pr103813.c: New test.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-28 15:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 10:27 [PATCH] fold-const: Fix up fold_truth_andor_1 shift handling [PR103813] Jakub Jelinek
2021-12-28 15:21 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).