summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGObjC.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2019-01-02 17:25:30 +0000
committerPete Cooper <peter_cooper@apple.com>2019-01-02 17:25:30 +0000
commitde0a8d37a017d39a0a6cfa99ea71a47bf6bb0cc4 (patch)
treef84a4bce7f4eb2d9fbedfaabf0dfbdffa357b2cc /clang/lib/CodeGen/CGObjC.cpp
parentecc89b76cb8f3a9732bebb1a094b840bdb4c2302 (diff)
downloadbcm5719-llvm-de0a8d37a017d39a0a6cfa99ea71a47bf6bb0cc4.tar.gz
bcm5719-llvm-de0a8d37a017d39a0a6cfa99ea71a47bf6bb0cc4.zip
Only convert objc messages to alloc to objc_alloc if the receiver is a class.
r348687 converted [Foo alloc] to objc_alloc(Foo). However the objc runtime method only takes a Class, not an arbitrary pointer. This makes sure we are messaging a class before we convert these messages. rdar://problem/46943703 llvm-svn: 350224
Diffstat (limited to 'clang/lib/CodeGen/CGObjC.cpp')
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 8d24b15f76a..9c66ff0e8fb 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -370,7 +370,8 @@ static Optional<llvm::Value *>
tryGenerateSpecializedMessageSend(CodeGenFunction &CGF, QualType ResultType,
llvm::Value *Receiver,
const CallArgList& Args, Selector Sel,
- const ObjCMethodDecl *method) {
+ const ObjCMethodDecl *method,
+ bool isClassMessage) {
auto &CGM = CGF.CGM;
if (!CGM.getCodeGenOpts().ObjCConvertMessagesToRuntimeCalls)
return None;
@@ -378,7 +379,8 @@ tryGenerateSpecializedMessageSend(CodeGenFunction &CGF, QualType ResultType,
auto &Runtime = CGM.getLangOpts().ObjCRuntime;
switch (Sel.getMethodFamily()) {
case OMF_alloc:
- if (Runtime.shouldUseRuntimeFunctionsForAlloc() &&
+ if (isClassMessage &&
+ Runtime.shouldUseRuntimeFunctionsForAlloc() &&
ResultType->isObjCObjectPointerType()) {
// [Foo alloc] -> objc_alloc(Foo)
if (Sel.isUnarySelector() && Sel.getNameForSlot(0) == "alloc")
@@ -550,7 +552,8 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E,
// Call runtime methods directly if we can.
if (Optional<llvm::Value *> SpecializedResult =
tryGenerateSpecializedMessageSend(*this, ResultType, Receiver, Args,
- E->getSelector(), method)) {
+ E->getSelector(), method,
+ isClassMessage)) {
result = RValue::get(SpecializedResult.getValue());
} else {
result = Runtime.GenerateMessageSend(*this, Return, ResultType,
OpenPOWER on IntegriCloud