This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix warn_if_not_align ICE (PR c/83844)


On Mon, 15 Jan 2018, Jakub Jelinek wrote:

> Hi!
> 
> As the testcase shows, handle_warn_if_not_align ICEs on
> fields with types with warn_if_not_align attribute in variable length
> structures.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2018-01-15  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/83844
> 	* stor-layout.c (handle_warn_if_not_align): Use byte_position and
> 	multiple_of_p instead of unchecked tree_to_uhwi and UHWI check.
> 
> 	* gcc.dg/pr83844.c: New test.
> 
> --- gcc/stor-layout.c.jj	2018-01-14 17:16:55.590836141 +0100
> +++ gcc/stor-layout.c	2018-01-15 10:31:42.403874423 +0100
> @@ -1150,11 +1150,9 @@ handle_warn_if_not_align (tree field, un
>      warning (opt_w, "alignment %u of %qT is less than %u",
>  	     record_align, context, warn_if_not_align);
>  
> -  unsigned HOST_WIDE_INT off
> -    = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
> -       + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)) / BITS_PER_UNIT);
> -  if ((off % warn_if_not_align) != 0)
> -    warning (opt_w, "%q+D offset %wu in %qT isn't aligned to %u",
> +  tree off = byte_position (field);
> +  if (!multiple_of_p (TREE_TYPE (off), off, size_int (warn_if_not_align)))

multiple_of_p also returns 0 if it doesn't know (for the non-constant
case obviously), so the warning should say "may be not aligned"?  Or
we don't want any false positives which means multiple_of_p should get
a worker factored out that returns a tri-state value?

> +    warning (opt_w, "%q+D offset %E in %qT isn't aligned to %u",
>  	     field, off, context, warn_if_not_align);
>  }
>  
> --- gcc/testsuite/gcc.dg/pr83844.c.jj	2018-01-15 10:36:34.986655853 +0100
> +++ gcc/testsuite/gcc.dg/pr83844.c	2018-01-15 10:36:02.120669000 +0100
> @@ -0,0 +1,28 @@
> +/* PR c/83844 */
> +/* { dg-do compile } */
> +/* { dg-options "-O0 -Wall" } */
> +
> +typedef unsigned long long __u64 __attribute__((aligned(4),warn_if_not_aligned(8)));
> +void bar (void *, void *);
> +
> +void
> +foo (int n)
> +{
> +  struct A
> +  {
> +    int i1;
> +    int i2;
> +    int i3[n];
> +    __u64 x;	/* { dg-warning "in 'struct A' isn't aligned to 8" } */
> +  } __attribute__((aligned (8)));
> +  struct B
> +  {
> +    int i1;
> +    int i2;
> +    long long i3[n];
> +    __u64 x;
> +  } __attribute__((aligned (8)));
> +  struct A a;
> +  struct B b;
> +  bar (&a, &b);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]