public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] ubsan: Avoid -Wpadded warnings [PR94641]
@ 2020-09-17 17:22 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 17:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c4f33fe9cd322455e016787c5f726b5559844f26
commit c4f33fe9cd322455e016787c5f726b5559844f26
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Apr 21 17:06:31 2020 +0200
ubsan: Avoid -Wpadded warnings [PR94641]
-Wpadded warnings aren't really useful for the artificial types that GCC
lays out for ubsan.
2020-04-21 Jakub Jelinek <jakub@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.
(cherry picked from commit 73f8e9dca5ff891ed19001b213fd1f6ce31417e3)
Diff:
---
gcc/asan.c | 1 +
gcc/stor-layout.c | 6 ++++--
gcc/testsuite/c-c++-common/ubsan/pr94641.c | 11 +++++++++++
gcc/ubsan.c | 3 +++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/gcc/asan.c b/gcc/asan.c
index 9014df19939..220ecf64d6b 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2539,6 +2539,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;
}
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index d06e88a8135..25377232248 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -1314,7 +1314,8 @@ place_field (record_layout_info rli, tree field)
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
@@ -1748,7 +1749,8 @@ finalize_record_size (record_layout_info rli)
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
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr94641.c b/gcc/testsuite/c-c++-common/ubsan/pr94641.c
new file mode 100644
index 00000000000..b41cb06164d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr94641.c
@@ -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);
+}
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index 722f5702612..f859689a8d1 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -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 loccnt, const location_t *ploc, ...)
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. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-17 17:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 17:22 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] ubsan: Avoid -Wpadded warnings [PR94641] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).