rsmith added inline comments.

================
Comment at: lib/AST/ASTContext.cpp:2200
+          Layout.getBaseClassOffset(Base->getAsCXXRecordDecl());
+      CharUnits BaseSize = Context.getTypeSizeInChars(Base);
+      if (BaseOffset != CurOffset)
----------------
On reflection, I don't think this is right, and likewise I don't think the 
check for unique object representations of the base class above is quite right.

A class can be standard-layout but not POD for the purposes of layout (eg, by 
declaring a special member function). If so, the derived class can reuse the 
base class's tail padding, and if it does, the derived class can have unique 
object representations even when the base class does not. Example:

```
struct A { ~A(); int n; char a; }; struct B : A { char b, c, d; };
```

Here, under the Itanium C++ ABI, `sizeof(B) == 8`, and `B` has unique object 
representations even though its base class `A` does not.


This should be fairly easy to fix. One approach would be to change the 
recursive call to `hasUniqueObjectRepresentations` above to return the actual 
size occupied by the struct and its fields (rather than checking for tail 
padding), and add that size here instead of using the base size. Or you could 
query the DataSize in the record layout rather than getting the (complete 
object) type size (but you'd then still need to check that there's no bits of 
tail padding before the end of the dsize, since we still pad out trailing 
bit-fields in the dsize computation).


================
Comment at: lib/AST/ASTContext.cpp:2231
+
+  // Handles tail-padding.  >= comparision takes care of EBO cases.
+  return CurOffsetInBits == Context.toBits(Layout.getSize());
----------------
What `>=` comparison? I think the comment has got out of date relative to the 
code.


https://reviews.llvm.org/D39347



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to