diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -2837,11 +2837,13 @@ // Enter the continuation block and emit a phi if required. CGF.EmitBlock(continueBB); if (msgRet.isScalar()) { - llvm::Value *v = msgRet.getScalarVal(); - llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2); - phi->addIncoming(v, nonNilPathBB); - phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB); - msgRet = RValue::get(phi); + // If the return type is void, do nothing + if (llvm::Value *v = msgRet.getScalarVal()) { + llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2); + phi->addIncoming(v, nonNilPathBB); + phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB); + msgRet = RValue::get(phi); + } } else if (msgRet.isAggregate()) { // Aggregate zeroing is handled in nilCleanupBB when it's required. } else /* isComplex() */ { diff --git a/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm b/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple x86_64-unknow-windows-msvc -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s + +// Regression test. Ensure that C++ arguments with non-trivial destructors +// don't crash the compiler. + +struct X +{ + int a; + ~X(); +}; + +@protocol Y +- (void)foo: (X)bar; +@end + + +void test(id obj) +{ + X a{12}; + [obj foo: a]; +} +