From b19c76e857d21b722d0a207cb45b26d7cb20a73f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 8 Feb 2011 22:33:23 +0000 Subject: [PATCH] Fix an IRGen bug in property setter calls when setter and getter types mismatch. // rdar://8966864 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125125 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjC.cpp | 12 +++++++++++- test/CodeGenObjC/property-type-mismatch.m | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenObjC/property-type-mismatch.m diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 1c64e3cb4c..066ae5ab3a 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -585,7 +585,17 @@ void CodeGenFunction::EmitStoreThroughPropertyRefLValue(RValue Src, } else { ArgType = E->getType(); } - + // FIXME. Other than scalars, AST is not adequate for setter and + // getter type mismatches which require conversion. + if (Src.isScalar()) { + llvm::Value *SrcVal = Src.getScalarVal(); + QualType DstType = getContext().getCanonicalType(ArgType); + const llvm::Type *DstTy = ConvertType(DstType); + if (SrcVal->getType() != DstTy) + Src = + RValue::get(EmitScalarConversion(SrcVal, E->getType(), DstType)); + } + CallArgList Args; Args.push_back(std::make_pair(Src, ArgType)); diff --git a/test/CodeGenObjC/property-type-mismatch.m b/test/CodeGenObjC/property-type-mismatch.m new file mode 100644 index 0000000000..7045947b1a --- /dev/null +++ b/test/CodeGenObjC/property-type-mismatch.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s +// rdar://8966864 + +@interface Foo +-(float)myfo; +-(void)setMyfo: (int)p; +@end + +void bar(Foo *x) { + x.myfo++; +} + +// CHECK: [[C1:%.*]] = call float bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: [[I:%.*]] = fadd float [[C1]], 1.000000e+00 +// CHECK: [[CONV:%.*]] = fptosi float [[I]] to i32 +// CHECK: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_2" +// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend -- 2.50.1