Revert "Numerous changes to selector handling:", this breaks a whole bunch of

working code, for no apparent reason.

llvm-svn: 95244
This commit is contained in:
Daniel Dunbar 2010-02-03 20:11:42 +00:00
parent d231689adb
commit 45858d2d59
8 changed files with 29 additions and 84 deletions

View File

@ -96,22 +96,18 @@ public:
/// ObjCSelectorExpr used for @selector in Objective-C. /// ObjCSelectorExpr used for @selector in Objective-C.
class ObjCSelectorExpr : public Expr { class ObjCSelectorExpr : public Expr {
Selector SelName; Selector SelName;
ObjCMethodDecl *Method;
SourceLocation AtLoc, RParenLoc; SourceLocation AtLoc, RParenLoc;
public: public:
ObjCSelectorExpr(QualType T, Selector selInfo, ObjCSelectorExpr(QualType T, Selector selInfo,
SourceLocation at, SourceLocation rp) SourceLocation at, SourceLocation rp)
: Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), Method(0), : Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), AtLoc(at),
AtLoc(at), RParenLoc(rp){} RParenLoc(rp){}
explicit ObjCSelectorExpr(EmptyShell Empty) explicit ObjCSelectorExpr(EmptyShell Empty)
: Expr(ObjCSelectorExprClass, Empty) {} : Expr(ObjCSelectorExprClass, Empty) {}
Selector getSelector() const { return SelName; } Selector getSelector() const { return SelName; }
void setSelector(Selector S) { SelName = S; } void setSelector(Selector S) { SelName = S; }
ObjCMethodDecl *getMethodDecl() const { return Method; }
void setMethodDecl(ObjCMethodDecl *M) { Method = M; }
SourceLocation getAtLoc() const { return AtLoc; } SourceLocation getAtLoc() const { return AtLoc; }
SourceLocation getRParenLoc() const { return RParenLoc; } SourceLocation getRParenLoc() const { return RParenLoc; }
void setAtLoc(SourceLocation L) { AtLoc = L; } void setAtLoc(SourceLocation L) { AtLoc = L; }

View File

