summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-02-05 19:18:30 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-02-05 19:18:30 +0000
commitdf506b934ec2d0e2428edbe51501228fee753c43 (patch)
treea2f14e1bc3bc8a028616300c4a835f84ed2a7574
parentb8d375fd211fbe64f324d928fba902c5ce69dbd7 (diff)
downloadbcm5719-llvm-df506b934ec2d0e2428edbe51501228fee753c43.tar.gz
bcm5719-llvm-df506b934ec2d0e2428edbe51501228fee753c43.zip
Fix a code gen bug accessing 'isa' field via a message call
(Fixes radar 7609722). llvm-svn: 95406
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp19
-rw-r--r--clang/test/CodeGenObjC/id-isa-codegen.m14
2 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index f58d6e871bf..cb3fb61cf3f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1880,14 +1880,23 @@ LValue CodeGenFunction::EmitObjCIsaExpr(const ObjCIsaExpr *E) {
llvm::Value *V;
// object->isa or (*object).isa
// Generate code as for: *(Class*)object
+ // build Class* type
+ const llvm::Type *ClassPtrTy = ConvertType(E->getType());
+
Expr *BaseExpr = E->getBase();
- if (E->isArrow())
- V = ScalarExprEmitter(*this).EmitLoadOfLValue(BaseExpr);
- else
- V = EmitLValue(BaseExpr).getAddress();
+ if (BaseExpr->isLvalue(getContext()) != Expr::LV_Valid) {
+ V = CreateTempAlloca(ClassPtrTy, "resval");
+ llvm::Value *Src = EmitScalarExpr(BaseExpr);
+ Builder.CreateStore(Src, V);
+ }
+ else {
+ if (E->isArrow())
+ V = ScalarExprEmitter(*this).EmitLoadOfLValue(BaseExpr);
+ else
+ V = EmitLValue(BaseExpr).getAddress();
+ }
// build Class* type
- const llvm::Type *ClassPtrTy = ConvertType(E->getType());
ClassPtrTy = ClassPtrTy->getPointerTo();
V = Builder.CreateBitCast(V, ClassPtrTy);
LValue LV = LValue::MakeAddr(V, MakeQualifiers(E->getType()));
diff --git a/clang/test/CodeGenObjC/id-isa-codegen.m b/clang/test/CodeGenObjC/id-isa-codegen.m
index 89e99220907..3179e11b7f3 100644
--- a/clang/test/CodeGenObjC/id-isa-codegen.m
+++ b/clang/test/CodeGenObjC/id-isa-codegen.m
@@ -34,3 +34,17 @@ Class Test(const void *inObject1) {
return ((id)inObject1)->isa;
return (id)0;
}
+
+// rdar 7609722
+@interface Foo {
+@public
+ id isa;
+}
++(id)method;
+@end
+
+id Test2() {
+ if([Foo method]->isa)
+ return (*[Foo method]).isa;
+ return [Foo method]->isa;
+}
OpenPOWER on IntegriCloud