summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2016-10-13 19:45:08 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2016-10-13 19:45:08 +0000
commit887a82c5d633548c97d3e5f5b586bb88f5bb8943 (patch)
tree25d6c1d847016d71cd3326079ec06267f63b0292
parent52ffa6711b967770f08ebb606a649c3afb9f5e66 (diff)
downloadbcm5719-llvm-887a82c5d633548c97d3e5f5b586bb88f5bb8943.tar.gz
bcm5719-llvm-887a82c5d633548c97d3e5f5b586bb88f5bb8943.zip
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`. llvm-svn: 284154
-rw-r--r--clang/lib/CodeGen/CGObjCRuntime.cpp20
-rw-r--r--clang/test/CodeGenObjC/runtime-abi-match.m24
2 files changed, 32 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CGObjCRuntime.cpp b/clang/lib/CodeGen/CGObjCRuntime.cpp
index ebc829272e7..3da7ed230ed 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.cpp
+++ b/clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -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/clang/test/CodeGenObjC/runtime-abi-match.m b/clang/test/CodeGenObjC/runtime-abi-match.m
new file mode 100644
index 00000000000..818f5ad53ee
--- /dev/null
+++ b/clang/test/CodeGenObjC/runtime-abi-match.m
@@ -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
+
OpenPOWER on IntegriCloud