[cfe-commits] r157641 - in /cfe/trunk: lib/CodeGen/CGObjC.cpp lib/CodeGen/CodeGenFunction.h lib/Sema/SemaObjCProperty.cpp test/CodeGenObjC/getter-property-type-mismatch.m test/SemaObjC/property-typecheck-1.m
Fariborz Jahanian
fjahanian at apple.com
Tue May 29 12:56:01 PDT 2012
Author: fjahanian
Date: Tue May 29 14:56:01 2012
New Revision: 157641
URL: http://llvm.org/viewvc/llvm-project?rev=157641&view=rev
Log:
objective-c: fix a sema and IRGen crash when property
getter result type is safe but does not match with property
type resulting in spurious warning followed by crash in
IRGen. // rdar://11515196
Added:
cfe/trunk/test/CodeGenObjC/getter-property-type-mismatch.m
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/property-typecheck-1.m
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=157641&r1=157640&r2=157641&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue May 29 14:56:01 2012
@@ -30,7 +30,7 @@
static TryEmitResult
tryEmitARCRetainScalarExpr(CodeGenFunction &CGF, const Expr *e);
static RValue AdjustRelatedResultType(CodeGenFunction &CGF,
- const Expr *E,
+ QualType ET,
const ObjCMethodDecl *Method,
RValue Result);
@@ -202,20 +202,20 @@
/// \brief Adjust the type of the result of an Objective-C message send
/// expression when the method has a related result type.
static RValue AdjustRelatedResultType(CodeGenFunction &CGF,
- const Expr *E,
+ QualType ExpT,
const ObjCMethodDecl *Method,
RValue Result) {
if (!Method)
return Result;
if (!Method->hasRelatedResultType() ||
- CGF.getContext().hasSameType(E->getType(), Method->getResultType()) ||
+ CGF.getContext().hasSameType(ExpT, Method->getResultType()) ||
!Result.isScalar())
return Result;
// We have applied a related result type. Cast the rvalue appropriately.
return RValue::get(CGF.Builder.CreateBitCast(Result.getScalarVal(),
- CGF.ConvertType(E->getType())));
+ CGF.ConvertType(ExpT)));
}
/// Decide whether to extend the lifetime of the receiver of a
@@ -401,7 +401,7 @@
Builder.CreateStore(newSelf, selfAddr);
}
- return AdjustRelatedResultType(*this, E, method, result);
+ return AdjustRelatedResultType(*this, E->getType(), method, result);
}
namespace {
@@ -710,7 +710,7 @@
assert(OMD && "Invalid call to generate getter (empty method)");
StartObjCMethod(OMD, IMP->getClassInterface(), OMD->getLocStart());
- generateObjCGetterBody(IMP, PID, AtomicHelperFn);
+ generateObjCGetterBody(IMP, PID, OMD, AtomicHelperFn);
FinishFunction();
}
@@ -772,6 +772,7 @@
void
CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
const ObjCPropertyImplDecl *propImpl,
+ const ObjCMethodDecl *GetterMethodDecl,
llvm::Constant *AtomicHelperFn) {
// If there's a non-trivial 'get' expression, we just have to emit that.
if (!hasTrivialGetExpr(propImpl)) {
@@ -905,6 +906,8 @@
}
value = Builder.CreateBitCast(value, ConvertType(propType));
+ value = Builder.CreateBitCast(value,
+ ConvertType(GetterMethodDecl->getResultType()));
}
EmitReturnOfRValue(RValue::get(value), propType);
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=157641&r1=157640&r2=157641&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue May 29 14:56:01 2012
@@ -1310,6 +1310,7 @@
const ObjCPropertyImplDecl *PID);
void generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
const ObjCPropertyImplDecl *propImpl,
+ const ObjCMethodDecl *GetterMothodDecl,
llvm::Constant *AtomicHelperFn);
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=157641&r1=157640&r2=157641&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue May 29 14:56:01 2012
@@ -1114,9 +1114,9 @@
isa<ObjCObjectPointerType>(GetterType))
compat =
Context.canAssignObjCInterfaces(
- PropertyIvarType->getAs<ObjCObjectPointerType>(),
- GetterType->getAs<ObjCObjectPointerType>());
- else if (CheckAssignmentConstraints(Loc, PropertyIvarType, GetterType)
+ GetterType->getAs<ObjCObjectPointerType>(),
+ PropertyIvarType->getAs<ObjCObjectPointerType>());
+ else if (CheckAssignmentConstraints(Loc, GetterType, PropertyIvarType)
!= Compatible) {
Diag(Loc, diag::error_property_accessor_type)
<< property->getDeclName() << PropertyIvarType
Added: cfe/trunk/test/CodeGenObjC/getter-property-type-mismatch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/getter-property-type-mismatch.m?rev=157641&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/getter-property-type-mismatch.m (added)
+++ cfe/trunk/test/CodeGenObjC/getter-property-type-mismatch.m Tue May 29 14:56:01 2012
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://11515196
+
+ at interface NSArray @end
+
+ at interface NSMutableArray : NSArray
+- (void) addObject;
+ at end
+
+ at interface BPXLAppDelegate
+
+- (NSArray *)arrayOfThings;
+
+ at end
+
+
+ at interface BPXLAppDelegate ()
+ at property (retain, nonatomic) NSMutableArray *arrayOfThings;
+ at end
+
+ at implementation BPXLAppDelegate
+
+ at synthesize arrayOfThings=_arrayOfThings;
+
+- (void)applicationDidFinishLaunching
+{
+ [self.arrayOfThings addObject];
+}
+
+ at end
+
+// CHECK: define internal [[RET:%.*]]* @"\01-[BPXLAppDelegate arrayOfThings
+// CHECK: [[THREE:%.*]] = bitcast [[OPQ:%.*]]* [[TWO:%.*]] to [[RET]]*
+// CHECK: ret [[RET]]* [[THREE]]
+
Modified: cfe/trunk/test/SemaObjC/property-typecheck-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-typecheck-1.m?rev=157641&r1=157640&r2=157641&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-typecheck-1.m (original)
+++ cfe/trunk/test/SemaObjC/property-typecheck-1.m Tue May 29 14:56:01 2012
@@ -73,11 +73,11 @@
NSArray* first;
}
- at property (readonly) NSArray* pieces;
- at property (readonly) NSMutableArray* first; // expected-warning {{type of property 'first' does not match type of accessor 'first'}}
+ at property (readonly) NSArray* pieces; // expected-warning {{type of property 'pieces' does not match type of accessor 'pieces'}}
+ at property (readonly) NSMutableArray* first;
-- (NSMutableArray*) pieces;
-- (NSArray*) first; // expected-note 2 {{declared here}}
+- (NSMutableArray*) pieces; // expected-note 2 {{declared here}}
+- (NSArray*) first;
@end
@interface Class2 {
@@ -90,12 +90,12 @@
- (id) lastPiece
{
- return container.pieces;
+ return container.pieces; // expected-warning {{type of property 'pieces' does not match type of accessor 'pieces'}}
}
- (id)firstPeice
{
- return container.first; // expected-warning {{type of property 'first' does not match type of accessor 'first'}}
+ return container.first;
}
@end
More information about the cfe-commits
mailing list