Skip to content

Commit

Permalink
Merging r324134:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
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
------------------------------------------------------------------------

llvm-svn: 324213
  • Loading branch information
zmodem committed Feb 5, 2018
1 parent 3980c8d commit e71868f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTContext.cpp
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions clang/test/SemaCXX/type-traits.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit e71868f

Please sign in to comment.