r284154 - CodeGen: ensure that the runtime calling convention matches

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 13 12:45:08 PDT 2016


Author: compnerd
Date: Thu Oct 13 14:45:08 2016
New Revision: 284154

URL: http://llvm.org/viewvc/llvm-project?rev=284154&view=rev
Log:
CodeGen: ensure that the runtime calling convention matches

Incorrect specification of the calling convention results in UB which can cause
the code path to be eliminated.  Simplify the existing code by using the
RuntimeCall constructor in `CodeGenFunction`.

Added:
    cfe/trunk/test/CodeGenObjC/runtime-abi-match.m
Modified:
    cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp?rev=284154&r1=284153&r2=284154&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp Thu Oct 13 14:45:08 2016
@@ -150,18 +150,16 @@ namespace {
   };
 
   struct CallObjCEndCatch final : EHScopeStack::Cleanup {
-    CallObjCEndCatch(bool MightThrow, llvm::Value *Fn) :
-      MightThrow(MightThrow), Fn(Fn) {}
+    CallObjCEndCatch(bool MightThrow, llvm::Value *Fn)
+        : MightThrow(MightThrow), Fn(Fn) {}
     bool MightThrow;
     llvm::Value *Fn;
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      if (!MightThrow) {
-        CGF.Builder.CreateCall(Fn)->setDoesNotThrow();
-        return;
-      }
-
-      CGF.EmitRuntimeCallOrInvoke(Fn);
+      if (MightThrow)
+        CGF.EmitRuntimeCallOrInvoke(Fn);
+      else
+        CGF.EmitNounwindRuntimeCall(Fn);
     }
   };
 }
@@ -230,10 +228,8 @@ void CGObjCRuntime::EmitTryCatchStmt(Cod
 
     // Enter the catch.
     llvm::Value *Exn = RawExn;
-    if (beginCatchFn) {
-      Exn = CGF.Builder.CreateCall(beginCatchFn, RawExn, "exn.adjusted");
-      cast<llvm::CallInst>(Exn)->setDoesNotThrow();
-    }
+    if (beginCatchFn)
+      Exn = CGF.EmitNounwindRuntimeCall(beginCatchFn, RawExn, "exn.adjusted");
 
     CodeGenFunction::LexicalScope cleanups(CGF, Handler.Body->getSourceRange());
 

Added: cfe/trunk/test/CodeGenObjC/runtime-abi-match.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/runtime-abi-match.m?rev=284154&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/runtime-abi-match.m (added)
+++ cfe/trunk/test/CodeGenObjC/runtime-abi-match.m Thu Oct 13 14:45:08 2016
@@ -0,0 +1,24 @@
+// RUN: %clang -target armv7-windows -fobjc-runtime=ios -O1 -fexceptions -S -emit-llvm %s -o - | FileCheck %s
+
+void (*f)(id);
+void (*g)(void);
+void h(void);
+
+ at interface NSNumber
++ (NSNumber *)numberWithInt:(int)i;
+ at end
+
+void i(void) {
+  @try {
+    @throw(@1);
+  } @catch (id i) {
+    (*f)(i);
+    (*g)();
+  }
+}
+
+// CHECK: call arm_aapcs_vfpcc i8* @objc_begin_catch
+// CHECK: call arm_aapcs_vfpcc void @objc_end_catch
+// CHECK-NOT: call i8* @objc_begin_catch
+// CHECK-NOT: call void @objc_end_catch
+




More information about the cfe-commits mailing list