Protocol related tweaks
- Implement type conversion of ObjCQualifiedIdType
- Wire @protocol(...) to GenerateProtocolRef in ScalarExprEmitter
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54666 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index decf539..2949654 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -14,6 +14,7 @@
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Constants.h"
@@ -135,6 +136,7 @@
}
Value *VisitObjCMessageExpr(ObjCMessageExpr *E);
Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E);
+ Value *VisitObjCProtocolExpr(ObjCProtocolExpr *E);
Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E);}
Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E);
@@ -506,6 +508,11 @@
return Runtime->GetSelector(Builder, E->getSelector());
}
+Value *ScalarExprEmitter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
+ // FIXME: This should pass the Decl not the name.
+ return Runtime->GenerateProtocolRef(Builder, E->getProtocol()->getName());
+}
+
Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
// Emit subscript expressions in rvalue context's. For most cases, this just
// loads the lvalue formed by the subscript expr. However, we have to be
diff --git a/lib/CodeGen/CGObjCRuntime.h b/lib/CodeGen/CGObjCRuntime.h
index 5e8172b..d4f7bb0 100644
--- a/lib/CodeGen/CGObjCRuntime.h
+++ b/lib/CodeGen/CGObjCRuntime.h
@@ -47,6 +47,10 @@
/// Generate an Objective-C message send operation
virtual llvm::Value *GenerateMessageSend(BuilderType &Builder,
const llvm::Type *ReturnTy,
+ // FIXME: This should be
+ // dropped, it is unused
+ // and generates a spurious
+ // load.
llvm::Value *Sender,
llvm::Value *Receiver,
Selector Sel,
@@ -81,17 +85,25 @@
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
const llvm::SmallVectorImpl<std::string> &Protocols) =0;
- /// Generate a reference to the named protocol.
- virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
- const char *ProtocolName) = 0;
virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
const llvm::Type *ReturnTy,
+ // FIXME: This should
+ // be dropped, it is
+ // unused and
+ // generates a
+ // spurious load.
llvm::Value *Sender,
const char *SuperClassName,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC) = 0;
+
+ /// Emit the code to return the named protocol as an object, as in a
+ /// @protocol expression.
+ virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
+ const char *ProtocolName) = 0;
+
/// Generate the named protocol. Protocols contain method metadata but no
/// implementations.
virtual void GenerateProtocol(const char *ProtocolName,
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index ab0829e..2d5bd12 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -306,6 +306,10 @@
ConvertTypeRecursive(QualType(cast<ASQualType>(Ty).getBaseType(), 0));
case Type::ObjCInterface: {
+ // FIXME: This comment is broken. Either the code should check for
+ // the flag it is referring to or it should do the right thing in
+ // the presence of it.
+
// Warning: Use of this is strongly discouraged. Late binding of instance
// variables is supported on some runtimes and so using static binding can
// break code when libraries are updated. Only use this if you have
@@ -322,8 +326,8 @@
break;
case Type::ObjCQualifiedId:
- assert(0 && "FIXME: add missing functionality here");
- break;
+ // Protocols don't influence the LLVM type.
+ return ConvertTypeRecursive(Context.getObjCIdType());
case Type::Tagged: {
const TagDecl *TD = cast<TagType>(Ty).getDecl();