From 3523d4f59eb0aa1f200dcb943093ecfe75008735 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 10 Mar 2009 18:03:11 +0000 Subject: [PATCH] ir-gen support for class getter/setter call using property dot-syntax. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66556 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprObjC.h | 6 +++++- lib/CodeGen/CGObjC.cpp | 22 ++++++++++++++++++---- test/CodeGenObjC/class-getter-dotsyntax.m | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 test/CodeGenObjC/class-getter-dotsyntax.m diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h index d312d539a8..5775cab3ba 100644 --- a/include/clang/AST/ExprObjC.h +++ b/include/clang/AST/ExprObjC.h @@ -275,7 +275,11 @@ public: ObjCMethodDecl *getSetterMethod() const { return Setter; } - + + ObjCInterfaceDecl *getClassProp() const { + return ClassProp; + } + virtual SourceRange getSourceRange() const { if (Base) return SourceRange(getBase()->getLocStart(), Loc); diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 5798865077..aa1f4c2494 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -327,10 +327,17 @@ RValue CodeGenFunction::EmitObjCPropertyGet(const Expr *Exp) { else { const ObjCKVCRefExpr *KE = cast(Exp); Selector S = KE->getGetterMethod()->getSelector(); + llvm::Value *Receiver; + if (KE->getClassProp()) { + const ObjCInterfaceDecl *OID = KE->getClassProp(); + Receiver = CGM.getObjCRuntime().GetClass(Builder, OID); + } + else + Receiver = EmitScalarExpr(KE->getBase()); return CGM.getObjCRuntime(). GenerateMessageSend(*this, Exp->getType(), S, - EmitScalarExpr(KE->getBase()), - false, CallArgList()); + Receiver, + KE->getClassProp() != 0, CallArgList()); } } @@ -348,10 +355,17 @@ void CodeGenFunction::EmitObjCPropertySet(const Expr *Exp, else if (const ObjCKVCRefExpr *E = dyn_cast(Exp)) { Selector S = E->getSetterMethod()->getSelector(); CallArgList Args; + llvm::Value *Receiver; + if (E->getClassProp()) { + const ObjCInterfaceDecl *OID = E->getClassProp(); + Receiver = CGM.getObjCRuntime().GetClass(Builder, OID); + } + else + Receiver = EmitScalarExpr(E->getBase()); Args.push_back(std::make_pair(Src, E->getType())); CGM.getObjCRuntime().GenerateMessageSend(*this, getContext().VoidTy, S, - EmitScalarExpr(E->getBase()), - false, Args); + Receiver, + E->getClassProp() != 0, Args); } else assert (0 && "bad expression node in EmitObjCPropertySet"); diff --git a/test/CodeGenObjC/class-getter-dotsyntax.m b/test/CodeGenObjC/class-getter-dotsyntax.m new file mode 100644 index 0000000000..54ed890cc4 --- /dev/null +++ b/test/CodeGenObjC/class-getter-dotsyntax.m @@ -0,0 +1,21 @@ +// RUN: clang -fnext-runtime -emit-llvm -o %t %s + +@interface Test { } ++ (Test *)crash; ++ (void)setCrash: (int)value; +@end + +@implementation Test +static int _value; +- (void)cachesPath +{ + static Test *cachesPath; + + if (!cachesPath) { + Test *crash = Test.crash; + } +} ++ (Test *)crash{ return 0; } ++ (void)setCrash: (int)value{ _value = value; } +@end + -- 2.40.0