Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit d21d749

Browse files
committed
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`. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284154 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6ea1c6c commit d21d749

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

lib/CodeGen/CGObjCRuntime.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,16 @@ namespace {
150150
};
151151

152152
struct CallObjCEndCatch final : EHScopeStack::Cleanup {
153-
CallObjCEndCatch(bool MightThrow, llvm::Value *Fn) :
154-
MightThrow(MightThrow), Fn(Fn) {}
153+
CallObjCEndCatch(bool MightThrow, llvm::Value *Fn)
154+
: MightThrow(MightThrow), Fn(Fn) {}
155155
bool MightThrow;
156156
llvm::Value *Fn;
157157

158158
void Emit(CodeGenFunction &CGF, Flags flags) override {
159-
if (!MightThrow) {
160-
CGF.Builder.CreateCall(Fn)->setDoesNotThrow();
161-
return;
162-
}
163-
164-
CGF.EmitRuntimeCallOrInvoke(Fn);
159+
if (MightThrow)
160+
CGF.EmitRuntimeCallOrInvoke(Fn);
161+
else
162+
CGF.EmitNounwindRuntimeCall(Fn);
165163
}
166164
};
167165
}
@@ -230,10 +228,8 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
230228

231229
// Enter the catch.
232230
llvm::Value *Exn = RawExn;
233-
if (beginCatchFn) {
234-
Exn = CGF.Builder.CreateCall(beginCatchFn, RawExn, "exn.adjusted");
235-
cast<llvm::CallInst>(Exn)->setDoesNotThrow();
236-
}
231+
if (beginCatchFn)
232+
Exn = CGF.EmitNounwindRuntimeCall(beginCatchFn, RawExn, "exn.adjusted");
237233

238234
CodeGenFunction::LexicalScope cleanups(CGF, Handler.Body->getSourceRange());
239235

test/CodeGenObjC/runtime-abi-match.m

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang -target armv7-windows -fobjc-runtime=ios -O1 -fexceptions -S -emit-llvm %s -o - | FileCheck %s
2+
3+
void (*f)(id);
4+
void (*g)(void);
5+
void h(void);
6+
7+
@interface NSNumber
8+
+ (NSNumber *)numberWithInt:(int)i;
9+
@end
10+
11+
void i(void) {
12+
@try {
13+
@throw(@1);
14+
} @catch (id i) {
15+
(*f)(i);
16+
(*g)();
17+
}
18+
}
19+
20+
// CHECK: call arm_aapcs_vfpcc i8* @objc_begin_catch
21+
// CHECK: call arm_aapcs_vfpcc void @objc_end_catch
22+
// CHECK-NOT: call i8* @objc_begin_catch
23+
// CHECK-NOT: call void @objc_end_catch
24+

0 commit comments

Comments
 (0)