зеркало из https://github.com/microsoft/clang-1.git
Fix an Obj-C++ miscompile when calling an Obj-C method that returns a C++ reference.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106477 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
9a14084543
Коммит
7e70fb217d
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
|
||||
|
||||
struct A { ~A(); };
|
||||
|
||||
@interface B {
|
||||
A a;
|
||||
}
|
||||
|
||||
- (const A&)getA;
|
||||
@end
|
||||
|
||||
@implementation B
|
||||
|
||||
- (const A&)getA {
|
||||
return a;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// CHECK: define void @_Z1fP1B
|
||||
// CHECK: objc_msgSend to
|
||||
// CHECK: ret void
|
||||
void f(B* b) {
|
||||
(void)[b getA];
|
||||
}
|
Загрузка…
Ссылка в новой задаче