[PATCH] ubsan: Avoid -Wpadded warnings [PR94641]

Richard Biener rguenther@suse.de
Tue Apr 21 06:21:36 GMT 2020


On Tue, 21 Apr 2020, Jakub Jelinek wrote:

> Hi!
> 
> -Wpadded warnings aren't really useful for the artificial types that GCC
> lays out for ubsan.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

I believe most of those warnings should simply not look at
TYPE_ARTIFICIAL types.  So why the above kludge certainly
works a better fix is on the -Wpadded side IMHO.

Thanks,
Richard.

> 2020-04-20  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/94641
> 	* ubsan.c (ubsan_get_type_descriptor_type,
> 	ubsan_get_source_location_type, ubsan_create_data): Temporarily
> 	disable warn_padded for the layout_type calls.
> 
> 	* c-c++-common/ubsan/pr94641.c: New test.
> 
> --- gcc/ubsan.c.jj	2020-01-12 11:54:38.529381484 +0100
> +++ gcc/ubsan.c	2020-04-20 09:51:16.805090228 +0200
> @@ -229,7 +229,10 @@ ubsan_get_type_descriptor_type (void)
>    TYPE_FIELDS (ret) = fields[0];
>    TYPE_NAME (ret) = type_decl;
>    TYPE_STUB_DECL (ret) = type_decl;
> +  int saved_warn_padded = warn_padded;
> +  warn_padded = 0;
>    layout_type (ret);
> +  warn_padded = saved_warn_padded;
>    ubsan_type_descriptor_type = ret;
>    return ret;
>  }
> @@ -277,7 +280,10 @@ ubsan_get_source_location_type (void)
>    TYPE_FIELDS (ret) = fields[0];
>    TYPE_NAME (ret) = type_decl;
>    TYPE_STUB_DECL (ret) = type_decl;
> +  int saved_warn_padded = warn_padded;
> +  warn_padded = 0;
>    layout_type (ret);
> +  warn_padded = saved_warn_padded;
>    ubsan_source_location_type = ret;
>    return ret;
>  }
> @@ -593,7 +599,10 @@ ubsan_create_data (const char *name, int
>    TYPE_FIELDS (ret) = fields[0];
>    TYPE_NAME (ret) = type_decl;
>    TYPE_STUB_DECL (ret) = type_decl;
> +  int saved_warn_padded = warn_padded;
> +  warn_padded = 0;
>    layout_type (ret);
> +  warn_padded = saved_warn_padded;
>  
>    /* Now, fill in the type.  */
>    char tmp_name[32];
> --- gcc/testsuite/c-c++-common/ubsan/pr94641.c.jj	2020-04-20 09:54:02.036564064 +0200
> +++ gcc/testsuite/c-c++-common/ubsan/pr94641.c	2020-04-20 09:53:01.101495679 +0200
> @@ -0,0 +1,11 @@
> +/* PR c/94641 */
> +/* { dg-do compile } */
> +/* { dg-options "-fsanitize=undefined -Wpadded" } */
> +
> +void foo (void *) __attribute__((nonnull));
> +
> +void
> +bar (void *p)
> +{
> +  foo (p);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)


More information about the Gcc-patches mailing list