r324134 - Make __has_unique_object_representations reject empty union types.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 2 12:30:39 PST 2018
Author: ericwf
Date: Fri Feb 2 12:30:39 2018
New Revision: 324134
URL: http://llvm.org/viewvc/llvm-project?rev=324134&view=rev
Log:
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
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=324134&r1=324133&r2=324134&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Feb 2 12:30:39 2018
@@ -2145,7 +2145,7 @@ static bool unionHasUniqueObjectRepresen
if (FieldSize != UnionSize)
return false;
}
- return true;
+ return !RD->field_empty();
}
static bool isStructEmpty(QualType Ty) {
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=324134&r1=324133&r2=324134&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Fri Feb 2 12:30:39 2018
@@ -2566,6 +2566,7 @@ static_assert(!has_unique_object_represe
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;
More information about the cfe-commits
mailing list