Re: c-family PATCH to fix invalid shifting (PR c++/84639)

2018-03-01 Thread Jason Merrill
OK.

On Thu, Mar 1, 2018 at 9:14 AM, Marek Polacek  wrote:
> Here we were using pow2align as the right operand of <<.  But for invalid
> alignments pow2align can be -1 which makes the shifting invalid.  Fixed by
> moving the checking before using pow2align.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-03-01  Marek Polacek  
>
> PR c++/84639
> * c-attribs.c (common_handle_aligned_attribute): Don't use invalid
> alignment in computation.
>
> diff --git gcc/c-family/c-attribs.c gcc/c-family/c-attribs.c
> index 0261a45ec98..3ebb2d6000c 100644
> --- gcc/c-family/c-attribs.c
> +++ gcc/c-family/c-attribs.c
> @@ -1817,6 +1817,12 @@ common_handle_aligned_attribute (tree *node, tree 
> name, tree args, int flags,
>
>/* Log2 of specified alignment.  */
>int pow2align = check_user_alignment (align_expr, true);
> +  if (pow2align == -1
> +  || !check_cxx_fundamental_alignment_constraints (*node, pow2align, 
> flags))
> +{
> +  *no_add_attrs = true;
> +  return NULL_TREE;
> +}
>
>/* The alignment in bits corresponding to the specified alignment.  */
>unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
> @@ -1826,10 +1832,7 @@ common_handle_aligned_attribute (tree *node, tree 
> name, tree args, int flags,
>unsigned curalign = 0;
>unsigned lastalign = 0;
>
> -  if (pow2align == -1
> -  || !check_cxx_fundamental_alignment_constraints (*node, pow2align, 
> flags))
> -*no_add_attrs = true;
> -  else if (is_type)
> +  if (is_type)
>  {
>if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
> /* OK, modify the type in place.  */;
>
> Marek


c-family PATCH to fix invalid shifting (PR c++/84639)

2018-03-01 Thread Marek Polacek
Here we were using pow2align as the right operand of <<.  But for invalid
alignments pow2align can be -1 which makes the shifting invalid.  Fixed by
moving the checking before using pow2align.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-03-01  Marek Polacek  

PR c++/84639
* c-attribs.c (common_handle_aligned_attribute): Don't use invalid
alignment in computation.

diff --git gcc/c-family/c-attribs.c gcc/c-family/c-attribs.c
index 0261a45ec98..3ebb2d6000c 100644
--- gcc/c-family/c-attribs.c
+++ gcc/c-family/c-attribs.c
@@ -1817,6 +1817,12 @@ common_handle_aligned_attribute (tree *node, tree name, 
tree args, int flags,
 
   /* Log2 of specified alignment.  */
   int pow2align = check_user_alignment (align_expr, true);
+  if (pow2align == -1
+  || !check_cxx_fundamental_alignment_constraints (*node, pow2align, 
flags))
+{
+  *no_add_attrs = true;
+  return NULL_TREE;
+}
 
   /* The alignment in bits corresponding to the specified alignment.  */
   unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
@@ -1826,10 +1832,7 @@ common_handle_aligned_attribute (tree *node, tree name, 
tree args, int flags,
   unsigned curalign = 0;
   unsigned lastalign = 0;
 
-  if (pow2align == -1
-  || !check_cxx_fundamental_alignment_constraints (*node, pow2align, 
flags))
-*no_add_attrs = true;
-  else if (is_type)
+  if (is_type)
 {
   if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
/* OK, modify the type in place.  */;

Marek