diff mbox

Fix condition in is_aligning_offset (PR c/61271)

Message ID 20140821155210.GT14320@redhat.com
State New
Headers show

Commit Message

Marek Polacek Aug. 21, 2014, 3:52 p.m. UTC
This is one of the issues that -Wlogical-not-parentheses detected.
Interestingly, this code has been added in 2002 (!).  I believe the
logical not there should be just removed; the comment above it says
  /* We must now have a BIT_AND_EXPR with a constant that is one less than
     power of 2 and which is larger than BIGGEST_ALIGNMENT.  */
so if the constant is not one less than power of 2 (exact_log2 returns -1),
we should bail out.

Bootstrapped/regtested on x86_64-linux, ok for trunk?
Should I backport this to 4.9/4.8 after a while?

2014-08-21  Marek Polacek  <polacek@redhat.com>

	PR c/61271
	* expr.c (is_aligning_offset): Remove logical not.


	Marek

Comments

Richard Biener Aug. 26, 2014, 8:04 a.m. UTC | #1
On Thu, Aug 21, 2014 at 5:52 PM, Marek Polacek <polacek@redhat.com> wrote:
> This is one of the issues that -Wlogical-not-parentheses detected.
> Interestingly, this code has been added in 2002 (!).  I believe the
> logical not there should be just removed; the comment above it says
>   /* We must now have a BIT_AND_EXPR with a constant that is one less than
>      power of 2 and which is larger than BIGGEST_ALIGNMENT.  */
> so if the constant is not one less than power of 2 (exact_log2 returns -1),
> we should bail out.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Ok.

> Should I backport this to 4.9/4.8 after a while?

Yes please.

Thanks,
Richard.

> 2014-08-21  Marek Polacek  <polacek@redhat.com>
>
>         PR c/61271
>         * expr.c (is_aligning_offset): Remove logical not.
>
> diff --git gcc/expr.c gcc/expr.c
> index 920d47b..05d81dc 100644
> --- gcc/expr.c
> +++ gcc/expr.c
> @@ -10721,7 +10721,7 @@ is_aligning_offset (const_tree offset, const_tree exp)
>        || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
>        || compare_tree_int (TREE_OPERAND (offset, 1),
>                            BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
> -      || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
> +      || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
>      return 0;
>
>    /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
>
>         Marek
Marek Polacek Sept. 1, 2014, 2:20 p.m. UTC | #2
On Tue, Aug 26, 2014 at 10:04:36AM +0200, Richard Biener wrote:
> > Should I backport this to 4.9/4.8 after a while?
> 
> Yes please.

Done.

	Marek
diff mbox

Patch

diff --git gcc/expr.c gcc/expr.c
index 920d47b..05d81dc 100644
--- gcc/expr.c
+++ gcc/expr.c
@@ -10721,7 +10721,7 @@  is_aligning_offset (const_tree offset, const_tree exp)
       || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
       || compare_tree_int (TREE_OPERAND (offset, 1),
 			   BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
-      || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
+      || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
     return 0;
 
   /* Look at the first operand of BIT_AND_EXPR and strip any conversion.