@ -1454,7 +1454,6 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const {
case StringLiteralClass: case StringLiteralClass:
case ObjCStringLiteralClass: case ObjCStringLiteralClass:
case ObjCEncodeExprClass: case ObjCEncodeExprClass:
case ObjCSelectorExprClass:
return true; return true;
case CompoundLiteralExprClass: { case CompoundLiteralExprClass: {
// This handles gcc's extension that allows global initializers like // This handles gcc's extension that allows global initializers like

View File

@ -701,14 +701,6 @@ public:
CGM.GetStringForStringLiteral(E), false); CGM.GetStringForStringLiteral(E), false);
} }
llvm::Constant *VisitObjCSelectorExpr(const ObjCSelectorExpr *E) {
ObjCMethodDecl *OMD = E->getMethodDecl();
if (OMD)
return CGM.getObjCRuntime().GetConstantTypedSelector(OMD);
else
return CGM.getObjCRuntime().GetConstantSelector(E->getSelector());
}
llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) { llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
// This must be an @encode initializing an array in a static initializer. // This must be an @encode initializing an array in a static initializer.
// Don't emit it as the address of the string, emit the string data itself // Don't emit it as the address of the string, emit the string data itself

View File

@ -38,11 +38,7 @@ llvm::Value *CodeGenFunction::EmitObjCSelectorExpr(const ObjCSelectorExpr *E) {
// Note that this implementation allows for non-constant strings to be passed // Note that this implementation allows for non-constant strings to be passed
// as arguments to @selector(). Currently, the only thing preventing this // as arguments to @selector(). Currently, the only thing preventing this
// behaviour is the type checking in the front end. // behaviour is the type checking in the front end.
ObjCMethodDecl *OMD = E->getMethodDecl(); return CGM.getObjCRuntime().GetSelector(Builder, E->getSelector());
if (OMD)
return CGM.getObjCRuntime().GetSelector(Builder, OMD);
else
return CGM.getObjCRuntime().GetSelector(Builder, E->getSelector());
} }
llvm::Value *CodeGenFunction::EmitObjCProtocolExpr(const ObjCProtocolExpr *E) { llvm::Value *CodeGenFunction::EmitObjCProtocolExpr(const ObjCProtocolExpr *E) {

View File

@ -156,17 +156,9 @@ public:
const ObjCMethodDecl *Method); const ObjCMethodDecl *Method);
virtual llvm::Value *GetClass(CGBuilderTy &Builder, virtual llvm::Value *GetClass(CGBuilderTy &Builder,
const ObjCInterfaceDecl *OID); const ObjCInterfaceDecl *OID);
virtual llvm::Constant *GetConstantSelector(Selector Sel); virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel);
virtual llvm::Constant *GetConstantTypedSelector( virtual llvm::Value *GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
const ObjCMethodDecl *Method); *Method);
llvm::Value *GetSelector(CGBuilderTy &Builder,
Selector Sel) {
return cast<llvm::Constant>((GetConstantSelector(Sel)));
}
llvm::Value *GetSelector(CGBuilderTy &Builder,
const ObjCMethodDecl *Method) {
return cast<llvm::Constant>(GetConstantTypedSelector(Method));
}
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD, virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
const ObjCContainerDecl *CD); const ObjCContainerDecl *CD);
@ -347,18 +339,18 @@ llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder,
return Builder.CreateCall(ClassLookupFn, ClassName); return Builder.CreateCall(ClassLookupFn, ClassName);
} }
llvm::Constant *CGObjCGNU::GetConstantSelector(Selector Sel) { llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel) {
llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()]; llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()];
if (US == 0) if (US == 0)
US = new llvm::GlobalAlias(SelectorTy, US = new llvm::GlobalAlias(llvm::PointerType::getUnqual(SelectorTy),
llvm::GlobalValue::PrivateLinkage, llvm::GlobalValue::PrivateLinkage,
".objc_untyped_selector_alias"+Sel.getAsString(), ".objc_untyped_selector_alias"+Sel.getAsString(),
NULL, &TheModule); NULL, &TheModule);
return US; return Builder.CreateLoad(US);
} }
llvm::Constant *CGObjCGNU::GetConstantTypedSelector(const ObjCMethodDecl llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
*Method) { *Method) {
std::string SelName = Method->getSelector().getAsString(); std::string SelName = Method->getSelector().getAsString();
@ -370,17 +362,17 @@ llvm::Constant *CGObjCGNU::GetConstantTypedSelector(const ObjCMethodDecl
// If it's already cached, return it. // If it's already cached, return it.
if (TypedSelectors[Selector]) { if (TypedSelectors[Selector]) {
return TypedSelectors[Selector]; return Builder.CreateLoad(TypedSelectors[Selector]);
} }
// If it isn't, cache it. // If it isn't, cache it.
llvm::GlobalAlias *Sel = new llvm::GlobalAlias( llvm::GlobalAlias *Sel = new llvm::GlobalAlias(
SelectorTy, llvm::PointerType::getUnqual(SelectorTy),
llvm::GlobalValue::PrivateLinkage, ".objc_selector_alias" + SelName, llvm::GlobalValue::PrivateLinkage, ".objc_selector_alias" + SelName,
NULL, &TheModule); NULL, &TheModule);
TypedSelectors[Selector] = Sel; TypedSelectors[Selector] = Sel;
return Sel; return Builder.CreateLoad(Sel);
} }
llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str, llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str,
@ -1537,43 +1529,40 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
// Now that all of the static selectors exist, create pointers to them. // Now that all of the static selectors exist, create pointers to them.
int index = 0; int index = 0;
llvm::SmallVector<std::pair<llvm::GlobalAlias*,llvm::Value*>, 16> selectors;
for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator
iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end(); iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end();
iter != iterEnd; ++iter) { iter != iterEnd; ++iter) {
llvm::Constant *Idxs[] = {Zeros[0], llvm::Constant *Idxs[] = {Zeros[0],
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
llvm::Constant *SelPtr = llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy,
llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2); true, llvm::GlobalValue::InternalLinkage,
llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
".objc_sel_ptr");
// If selectors are defined as an opaque type, cast the pointer to this // If selectors are defined as an opaque type, cast the pointer to this
// type. // type.
if (isSelOpaque) { if (isSelOpaque) {
SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,SelectorTy); SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
llvm::PointerType::getUnqual(SelectorTy));
} }
selectors.push_back( (*iter).second->setAliasee(SelPtr);
std::pair<llvm::GlobalAlias*,llvm::Value*>((*iter).second, SelPtr));
} }
for (llvm::StringMap<llvm::GlobalAlias*>::iterator for (llvm::StringMap<llvm::GlobalAlias*>::iterator
iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end(); iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
iter != iterEnd; iter++) { iter != iterEnd; iter++) {
llvm::Constant *Idxs[] = {Zeros[0], llvm::Constant *Idxs[] = {Zeros[0],
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]}; llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
llvm::Constant *SelPtr = llvm::Constant *SelPtr = new llvm::GlobalVariable
llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2); (TheModule, SelStructPtrTy,
true, llvm::GlobalValue::InternalLinkage,
llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
".objc_sel_ptr");
// If selectors are defined as an opaque type, cast the pointer to this // If selectors are defined as an opaque type, cast the pointer to this
// type. // type.
if (isSelOpaque) { if (isSelOpaque) {
SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, SelectorTy); SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
llvm::PointerType::getUnqual(SelectorTy));
} }
selectors.push_back( (*iter).second->setAliasee(SelPtr);
std::pair<llvm::GlobalAlias*,llvm::Value*>((*iter).second, SelPtr));
}
for (llvm::SmallVectorImpl<std::pair<
llvm::GlobalAlias*,llvm::Value*> >::iterator
iter=selectors.begin(), iterEnd =selectors.end();
iter != iterEnd; ++iter) {
iter->first->replaceAllUsesWith(iter->second);
iter->first->eraseFromParent();
} }
// Number of classes defined. // Number of classes defined.
Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext), Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext),

