[PATCH] D89649: Fix __has_unique_object_representations with no_unique_address

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 18 13:47:59 PDT 2020


rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

This looks fine as far as it goes, but it doesn't fix all cases of incorrect behavior of `__has_unique_object_representations` due to `[[no_unique_address]]`. Feel free to either to land this as-is and leave the other case to a separate patch, or fix it as a revision of this same change. I would expect we'll want to unify the code paths for base classes and non-static data members, which might be better done all at once.



================
Comment at: clang/lib/AST/ASTContext.cpp:2580-2581
       if (!isStructEmpty(Base.getType())) {
         llvm::Optional<int64_t> Size = structHasUniqueObjectRepresentations(
             Context, Base.getType()->castAs<RecordType>()->getDecl());
         if (!Size)
----------------
We need to do this for non-empty `[[no_unique_address]]` members of class type too, to handle tail padding reuse in cases such as:

```
struct A {
    ~A();
    int a;
    char b;
};
struct B {
    [[no_unique_address]] A a;
    char c[3];
};
static_assert(sizeof(B) == 8, "");
static_assert(__has_unique_object_representations(B), "");
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89649/new/

https://reviews.llvm.org/D89649



More information about the cfe-commits mailing list