diff options
author | Anders Carlsson <andersca@mac.com> | 2010-06-21 20:59:55 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-06-21 20:59:55 +0000 |
commit | 280e61f148d66ba5a5352e7d9dfa70ce64f1fa29 (patch) | |
tree | f128049933f12378052dc7efe7ada6ee8499b3a1 /clang/lib | |
parent | c62ab8d064f6c6a8553ffe4571c9da7e9ecbc337 (diff) | |
download | bcm5719-llvm-280e61f148d66ba5a5352e7d9dfa70ce64f1fa29.tar.gz bcm5719-llvm-280e61f148d66ba5a5352e7d9dfa70ce64f1fa29.zip |
Fix an Obj-C++ miscompile when calling an Obj-C method that returns a C++ reference.
llvm-svn: 106477
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 13 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjC.cpp | 7 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 5 |
3 files changed, 20 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 8655a66bd95..cfb5af724bf 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1981,10 +1981,17 @@ CodeGenFunction::EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E) { } LValue CodeGenFunction::EmitObjCMessageExprLValue(const ObjCMessageExpr *E) { - // Can only get l-value for message expression returning aggregate type RValue RV = EmitObjCMessageExpr(E); - // FIXME: can this be volatile? - return LValue::MakeAddr(RV.getAggregateAddr(), MakeQualifiers(E->getType())); + + if (!RV.isScalar()) + return LValue::MakeAddr(RV.getAggregateAddr(), + MakeQualifiers(E->getType())); + + assert(E->getMethodDecl()->getResultType()->isReferenceType() && + "Can't have a scalar return unless the return type is a " + "reference type!"); + + return LValue::MakeAddr(RV.getScalarVal(), MakeQualifiers(E->getType())); } LValue CodeGenFunction::EmitObjCSelectorLValue(const ObjCSelectorExpr *E) { diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 95be0dd1204..30f7ab55ce9 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -90,11 +90,14 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, CallArgList Args; EmitCallArgs(Args, E->getMethodDecl(), E->arg_begin(), E->arg_end()); + QualType ResultType = + E->getMethodDecl() ? E->getMethodDecl()->getResultType() : E->getType(); + if (isSuperMessage) { // super is only valid in an Objective-C method const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl); bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext()); - return Runtime.GenerateMessageSendSuper(*this, Return, E->getType(), + return Runtime.GenerateMessageSendSuper(*this, Return, ResultType, E->getSelector(), OMD->getClassInterface(), isCategoryImpl, @@ -104,7 +107,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, E->getMethodDecl()); } - return Runtime.GenerateMessageSend(*this, Return, E->getType(), + return Runtime.GenerateMessageSend(*this, Return, ResultType, E->getSelector(), Receiver, Args, OID, E->getMethodDecl()); diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 8374aa8c555..cd27dcef011 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1634,6 +1634,11 @@ CGObjCCommonMac::EmitLegacyMessageSend(CodeGen::CodeGenFunction &CGF, const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false); + if (Method) + assert(CGM.getContext().getCanonicalType(Method->getResultType()) == + CGM.getContext().getCanonicalType(ResultType) && + "Result type mismatch!"); + llvm::Constant *Fn = NULL; if (CGM.ReturnTypeUsesSret(FnInfo)) { Fn = (ObjCABI == 2) ? ObjCTypes.getSendStretFn2(IsSuper) |