[PATCH] D123898: Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6
David Chisnall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 16 09:00:58 PDT 2022
theraven created this revision.
theraven added reviewers: rjmccall, triplef.
Herald added a project: All.
theraven requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
5ab6ee75994d645725264e757d67bbb1c96fb2b6 <https://reviews.llvm.org/rG5ab6ee75994d645725264e757d67bbb1c96fb2b6> assumed that if `RValue::isScalar()` returns true then `RValue::getScalarVal` will return a valid value. This is not the case when the return value is `void` and so void message returns would crash if they hit this path. This is triggered only for cases where the nil-handling path needs to do something non-trivial (destroy arguments that should be consumed by the callee).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123898
Files:
clang/lib/CodeGen/CGObjCGNU.cpp
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ 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() */ {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123898.423241.patch
Type: text/x-patch
Size: 1063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220416/71ae12d3/attachment.bin>
More information about the cfe-commits
mailing list