]> granicus.if.org Git - clang/commitdiff
CodeGen: ensure that the runtime calling convention matches
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 13 Oct 2016 19:45:08 +0000 (19:45 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 13 Oct 2016 19:45:08 +0000 (19:45 +0000)
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`.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284154 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCRuntime.cpp
test/CodeGenObjC/runtime-abi-match.m [new file with mode: 0644]

index ebc829272e7cf1ceee8924634bb44aa5f76a2230..3da7ed230eddb03a81bc708498923db3cb1c4bd7 100644 (file)
@@ -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(CodeGenFunction &CGF,
 
     // 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());
 
diff --git a/test/CodeGenObjC/runtime-abi-match.m b/test/CodeGenObjC/runtime-abi-match.m
new file mode 100644 (file)
index 0000000..818f5ad
--- /dev/null
@@ -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);
+
+@interface NSNumber
++ (NSNumber *)numberWithInt:(int)i;
+@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
+