[cfe-commits] r47538 - /cfe/trunk/Sema/Sema.cpp

Steve Naroff snaroff at apple.com
Sun Feb 24 08:25:03 PST 2008


Author: snaroff
Date: Sun Feb 24 10:25:02 2008
New Revision: 47538

URL: http://llvm.org/viewvc/llvm-project?rev=47538&view=rev
Log:
Move the initialization of SEL/objc_selector from Sema::Sema() to Sema::ActOnTranslationUnitScope() and make sure the type/struct get inserted into the translation unit scope.

Bug submitted by David Chisnall (thanks!).

Modified:
    cfe/trunk/Sema/Sema.cpp

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

==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Sun Feb 24 10:25:02 2008
@@ -57,9 +57,20 @@
   ObjCInterfaceDecl *IDecl = it->getDecl();
   IDecl->getIdentifier()->setFETokenInfo(IDecl);
   TUScope->AddDecl(IDecl);
-  t = cast<TypedefType>(Context.getObjCSelType().getTypePtr());
-  t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
-  TUScope->AddDecl(t->getDecl());
+  
+  // Synthesize "typedef struct objc_selector *SEL;"
+  RecordDecl *SelTag = new RecordDecl(Decl::Struct, SourceLocation(), 
+                                      &Context.Idents.get("objc_selector"), 0);
+  SelTag->getIdentifier()->setFETokenInfo(SelTag);
+  TUScope->AddDecl(SelTag);
+  
+  QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag));
+  TypedefDecl *SelTypedef = new TypedefDecl(SourceLocation(),
+                                            &Context.Idents.get("SEL"),
+                                            SelT, 0);
+  SelTypedef->getIdentifier()->setFETokenInfo(SelTypedef);
+  TUScope->AddDecl(SelTypedef);
+  Context.setObjCSelType(SelTypedef);
 }
 
 Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
@@ -81,6 +92,8 @@
   KnownFunctionIDs[id_vsprintf]  = &IT.get("vsprintf");
   KnownFunctionIDs[id_vprintf]   = &IT.get("vprintf");
 
+  // FIXME: Move this initialization up to Sema::ActOnTranslationUnitScope()
+  // and make sure the decls get inserted into TUScope!
   if (PP.getLangOptions().ObjC1) {
     // Synthesize "typedef struct objc_class *Class;"
     RecordDecl *ClassTag = new RecordDecl(Decl::Struct, SourceLocation(), 
@@ -107,16 +120,6 @@
                                              &Context.Idents.get("id"),
                                              ObjT, 0);
     Context.setObjCIdType(IdTypedef);
-    
-    // Synthesize "typedef struct objc_selector *SEL;"
-    RecordDecl *SelTag = new RecordDecl(Decl::Struct, SourceLocation(), 
-                                          &IT.get("objc_selector"), 0);
-    QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag));
-    TypedefDecl *SelTypedef = new TypedefDecl(SourceLocation(),
-                                              &Context.Idents.get("SEL"),
-                                              SelT, 0);
-    Context.setObjCSelType(SelTypedef);
-    
   }
   TUScope = 0;
 }





More information about the cfe-commits mailing list