[cfe-commits] r95406 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenObjC/id-isa-codegen.m

Fariborz Jahanian fjahanian at apple.com
Fri Feb 5 11:18:30 PST 2010


Author: fjahanian
Date: Fri Feb  5 13:18:30 2010
New Revision: 95406

URL: http://llvm.org/viewvc/llvm-project?rev=95406&view=rev
Log:
Fix a code gen bug accessing 'isa' field via a message call
(Fixes radar 7609722).

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenObjC/id-isa-codegen.m

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=95406&r1=95405&r2=95406&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Feb  5 13:18:30 2010
@@ -1880,14 +1880,23 @@
   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()));

Modified: cfe/trunk/test/CodeGenObjC/id-isa-codegen.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/id-isa-codegen.m?rev=95406&r1=95405&r2=95406&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/id-isa-codegen.m (original)
+++ cfe/trunk/test/CodeGenObjC/id-isa-codegen.m Fri Feb  5 13:18:30 2010
@@ -34,3 +34,17 @@
    return ((id)inObject1)->isa;
   return (id)0;
 }
+
+// rdar 7609722
+ at interface Foo { 
+ at public 
+  id isa; 
+} 
++(id)method;
+ at end
+
+id Test2() {
+    if([Foo method]->isa)
+      return (*[Foo method]).isa;
+    return [Foo method]->isa;
+}





More information about the cfe-commits mailing list