[cfe-commits] r106477 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGObjC.cpp lib/CodeGen/CGObjCMac.cpp test/CodeGenObjCXX/references.mm
Anders Carlsson
andersca at mac.com
Mon Jun 21 13:59:55 PDT 2010
Author: andersca
Date: Mon Jun 21 15:59:55 2010
New Revision: 106477
URL: http://llvm.org/viewvc/llvm-project?rev=106477&view=rev
Log:
Fix an Obj-C++ miscompile when calling an Obj-C method that returns a C++ reference.
Added:
cfe/trunk/test/CodeGenObjCXX/references.mm
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=106477&r1=106476&r2=106477&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jun 21 15:59:55 2010
@@ -1981,10 +1981,17 @@
}
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) {
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=106477&r1=106476&r2=106477&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Mon Jun 21 15:59:55 2010
@@ -90,11 +90,14 @@
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 @@
E->getMethodDecl());
}
- return Runtime.GenerateMessageSend(*this, Return, E->getType(),
+ return Runtime.GenerateMessageSend(*this, Return, ResultType,
E->getSelector(),
Receiver, Args, OID,
E->getMethodDecl());
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=106477&r1=106476&r2=106477&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Jun 21 15:59:55 2010
@@ -1634,6 +1634,11 @@
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)
Added: cfe/trunk/test/CodeGenObjCXX/references.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/references.mm?rev=106477&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/references.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/references.mm Mon Jun 21 15:59:55 2010
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+
+struct A { ~A(); };
+
+ at interface B {
+ A a;
+}
+
+- (const A&)getA;
+ at end
+
+ at implementation B
+
+- (const A&)getA {
+ return a;
+}
+
+ at end
+
+// CHECK: define void @_Z1fP1B
+// CHECK: objc_msgSend to
+// CHECK: ret void
+void f(B* b) {
+ (void)[b getA];
+}
More information about the cfe-commits
mailing list