summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-02-05 08:56:25 +0000
committerHans Wennborg <hans@hanshq.net>2018-02-05 08:56:25 +0000
commit2f7bb0ceae436c56d0e88c7a0215e6b072d86576 (patch)
treef8437ab9324e8aed42e7c98bc60a2c2748a1a32f
parent2e5d63f3a6cf01e4e484524d8827190eb1150224 (diff)
Merging r324134:
------------------------------------------------------------------------ r324134 | ericwf | 2018-02-02 21:30:39 +0100 (Fri, 02 Feb 2018) | 14 lines Make __has_unique_object_representations reject empty union types. Summary: Clang incorrectly reports empty unions as having a unique object representation. However, this is not correct since `sizeof(EmptyUnion) == 1` AKA it has 8 bits of padding. Therefore it should be treated the same as an empty struct and report `false`. @erichkeane also suggested this fix should be merged into the 6.0 release branch, so the initial release of `__has_unique_object_representations` is as bug-free as possible. Reviewers: erichkeane, rsmith, aaron.ballman, majnemer Reviewed By: erichkeane Subscribers: cfe-commits, erichkeane Differential Revision: https://reviews.llvm.org/D42863 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_60@324213 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ASTContext.cpp2
-rw-r--r--test/SemaCXX/type-traits.cpp1
2 files changed, 2 insertions, 1 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 3dc961d4f1..c73ae9efe1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2145,7 +2145,7 @@ static bool unionHasUniqueObjectRepresentations(const ASTContext &Context,
if (FieldSize != UnionSize)
return false;
}
- return true;
+ return !RD->field_empty();
}
static bool isStructEmpty(QualType Ty) {
diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp
index b334e50755..3c2f9c7f0f 100644
--- a/test/SemaCXX/type-traits.cpp
+++ b/test/SemaCXX/type-traits.cpp
@@ -2524,6 +2524,7 @@ static_assert(!has_unique_object_representations<const int &>::value, "No refere
static_assert(!has_unique_object_representations<volatile int &>::value, "No references!");
static_assert(!has_unique_object_representations<const volatile int &>::value, "No references!");
static_assert(!has_unique_object_representations<Empty>::value, "No empty types!");
+static_assert(!has_unique_object_representations<EmptyUnion>::value, "No empty types!");
class Compressed : Empty {
int x;