diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-12-09 19:05:56 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-12-09 19:05:56 +0000 |
commit | 83dc32594cde6bd083bd8b98b24bde2346585cad (patch) | |
tree | cf88a7c47256a426e396ef4ad2c59add12c31659 | |
parent | e4cb2a4b4ad6b9596f9109945a5b3a87949f375b (diff) |
Codegen. support for ObjCIsaExpr AST which until now
was not needed (fixes radar 7453430).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90981 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 19 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 | ||||
-rw-r--r-- | test/CodeGenObjC/id-isa-codegen.m | 24 |
3 files changed, 46 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index f19aa273d9..9ac8b4d8b3 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -167,6 +167,25 @@ public: return CGF.EmitObjCMessageExpr(E).getScalarVal(); } + Value *VisitObjCIsaExpr(ObjCIsaExpr *E) { + Value *V; + // object->isa or (*object).isa + // Generate code as for: *(Class*)object + Expr *BaseExpr = E->getBase(); + if (E->isArrow()) + V = 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, CGF.MakeQualifiers(E->getType())); + V = CGF.EmitLoadOfLValue(LV, E->getType()).getScalarVal(); + return V; + } + Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E); Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E); Value *VisitMemberExpr(MemberExpr *E); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index b284f83074..99afbaf605 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2528,8 +2528,8 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, BaseType->getAs<ObjCObjectPointerType>()) { if (OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && MemberName.getAsIdentifierInfo()->isStr("isa")) - return Owned(new (Context) ObjCIsaExpr(BaseExpr, false, MemberLoc, - Context.getObjCIdType())); + return Owned(new (Context) ObjCIsaExpr(BaseExpr, true, MemberLoc, + Context.getObjCClassType())); } } // We have an 'id' type. Rather than fall through, we check if this @@ -2888,7 +2888,7 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, BaseType->isSpecificBuiltinType(BuiltinType::ObjCId) && MemberName.getAsIdentifierInfo()->isStr("isa")) return Owned(new (Context) ObjCIsaExpr(BaseExpr, false, MemberLoc, - Context.getObjCIdType())); + Context.getObjCClassType())); // Handle 'field access' to vectors, such as 'V.xx'. if (BaseType->isExtVectorType()) { diff --git a/test/CodeGenObjC/id-isa-codegen.m b/test/CodeGenObjC/id-isa-codegen.m new file mode 100644 index 0000000000..a9ab4251e2 --- /dev/null +++ b/test/CodeGenObjC/id-isa-codegen.m @@ -0,0 +1,24 @@ +// RUN: clang-cc -emit-llvm -o %t %s + +typedef struct objc_class *Class; + +typedef struct objc_object { + Class isa; +} *id; + +@interface I ++ (Class) class; +- (void)meth : (id)object; ++ (unsigned char) isSubclassOfClass:(Class)aClass ; +@end + +@implementation I ++ (Class) class {return 0;} ++ (unsigned char) isSubclassOfClass:(Class)aClass {return 0;} +- (void)meth : (id)object { + [object->isa isSubclassOfClass:[I class]]; + + [(*object).isa isSubclassOfClass:[I class]]; +} +@end + |