r304449 - [CodeGen][ObjC] Fix assertion failure in EmitARCStoreStrongCall.
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 1 11:41:25 PDT 2017
Author: ahatanak
Date: Thu Jun 1 13:41:25 2017
New Revision: 304449
URL: http://llvm.org/viewvc/llvm-project?rev=304449&view=rev
Log:
[CodeGen][ObjC] Fix assertion failure in EmitARCStoreStrongCall.
The assertion fails because EmitValueForIvarAtOffset doesn't get the
correct type of the ivar when the class the ivar belongs to is
parameterized. This commit fixes the function to compute the ivar's type
based on the type argument provided to the parameterized class.
rdar://problem/32461723
Differential Revision: https://reviews.llvm.org/D33698
Modified:
cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
cfe/trunk/test/CodeGenObjC/parameterized_classes.m
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp?rev=304449&r1=304448&r2=304449&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp Thu Jun 1 13:41:25 2017
@@ -90,7 +90,11 @@ LValue CGObjCRuntime::EmitValueForIvarAt
unsigned CVRQualifiers,
llvm::Value *Offset) {
// Compute (type*) ( (char *) BaseValue + Offset)
- QualType IvarTy = Ivar->getType().withCVRQualifiers(CVRQualifiers);
+ QualType InterfaceTy{OID->getTypeForDecl(), 0};
+ QualType ObjectPtrTy =
+ CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
+ QualType IvarTy =
+ Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
V = CGF.Builder.CreateInBoundsGEP(V, Offset, "add.ptr");
Modified: cfe/trunk/test/CodeGenObjC/parameterized_classes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/parameterized_classes.m?rev=304449&r1=304448&r2=304449&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/parameterized_classes.m (original)
+++ cfe/trunk/test/CodeGenObjC/parameterized_classes.m Thu Jun 1 13:41:25 2017
@@ -68,3 +68,31 @@ void blockTest(NSMutableArray<void (^)(v
// CHECK: call i8* @objc_retainBlock
// CHECK: ret void
}
+
+// CHECK-LABEL: define internal void @"\01-[Derived setDest:]
+// CHECK: %[[SELFADDR:.*]] = alloca %[[SELFTY:.*]]*
+// CHECK: %[[AADDR:.*]] = alloca %[[IVARTY:.*]]*
+// CHECK: %[[V2:.*]] = load %[[IVARTY]]*, %[[IVARTY]]** %[[AADDR]]
+// CHECK: %[[V3:.*]] = load %[[SELFTY]]*, %[[SELFTY]]** %[[SELFADDR]]
+// CHECK: %[[IVAR:.*]] = load i64, i64* @"OBJC_IVAR_$_Base._destination"
+// CHECK: %[[V4:.*]] = bitcast %[[SELFTY]]* %[[V3]] to i8*
+// CHECK: %[[ADDPTR:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 %[[IVAR]]
+// CHECK: %[[V5:.*]] = bitcast i8* %[[ADDPTR]] to %[[IVARTY]]**
+// CHECK: %[[V6:.*]] = bitcast %[[IVARTY]]** %[[V5]] to i8**
+// CHECK: %[[V7:.*]] = bitcast %[[IVARTY]]* %[[V2]] to i8*
+// CHECK: call void @objc_storeStrong(i8** %[[V6]], i8* %[[V7]])
+
+ at interface Base<DestType> : NSObject {
+ DestType _destination;
+}
+ at end
+
+ at interface Derived : Base<NSObject *>
+- (void)setDest:(NSObject *)a;
+ at end
+
+ at implementation Derived
+- (void)setDest:(NSObject *)a {
+ _destination = a;
+}
+ at end
More information about the cfe-commits
mailing list