summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-10-09 22:01:59 +0000
committerSteve Naroff <snaroff@apple.com>2007-10-09 22:01:59 +0000
commitc62adb6d1a185870ce57766cd20e793545863683 (patch)
treefd8e64929f7a19fa5b2d94cbc4eb53beb5db3ba1 /clang
parent230c6cc51682b935cb4204b2eb77e990b352e02d (diff)
downloadbcm5719-llvm-c62adb6d1a185870ce57766cd20e793545863683.tar.gz
bcm5719-llvm-c62adb6d1a185870ce57766cd20e793545863683.zip
Make sure methods with no return type default to "id".
This fixes a crasher in Sema::MatchTwoMethodDeclarations(), identified by selector-overload.m (just added). Added Action::ActOnTranslationUnitScope() and renamed Action::PopScope to ActOnPopScope. Added a Translation Unit Scope instance variable to Sema (will be very useful to ObjC-related actions, since ObjC declarations are always file-scoped). llvm-svn: 42817
Diffstat (limited to 'clang')
-rw-r--r--clang/AST/ASTContext.cpp1
-rw-r--r--clang/Parse/Parser.cpp5
-rw-r--r--clang/Sema/Sema.cpp4
-rw-r--r--clang/Sema/Sema.h8
-rw-r--r--clang/Sema/SemaDecl.cpp15
-rw-r--r--clang/clang.xcodeproj/project.pbxproj3
-rw-r--r--clang/include/clang/Parse/Action.h12
-rw-r--r--clang/test/Sema/selector-overload.m43
8 files changed, 79 insertions, 12 deletions
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp
index c9959df31fd..6608330b680 100644
--- a/clang/AST/ASTContext.cpp
+++ b/clang/AST/ASTContext.cpp
@@ -110,7 +110,6 @@ void ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) {
Types.push_back((R = QualType(new BuiltinType(K),0)).getTypePtr());
}
-
void ASTContext::InitBuiltinTypes() {
assert(VoidTy.isNull() && "Context reinitialized?");
diff --git a/clang/Parse/Parser.cpp b/clang/Parse/Parser.cpp
index 117afab5cfa..fc5c4ae4f71 100644
--- a/clang/Parse/Parser.cpp
+++ b/clang/Parse/Parser.cpp
@@ -192,7 +192,7 @@ void Parser::ExitScope() {
// Inform the actions module that this scope is going away if there are any
// decls in it.
if (!CurScope->decl_empty())
- Actions.PopScope(Tok.getLocation(), CurScope);
+ Actions.ActOnPopScope(Tok.getLocation(), CurScope);
Scope *OldScope = CurScope;
CurScope = OldScope->getParent();
@@ -228,7 +228,8 @@ void Parser::Initialize() {
// Create the translation unit scope. Install it as the current scope.
assert(CurScope == 0 && "A scope is already active?");
EnterScope(Scope::DeclScope);
-
+ Actions.ActOnTranslationUnitScope(Tok.getLocation(), CurScope);
+
// Install builtin types.
// TODO: Move this someplace more useful.
{
diff --git a/clang/Sema/Sema.cpp b/clang/Sema/Sema.cpp
index 1a012706927..125b0cb63fd 100644
--- a/clang/Sema/Sema.cpp
+++ b/clang/Sema/Sema.cpp
@@ -19,6 +19,10 @@
using namespace clang;
+void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
+ TUScope = S;
+}
+
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
: PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
diff --git a/clang/Sema/Sema.h b/clang/Sema/Sema.h
index e2ec394901c..6c2b41e3ce3 100644
--- a/clang/Sema/Sema.h
+++ b/clang/Sema/Sema.h
@@ -113,6 +113,9 @@ class Sema : public Action {
/// This list is populated upon the creation of a Sema object.
IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
+ /// Translation Unit Scope - useful to many Objective-C actions that need
+ /// to lookup file scope declarations (like classes, protocols, etc.).
+ Scope *TUScope;
public:
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
@@ -161,7 +164,10 @@ private:
virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body);
- virtual void PopScope(SourceLocation Loc, Scope *S);
+
+ /// Scope actions.
+ virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
+ virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index d85ee6bc301..ba6c7d0175e 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -34,7 +34,7 @@ Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
return 0;
}
-void Sema::PopScope(SourceLocation Loc, Scope *S) {
+void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
if (S->decl_empty()) return;
assert((S->getFlags() & Scope::DeclScope) &&"Scope shouldn't contain decls!");
@@ -1782,7 +1782,18 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(SourceLocation MethodLoc,
VarDecl::None, 0);
Params.push_back(Param);
}
- QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
+ QualType resultDeclType;
+
+ if (ReturnType)
+ resultDeclType = QualType::getFromOpaquePtr(ReturnType);
+ else { // get the type for "id".
+ IdentifierInfo *IdIdent = &Context.Idents.get("id");
+ ScopedDecl *IdDecl = LookupScopedDecl(IdIdent, Decl::IDNS_Ordinary,
+ SourceLocation(), TUScope);
+ TypedefDecl *IdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
+ assert(IdTypedef && "ActOnMethodDeclaration(): Couldn't find 'id' type");
+ resultDeclType = IdTypedef->getUnderlyingType();
+ }
ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel,
resultDeclType, 0, -1, AttrList,
MethodType == tok::minus,
diff --git a/clang/clang.xcodeproj/project.pbxproj b/clang/clang.xcodeproj/project.pbxproj
index c7f4908c0dd..0db725b41a9 100644
--- a/clang/clang.xcodeproj/project.pbxproj
+++ b/clang/clang.xcodeproj/project.pbxproj
@@ -237,7 +237,7 @@
84AF36A00CB17A3B00C820A5 /* DeclObjC.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclObjC.h; path = clang/AST/DeclObjC.h; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
- 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
@@ -739,7 +739,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h
index 31045f3cf44..af8170fe904 100644
--- a/clang/include/clang/Parse/Action.h
+++ b/clang/include/clang/Parse/Action.h
@@ -135,10 +135,14 @@ public:
}
- /// PopScope - This callback is called immediately before the specified scope
- /// is popped and deleted.
- virtual void PopScope(SourceLocation Loc, Scope *S) {}
-
+ /// ActOnPopScope - This callback is called immediately before the specified
+ /// scope is popped and deleted.
+ virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {}
+
+ /// ActOnTranslationUnitScope - This callback is called once, immediately
+ /// after creating the translation unit scope (in Parser::Initialize).
+ virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {}
+
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
diff --git a/clang/test/Sema/selector-overload.m b/clang/test/Sema/selector-overload.m
new file mode 100644
index 00000000000..8b433a48030
--- /dev/null
+++ b/clang/test/Sema/selector-overload.m
@@ -0,0 +1,43 @@
+// RUN: clang %s -parse-ast
+#import <Foundation/NSObject.h>
+
+struct D {
+ double d;
+};
+
+@interface Foo : NSObject
+
+- method:(int)a;
+- method:(int)a;
+
+@end
+
+@interface Bar : NSObject
+
+- method:(void *)a;
+
+@end
+
+@interface Car : NSObject
+
+- method:(struct D)a;
+
+@end
+
+@interface Zar : NSObject
+
+- method:(float)a;
+
+@end
+
+@interface Rar : NSObject
+
+- method:(float)a;
+
+@end
+
+int main() {
+// id xx = [[Car alloc] init];
+
+// [xx method:4];
+}
OpenPOWER on IntegriCloud