aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/RecordLayoutBuilder.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-02-02 19:36:18 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-02-02 19:36:18 +0000
commitadf082e829eb71871b6043009888df3b79055dba (patch)
tree747ab604ad6e2cca0fd6d5c5b18d08e202390cee /lib/AST/RecordLayoutBuilder.cpp
parent6159d0fe2d40708b5a3caab91c8292253894ebf3 (diff)
For gcc compatibility, size of a class which is zero
but has non-empty data fields, such as array of zero length, remains zero. // rdar://8945175 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124741 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/RecordLayoutBuilder.cpp')
-rw-r--r--lib/AST/RecordLayoutBuilder.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp
index 730ec21358..a871c3d176 100644
--- a/lib/AST/RecordLayoutBuilder.cpp
+++ b/lib/AST/RecordLayoutBuilder.cpp
@@ -1469,8 +1469,17 @@ void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
void RecordLayoutBuilder::FinishLayout(const NamedDecl *D) {
// In C++, records cannot be of size 0.
- if (Context.getLangOptions().CPlusPlus && Size == 0)
- Size = 8;
+ if (Context.getLangOptions().CPlusPlus && Size == 0) {
+ if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
+ // Compatibility with gcc requires a class (pod or non-pod)
+ // which is not empty but of size 0; such as having fields of
+ // array of zero-length, remains of Size 0
+ if (RD->isEmpty())
+ Size = 8;
+ }
+ else
+ Size = 8;
+ }
// Finally, round the size of the record up to the alignment of the
// record itself.
uint64_t UnpaddedSize = Size - UnfilledBitsInLastByte;