[PATCH] Don't emit -Wpadded for builtin structs

Richard Guenther richard.guenther@gmail.com
Wed Oct 14 21:25:00 GMT 2009


On Wed, Oct 14, 2009 at 10:58 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The 3 tests below started FAILing after my recent BUILTINS_LOCATION
> patch, the warnings are now reported at <built-in>:0:0.  Instead of
> adjusting the testcase, I think it is better not to warn about builtin
> structs at all.  After all, what is it good for to let the user know?
> The warning is meant to allow the user to better repack structs, but
> obviously he can't do that with builtin structs, unless gcc sources are
> changed.
>
> We then have ugly hacks like:
>  /* Give the two bytes of padding a name, so that -Wpadded won't warn on
>     every user file.  */
>  f_res = build_decl (BUILTINS_LOCATION, FIELD_DECL,
>                      get_identifier ("reserved"), short_unsigned_type_node);
> but it still doesn't cover many other cases, e.g. C++ RTTI, several
> backends, etc.
>
> I've bootstrapped/regtested this on x86_64-linux and i686-linux.

Ok.

Thanks,
Richard.

> 2009-10-14  Jakub Jelinek  <jakub@redhat.com>
>
>        * stor-layout.c (place_field): Don't emit -Wpadded warnings for
>        fields in builtin structs.
>        (finalize_record_size): Likewise.
>
>        * obj-c++.dg/layout-1.mm: Don't xfail dg-bogus on lp64, change
>        line from 1 to 0.
>        * obj-c++.dg/bitfield-1.mm: Likewise.
>        * obj-c++.dg/bitfield-4.mm: Likewise.
>
> --- gcc/stor-layout.c.jj        2009-10-05 11:49:35.000000000 +0200
> +++ gcc/stor-layout.c   2009-10-14 20:55:16.000000000 +0200
> @@ -1118,7 +1118,8 @@ place_field (record_layout_info rli, tre
>       /* No, we need to skip space before this field.
>         Bump the cumulative size to multiple of field alignment.  */
>
> -      warning (OPT_Wpadded, "padding struct to align %q+D", field);
> +      if (DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION)
> +       warning (OPT_Wpadded, "padding struct to align %q+D", field);
>
>       /* If the alignment is still within offset_align, just align
>         the bit position.  */
> @@ -1483,7 +1484,8 @@ finalize_record_size (record_layout_info
>     = round_up_loc (input_location, unpadded_size_unit, TYPE_ALIGN_UNIT (rli->t));
>
>   if (TREE_CONSTANT (unpadded_size)
> -      && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0)
> +      && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0
> +      && input_location != BUILTINS_LOCATION)
>     warning (OPT_Wpadded, "padding struct size to alignment boundary");
>
>   if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
> --- gcc/testsuite/obj-c++.dg/layout-1.mm.jj     2008-09-30 16:55:41.000000000 +0200
> +++ gcc/testsuite/obj-c++.dg/layout-1.mm        2009-10-14 22:50:42.000000000 +0200
> @@ -14,4 +14,4 @@
>  @end
>
>  /* { dg-prune-output "In output included from" }   Ignore this message.  */
> -/* { dg-bogus "padding struct to align" "PR23610" { xfail lp64 } 1 } */
> +/* { dg-bogus "padding struct to align" "PR23610" { target *-*-* } 0 } */
> --- gcc/testsuite/obj-c++.dg/bitfield-1.mm.jj   2008-12-15 11:10:36.000000000 +0100
> +++ gcc/testsuite/obj-c++.dg/bitfield-1.mm      2009-10-14 22:50:13.000000000 +0200
> @@ -115,7 +115,7 @@ int main(void)
>  }
>
>  /* { dg-prune-output "In file included from" }  Ignore this message.  */
> -/* { dg-bogus "padding struct to align" "PR23610" { xfail lp64 } 1 } */
> +/* { dg-bogus "padding struct to align" "PR23610" { target *-*-* } 0 } */
>  /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 42 } */
>  /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 45 } */
>  /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 59 } */
> --- gcc/testsuite/obj-c++.dg/bitfield-4.mm.jj   2008-09-30 16:55:41.000000000 +0200
> +++ gcc/testsuite/obj-c++.dg/bitfield-4.mm      2009-10-14 22:50:31.000000000 +0200
> @@ -50,7 +50,7 @@ int main(void)
>  }
>
>  /* { dg-prune-output "In file included from" }  Ignore this message.  */
> -/* { dg-bogus "padding struct to align" "PR23610" { xfail lp64 } 1 } */
> +/* { dg-bogus "padding struct to align" "PR23610" { target *-*-* } 0 } */
>
>  /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 28 } */
>  /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 34 } */
>
>
>        Jakub
>



More information about the Gcc-patches mailing list