[cfe-commits] r42817 - in /cfe/trunk: AST/ASTContext.cpp Parse/Parser.cpp Sema/Sema.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Parse/Action.h test/Sema/selector-overload.m

Steve Naroff snaroff at apple.com
Tue Oct 9 15:01:59 PDT 2007


Author: snaroff
Date: Tue Oct  9 17:01:59 2007
New Revision: 42817

URL: http://llvm.org/viewvc/llvm-project?rev=42817&view=rev
Log:

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).

Added:
    cfe/trunk/test/Sema/selector-overload.m
Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/Sema/Sema.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Oct  9 17:01:59 2007
@@ -110,7 +110,6 @@
   Types.push_back((R = QualType(new BuiltinType(K),0)).getTypePtr());
 }
 
-
 void ASTContext::InitBuiltinTypes() {
   assert(VoidTy.isNull() && "Context reinitialized?");
   

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Tue Oct  9 17:01:59 2007
@@ -192,7 +192,7 @@
   // 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 @@
   // 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.
   {

Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Tue Oct  9 17:01:59 2007
@@ -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) {
   

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Oct  9 17:01:59 2007
@@ -113,6 +113,9 @@
   /// 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 @@
 
   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.

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct  9 17:01:59 2007
@@ -34,7 +34,7 @@
   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 @@
                               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,

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct  9 17:01:59 2007
@@ -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 = "";

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=42817&r1=42816&r2=42817&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Oct  9 17:01:59 2007
@@ -135,10 +135,14 @@
   }
 
   
-  /// 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) {

Added: cfe/trunk/test/Sema/selector-overload.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/selector-overload.m?rev=42817&view=auto

==============================================================================
--- cfe/trunk/test/Sema/selector-overload.m (added)
+++ cfe/trunk/test/Sema/selector-overload.m Tue Oct  9 17:01:59 2007
@@ -0,0 +1,43 @@
+// RUN: clang %s -parse-ast
+#import <Foundation/NSObject.h>
+
+struct D {
+  double d;
+};
+
+ at interface Foo : NSObject 
+
+- method:(int)a;
+- method:(int)a;
+
+ at end
+
+ at interface Bar : NSObject 
+
+- method:(void *)a;
+
+ at end
+
+ at interface Car : NSObject 
+
+- method:(struct D)a;
+
+ at end
+
+ at interface Zar : NSObject 
+
+- method:(float)a;
+
+ at end
+
+ at interface Rar : NSObject 
+
+- method:(float)a;
+
+ at end
+
+int main() {
+//  id xx = [[Car alloc] init];
+
+//  [xx method:4];
+}





More information about the cfe-commits mailing list