View File

@ -953,14 +953,6 @@ public:
CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
CGM(cgm), VMContext(cgm.getLLVMContext()) { } CGM(cgm), VMContext(cgm.getLLVMContext()) { }
virtual llvm::Constant *GetConstantSelector(Selector Sel) {
assert(0 && "Constant Selectors are not yet supported on the Mac runtimes");
return 0;
}
virtual llvm::Constant *GetConstantTypedSelector(
const ObjCMethodDecl *Method) {
return GetConstantSelector(Method->getSelector());
}
virtual llvm::Constant *GenerateConstantString(const StringLiteral *SL); virtual llvm::Constant *GenerateConstantString(const StringLiteral *SL);
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD, virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,

View File

@ -95,12 +95,6 @@ public:
/// this compilation unit with the runtime library. /// this compilation unit with the runtime library.
virtual llvm::Function *ModuleInitFunction() = 0; virtual llvm::Function *ModuleInitFunction() = 0;
virtual llvm::Constant *GetConstantSelector(Selector Sel) = 0;
/// Get a typed selector.
virtual llvm::Constant *GetConstantTypedSelector(
const ObjCMethodDecl *Method) = 0;
/// Get a selector for the specified name and type values. The /// Get a selector for the specified name and type values. The
/// return value should have the LLVM type for pointer-to /// return value should have the LLVM type for pointer-to
/// ASTContext::getObjCSelType(). /// ASTContext::getObjCSelType().

View File

@ -140,20 +140,7 @@ Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
Diag(SelLoc, diag::warn_undeclared_selector) << Sel; Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
QualType Ty = Context.getObjCSelType(); QualType Ty = Context.getObjCSelType();
ObjCSelectorExpr *E = return new (Context) ObjCSelectorExpr(Ty, Sel, AtLoc, RParenLoc);
new (Context) ObjCSelectorExpr(Ty, Sel, AtLoc, RParenLoc);
// Make sure that we have seen this selector. There are lots of checks we
// should be doing on this selector. For example, when this is passed as the
// second argument to objc_msgSend() on the Mac runtime, or as the selector
// argument to the -performSelector:. We can do these checks at run time
// with the GNU runtimes, but the Apple runtimes let you sneak stack
// corruption in easily by passing the wrong selector to these functions if
// there is no static checking.
//
// Only log a warning on the GNU runtime.
E->setMethodDecl(LookupInstanceMethodInGlobalPool(Sel,
SourceRange(LParenLoc, LParenLoc), !LangOpts.NeXTRuntime));
return E;
} }
Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId, Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,