forked from OSchip/llvm-project
[i386 ABI] expand small C like structs in C++, just like how we handle small
C structs. This comes up when we have a function that takes a struct and is defined in a C++ file and used in a C file. Before this commit, we will generate byval for C++ and will expand the struct for C, thus causing difference at IR level. We will use bitcast of function type at the callsite, which causes the inliner to not inline the function. This commit changes how we handle small C like structs at IR level, but at backend, we should generate the same argument passing before and after the commit. Note that the condition for expanding is still over conservative. We should be able to expand type that is spelled with “class” and types that are not C-like. But this commit fixes the inconsistent argument passing between C/C++. Reviewed by John. rdar://20121030 llvm-svn: 234033
This commit is contained in:
parent
6b2a8306a5
commit
2738278b7f
|
@ -339,9 +339,15 @@ static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) {
|
|||
//
|
||||
// FIXME: This needs to be generalized to handle classes as well.
|
||||
const RecordDecl *RD = RT->getDecl();
|
||||
if (!RD->isStruct() || isa<CXXRecordDecl>(RD))
|
||||
if (!RD->isStruct())
|
||||
return false;
|
||||
|
||||
// We try to expand CLike CXXRecordDecl.
|
||||
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
||||
if (!CXXRD->isCLike())
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t Size = 0;
|
||||
|
||||
for (const auto *FD : RD->fields()) {
|
||||
|
|
|
@ -21,7 +21,7 @@ A &f4();
|
|||
void test() {
|
||||
A a;
|
||||
|
||||
// CHECK32: call i32 bitcast (i32 (%struct.A*, %struct.A*, %struct.A*, %struct.A*)* @f1 to i32 (i8*, %struct.A*, %struct.A*, %struct.A*, %struct.A*)*)(i8* nest bitcast (i32 (%struct.A*, %struct.A*, %struct.A*, %struct.A*)* @f1 to i8*)
|
||||
// CHECK32: call i32 bitcast (i32 (i32, i32, i32, i32, i32, i32, i32, i32)* @f1 to i32 (i8*, i32, i32, i32, i32, i32, i32, i32, i32)*)(i8* nest bitcast (i32 (i32, i32, i32, i32, i32, i32, i32, i32)* @f1 to i8*)
|
||||
// CHECK64: call i32 bitcast (i32 (i64, i64, i64, i64, i64, i64, %struct.A*)* @f1 to i32 (i8*, i64, i64, i64, i64, i64, i64, %struct.A*)*)(i8* nest bitcast (i32 (i64, i64, i64, i64, i64, i64, %struct.A*)* @f1 to i8*)
|
||||
__builtin_call_with_static_chain(f1(a, a, a, a), f1);
|
||||
|
||||
|
|
|
@ -101,12 +101,12 @@ Big big_return() { return Big(); }
|
|||
|
||||
|
||||
void small_arg(Small s) {}
|
||||
// LINUX-LABEL: define void @_Z9small_arg5Small(%struct.Small* byval align 4 %s)
|
||||
// LINUX-LABEL: define void @_Z9small_arg5Small(i32 %s.0)
|
||||
// WIN32: define void @"\01?small_arg@@YAXUSmall@@@Z"(%struct.Small* byval align 4 %s)
|
||||
// WIN64: define void @"\01?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
|
||||
|
||||
void medium_arg(Medium s) {}
|
||||
// LINUX-LABEL: define void @_Z10medium_arg6Medium(%struct.Medium* byval align 4 %s)
|
||||
// LINUX-LABEL: define void @_Z10medium_arg6Medium(i32 %s.0, i32 %s.1)
|
||||
// WIN32: define void @"\01?medium_arg@@YAXUMedium@@@Z"(%struct.Medium* byval align 4 %s)
|
||||
// WIN64: define void @"\01?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
|
||||
|
||||
|
@ -229,7 +229,7 @@ class Class {
|
|||
// WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(%class.Class* %this, i8 %s.coerce)
|
||||
|
||||
void thiscall_method_arg(Small s) {}
|
||||
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, %struct.Small* byval align 4 %s)
|
||||
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, i32 %s.0)
|
||||
// WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(%class.Class* %this, %struct.Small* byval align 4 %s)
|
||||
// WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(%class.Class* %this, i32 %s.coerce)
|
||||
|
||||
|
|
Loading…
Reference in New Issue