aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/abi
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-09-05 17:36:28 -0400
committerJason Merrill <jason@redhat.com>2023-09-05 23:19:38 -0400
commitdbae784d50f499671fd2fde54a8d8d3421cba32b (patch)
treebea7d04fb1481058ac18e58252274916b24856f3 /gcc/testsuite/g++.dg/abi
parent254100a9a003a16255a58eec3fa24168e6dc7124 (diff)
downloadgcc-dbae784d50f499671fd2fde54a8d8d3421cba32b.zip
gcc-dbae784d50f499671fd2fde54a8d8d3421cba32b.tar.gz
gcc-dbae784d50f499671fd2fde54a8d8d3421cba32b.tar.bz2
c++: [[no_unique_address]] and cv-qualified type
We were checking for overlap using same_type_p and therefore allocating two Empty subobjects at the same offset because one was cv-qualified. This gives the warning at the location of the class name rather than the member declaration, but this should be a rare enough issue that it doesn't seem worth trying to be more precise. gcc/ChangeLog: * common.opt: Update -fabi-version=19. gcc/cp/ChangeLog: * class.cc (check_subobject_offset): Check same_type_ignoring_top_level_qualifiers_p. gcc/testsuite/ChangeLog: * g++.dg/abi/no_unique_address8.C: New test. * g++.dg/abi/no_unique_address8a.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/abi')
-rw-r--r--gcc/testsuite/g++.dg/abi/no_unique_address8.C30
-rw-r--r--gcc/testsuite/g++.dg/abi/no_unique_address8a.C31
2 files changed, 61 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/abi/no_unique_address8.C b/gcc/testsuite/g++.dg/abi/no_unique_address8.C
new file mode 100644
index 0000000..6aa2bba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/no_unique_address8.C
@@ -0,0 +1,30 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-fabi-version=19 -Wabi=18" }
+
+#include <cstddef>
+
+#define NOUNIQUE [[no_unique_address]]
+
+struct Empty { };
+#define CHECK_DISTINCT(type, field1, field2) static_assert(offsetof(type, field1) != offsetof(type, field2))
+
+struct A1 {
+ NOUNIQUE Empty a;
+ Empty b;
+};
+CHECK_DISTINCT(A1, a, b);
+struct A2 {
+ NOUNIQUE const Empty a;
+ const Empty b;
+};
+CHECK_DISTINCT(A2, a, b);
+struct A3 { // { dg-warning "layout" }
+ NOUNIQUE const Empty a;
+ Empty b;
+};
+CHECK_DISTINCT(A3, a, b);
+struct A4 { // { dg-warning "layout" }
+ NOUNIQUE Empty a;
+ const Empty b;
+};
+CHECK_DISTINCT(A4, a, b);
diff --git a/gcc/testsuite/g++.dg/abi/no_unique_address8a.C b/gcc/testsuite/g++.dg/abi/no_unique_address8a.C
new file mode 100644
index 0000000..c5d4808
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/no_unique_address8a.C
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-fabi-version=18 -Wabi=19" }
+
+#include <cstddef>
+
+#define NOUNIQUE [[no_unique_address]]
+
+struct Empty { };
+#define CHECK_DISTINCT(type, field1, field2) static_assert(offsetof(type, field1) != offsetof(type, field2))
+#define CHECK_SAME(type, field1, field2) static_assert(offsetof(type, field1) == offsetof(type, field2))
+
+struct A1 {
+ NOUNIQUE Empty a;
+ Empty b;
+};
+CHECK_DISTINCT(A1, a, b);
+struct A2 {
+ NOUNIQUE const Empty a;
+ const Empty b;
+};
+CHECK_DISTINCT(A2, a, b);
+struct A3 { // { dg-warning "layout" }
+ NOUNIQUE const Empty a;
+ Empty b;
+};
+CHECK_SAME(A3, a, b);
+struct A4 { // { dg-warning "layout" }
+ NOUNIQUE Empty a;
+ const Empty b;
+};
+CHECK_SAME(A4, a, b);