aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2010-02-03 02:09:30 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2010-02-03 02:09:30 +0000
commita8fa96e366ab36145a5500dd4fbea717c217f131 (patch)
tree4f4bc945ca6a5e8fd2ba6e8886089c8de164d696 /lib/Sema/SemaExprObjC.cpp
parent6c048a916f6bf526c12217f4a2bc3aa1a62bd62e (diff)
Numerous changes to selector handling:
- Don't use GlobalAliases with non-0 GEPs (GNU runtime) - this was unsupported and LLVM will be generating errors if you do it soon. This also simplifies the code generated by the GNU runtime a bit. - Make GetSelector() return a constant (GNU runtime), not a load of a store of a constant. - Recognise @selector() expressions as valid static initialisers (as GCC does). - Add methods to GCObjCRuntime to emit selectors as constants (needed for using @selector() expressions as constants. These need implementing for the Mac runtimes - I couldn't figure out how to do this, they seem to require a load. - Store an ObjCMethodDecl in an ObjCSelectorExpr so that we can get at the type information for the selector. This is needed for generating typed selectors from @selector() expressions (as GCC does). Ideally, this information should be stored in the Selector, but that would be an invasive change. We should eventually add checks for common uses of @selector() expressions. Possibly adding an attribute that can be applied to method args providing the types of a selector so, for example, you'd do something like this: - (id)performSelector: __attribute__((selector_types(id, SEL, id)))(SEL) withObject: (id)object; Then, any @selector() expressions passed to the method will be check to ensure that it conforms to this signature. We do this at run time on the GNU runtime already, but it would be nice to do it at compile time on all runtimes. - Made @selector() expressions emit type info if available and the runtime supports it. Someone more familiar with the Mac runtime needs to implement the GetConstantSelector() function in CGObjCMac. This currently just assert()s. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r--lib/Sema/SemaExprObjC.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 85956c3e7e..8ce782b961 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -140,7 +140,20 @@ Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
QualType Ty = Context.getObjCSelType();
- return new (Context) ObjCSelectorExpr(Ty, Sel, AtLoc, RParenLoc);
+ ObjCSelectorExpr *E =
+ 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,