[cfe-commits] r143053 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/complex-double-abi.m
Fariborz Jahanian
fjahanian at apple.com
Wed Oct 26 13:53:59 PDT 2011
Author: fjahanian
Date: Wed Oct 26 15:53:59 2011
New Revision: 143053
URL: http://llvm.org/viewvc/llvm-project?rev=143053&view=rev
Log:
Objective-c: fix an ir-gen crash where objc messag returns a _Complex
value and ABI requires return slot to be passed as first
argument to message sent. // rdar://10331109
Added:
cfe/trunk/test/CodeGenObjC/complex-double-abi.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=143053&r1=143052&r2=143053&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Oct 26 15:53:59 2011
@@ -1325,13 +1325,13 @@
/// value.
struct NullReturnState {
llvm::BasicBlock *NullBB;
-
- NullReturnState() : NullBB(0) {}
+ llvm::BasicBlock *callBB;
+ NullReturnState() : NullBB(0), callBB(0) {}
void init(CodeGenFunction &CGF, llvm::Value *receiver) {
// Make blocks for the null-init and call edges.
NullBB = CGF.createBasicBlock("msgSend.nullinit");
- llvm::BasicBlock *callBB = CGF.createBasicBlock("msgSend.call");
+ callBB = CGF.createBasicBlock("msgSend.call");
// Check for a null receiver and, if there is one, jump to the
// null-init test.
@@ -1351,13 +1351,29 @@
// Emit the null-init block and perform the null-initialization there.
CGF.EmitBlock(NullBB);
- assert(result.isAggregate() && "null init of non-aggregate result?");
- CGF.EmitNullInitialization(result.getAggregateAddr(), resultType);
+ if (!resultType->isAnyComplexType()) {
+ assert(result.isAggregate() && "null init of non-aggregate result?");
+ CGF.EmitNullInitialization(result.getAggregateAddr(), resultType);
+ // Jump to the continuation block.
+ CGF.EmitBlock(contBB);
+ return result;
+ }
- // Jump to the continuation block.
+ // _Complex type
+ // FIXME. Now easy to handle any other scalar type whose result is returned
+ // in memory due to ABI limitations.
CGF.EmitBlock(contBB);
-
- return result;
+ CodeGenFunction::ComplexPairTy CallCV = result.getComplexVal();
+ llvm::Type *MemberType = CallCV.first->getType();
+ llvm::Constant *ZeroCV = llvm::Constant::getNullValue(MemberType);
+ // Create phi instruction for scalar complex value.
+ llvm::PHINode *PHIReal = CGF.Builder.CreatePHI(MemberType, 2);
+ PHIReal->addIncoming(ZeroCV, NullBB);
+ PHIReal->addIncoming(CallCV.first, callBB);
+ llvm::PHINode *PHIImag = CGF.Builder.CreatePHI(MemberType, 2);
+ PHIImag->addIncoming(ZeroCV, NullBB);
+ PHIImag->addIncoming(CallCV.second, callBB);
+ return RValue::getComplex(PHIReal, PHIImag);
}
};
Added: cfe/trunk/test/CodeGenObjC/complex-double-abi.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/complex-double-abi.m?rev=143053&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/complex-double-abi.m (added)
+++ cfe/trunk/test/CodeGenObjC/complex-double-abi.m Wed Oct 26 15:53:59 2011
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -emit-llvm -triple i386-apple-macosx10.7.2 %s -o - | FileCheck %s
+// rdar://10331109
+
+ at interface CNumber
+- (double _Complex)sum;
+ at end
+
+double _Complex foo(CNumber *x) {
+ return [x sum];
+}
+
+// CHECK: [[T4:%.*]] = phi double [ 0.000000e+00, [[NULLINIT:%.*]] ], [ [[R1:%.*]], [[MSGCALL:%.*]] ]
+// CHECK: [[T5:%.*]] = phi double [ 0.000000e+00, [[NULLINIT:%.*]] ], [ [[I1:%.*]], [[MSGCALL:%.*]] ]
+
+// CHECK: store double [[T4]]
+// CHECK: store double [[T5]]
More information about the cfe-commits
mailing list