aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-05-11 21:15:36 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-05-11 21:15:36 +0000
commit9430d5a61598c47d827e1cd05f7cf3f110eeec9e (patch)
tree82b8e72e179b4ce140d1dd83cac5991c6c877553
parentbbbe074566a8defed299ff676bc65b3631861768 (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
-rw-r--r--lib/CodeGen/TargetInfo.cpp24
-rw-r--r--test/CodeGenCXX/x86_32-arguments.cpp34
2 files changed, 57 insertions, 1 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;
diff --git a/test/CodeGenCXX/x86_32-arguments.cpp b/test/CodeGenCXX/x86_32-arguments.cpp
index 141d3af44a..3af2746345 100644
--- a/test/CodeGenCXX/x86_32-arguments.cpp
+++ b/test/CodeGenCXX/x86_32-arguments.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
// Non-trivial dtors, should both be passed indirectly.
struct S {
@@ -13,6 +13,7 @@ void f(S) { }
// Non-trivial dtors, should both be passed indirectly.
class C {
+public:
~C();
double c;
};
@@ -51,3 +52,34 @@ struct BasicAliasAnalysis : public ModulePass, public AliasAnalysis {
void BasicAliasAnalysis::getModRefInfo(CallSite CS) {
}
+
+// Check various single element struct type conditions.
+//
+// PR7098.
+
+// CHECK: define i64 @_Z2f0v()
+struct s0_0 { int x; };
+struct s0_1 : s0_0 { int* y; };
+s0_1 f0() { return s0_1(); }
+
+// CHECK: define i32 @_Z2f1v()
+struct s1_0 { int x; };
+struct s1_1 : s1_0 { };
+s1_1 f1() { return s1_1(); }
+
+// CHECK: define double @_Z2f2v()
+struct s2_0 { double x; };
+struct s2_1 : s2_0 { };
+s2_1 f2() { return s2_1(); }
+
+// CHECK: define double @_Z2f3v()
+struct s3_0 { };
+struct s3_1 { double x; };
+struct s3_2 : s3_0, s3_1 { };
+s3_2 f3() { return s3_2(); }
+
+// CHECK: define i64 @_Z2f4v()
+struct s4_0 { float x; };
+struct s4_1 { float x; };
+struct s4_2 : s4_0, s4_1 { };
+s4_2 f4() { return s4_2(); }