[PATCH] D123898: Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6

David Chisnall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 24 06:02:12 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94c3b169785c: Fix crash in ObjC codegen introduced with… (authored by theraven).

Changed prior to commit:
  https://reviews.llvm.org/D123898?vs=423241&id=447127#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123898/new/

https://reviews.llvm.org/D123898

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm


Index: clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm
===================================================================
--- /dev/null
+++ 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();
+};
+
+ at protocol Y
+- (void)foo: (X)bar;
+ at end
+
+
+void test(id<Y> obj)
+{
+  X a{12};
+  [obj foo: a];
+}
+
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.447127.patch
Type: text/x-patch
Size: 1663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220724/93b7148a/attachment.bin>


More information about the cfe-commits mailing list