diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-05-11 21:15:36 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-05-11 21:15:36 +0000 |
commit | 9430d5a61598c47d827e1cd05f7cf3f110eeec9e (patch) | |
tree | 82b8e72e179b4ce140d1dd83cac5991c6c877553 /lib/CodeGen/TargetInfo.cpp | |
parent | bbbe074566a8defed299ff676bc65b3631861768 (diff) |
IRgen/i386/C++: Fix isSingleElementStruct computation for C++ record decls.
- Fixes PR7098.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103514 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/TargetInfo.cpp')
-rw-r--r-- | lib/CodeGen/TargetInfo.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index e1fdf86eb0..bcd332ac95 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -130,6 +130,30 @@ static const Type *isSingleElementStruct(QualType T, ASTContext &Context) { return 0; const Type *Found = 0; + + // If this is a C++ record, check the bases first. + if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { + for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), + e = CXXRD->bases_end(); i != e; ++i) { + const CXXRecordDecl *Base = + cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); + // Ignore empty records. + if (Base->isEmpty()) + continue; + + // If we already found an element then this isn't a single-element struct. + if (Found) + return 0; + + // If this is non-empty and not a single element struct, the composite + // cannot be a single element struct. + Found = isSingleElementStruct(i->getType(), Context); + if (!Found) + return 0; + } + } + + // Check for single element. for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i) { const FieldDecl *FD = *i; |