Hi! On Tue, Apr 21, 2020 at 08:21:36AM +0200, Richard Biener wrote: > 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.
So like this if it passes bootstrap/regtest? 2020-04-21 Jakub Jelinek <ja...@redhat.com> PR c/94641 * stor-layout.c (place_field, finalize_record_size): Don't emit -Wpadded warning on TYPE_ARTIFICIAL rli->t. * ubsan.c (ubsan_get_type_descriptor_type, ubsan_get_source_location_type, ubsan_create_data): Set TYPE_ARTIFICIAL. * asan.c (asan_global_struct): Likewise. * c-c++-common/ubsan/pr94641.c: New test. --- gcc/stor-layout.c.jj 2020-01-12 11:54:36.935405533 +0100 +++ gcc/stor-layout.c 2020-04-21 09:34:27.743871177 +0200 @@ -1341,7 +1341,8 @@ place_field (record_layout_info rli, tre Bump the cumulative size to multiple of field alignment. */ if (!targetm.ms_bitfield_layout_p (rli->t) - && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION) + && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION + && !TYPE_ARTIFICIAL (rli->t)) warning (OPT_Wpadded, "padding struct to align %q+D", field); /* If the alignment is still within offset_align, just align @@ -1775,7 +1776,8 @@ finalize_record_size (record_layout_info if (TREE_CONSTANT (unpadded_size) && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0 - && input_location != BUILTINS_LOCATION) + && input_location != BUILTINS_LOCATION + && !TYPE_ARTIFICIAL (rli->t)) warning (OPT_Wpadded, "padding struct size to alignment boundary"); if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE --- gcc/ubsan.c.jj 2020-04-20 11:46:07.892145312 +0200 +++ gcc/ubsan.c 2020-04-21 09:25:46.494055822 +0200 @@ -229,6 +229,7 @@ ubsan_get_type_descriptor_type (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); ubsan_type_descriptor_type = ret; return ret; @@ -277,6 +278,7 @@ ubsan_get_source_location_type (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); ubsan_source_location_type = ret; return ret; @@ -593,6 +595,7 @@ ubsan_create_data (const char *name, int TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); /* Now, fill in the type. */ --- gcc/asan.c.jj 2020-03-18 13:36:22.004021340 +0100 +++ gcc/asan.c 2020-04-21 09:28:00.692968875 +0200 @@ -2661,6 +2661,7 @@ asan_global_struct (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); return ret; } --- gcc/testsuite/c-c++-common/ubsan/pr94641.c.jj 2020-04-21 09:24:36.694141289 +0200 +++ gcc/testsuite/c-c++-common/ubsan/pr94641.c 2020-04-21 09:24:36.694141289 +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