[cfe-commits] r73319 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/Basic/Builtins.h include/clang/Lex/Preprocessor.h lib/AST/ASTContext.cpp lib/AST/Decl.cpp lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/Analysis/GRExprEngine.cpp lib/Basic/Builtins.cpp lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaLookup.cpp test/Preprocessor/feature_tests.c tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Sat Jun 13 18:54:57 PDT 2009


Author: lattner
Date: Sat Jun 13 20:54:56 2009
New Revision: 73319

URL: http://llvm.org/viewvc/llvm-project?rev=73319&view=rev
Log:
Sink the BuiltinInfo object from ASTContext into the
preprocessor and initialize it early in clang-cc.  This
ensures that __has_builtin works in all modes, not just
when ASTContext is around.


Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/Basic/Builtins.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Basic/Builtins.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Preprocessor/feature_tests.c
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jun 13 20:54:56 2009
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
 #define LLVM_CLANG_AST_ASTCONTEXT_H
 
-#include "clang/Basic/Builtins.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/AST/Attr.h"
@@ -55,6 +54,8 @@
   class ObjCIvarRefExpr;
   class ObjCIvarDecl;
   
+  namespace Builtin { class Context; }
+  
 /// ASTContext - This class holds long-lived AST nodes (such as types and
 /// decls) that can be referred to throughout the semantic analysis of a file.
 class ASTContext {  
@@ -141,6 +142,7 @@
   TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
+  Builtin::Context &BuiltinInfo;
   DeclarationNameTable DeclarationNames;
   llvm::OwningPtr<ExternalASTSource> ExternalSource;
   clang::PrintingPolicy PrintingPolicy;
@@ -163,7 +165,6 @@
 
   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
 
-  Builtin::Context BuiltinInfo;
 
   // Builtin Types.
   QualType VoidTy;
@@ -180,21 +181,12 @@
   QualType DependentTy;
 
   ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
-             IdentifierTable &idents, SelectorTable &sels, 
-             bool FreeMemory = true, unsigned size_reserve=0,
-             bool InitializeBuiltins = true);
+             IdentifierTable &idents, SelectorTable &sels,
+             Builtin::Context &builtins,
+             bool FreeMemory = true, unsigned size_reserve=0);
 
   ~ASTContext();
 
-  /// \brief Initialize builtins.
-  ///
-  /// Typically, this routine will be called automatically by the
-  /// constructor. However, in certain cases (e.g., when there is a
-  /// PCH file to be loaded), the constructor does not perform
-  /// initialization for builtins. This routine can be called to
-  /// perform the initialization.
-  void InitializeBuiltins(IdentifierTable &idents);
-
   /// \brief Attach an external AST source to the AST context.
   ///
   /// The external AST source provides the ability to load parts of

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Sat Jun 13 20:54:56 2009
@@ -55,14 +55,11 @@
 public:
   Context() : TSRecords(0), NumTSRecords(0) {}
 
-  /// \brief Load all of the target builtins. This should be called
-  /// prior to initializing the builtin identifiers.
-  void InitializeTargetBuiltins(const TargetInfo &Target);
-
   /// InitializeBuiltins - Mark the identifiers for all the builtins with their
   /// appropriate builtin ID # and mark any non-portable builtin identifiers as
   /// such.
-  void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false);
+  void InitializeBuiltins(IdentifierTable &Table, const TargetInfo &Target,
+                          bool NoBuiltins = false);
 
   /// \brief Popular the vector with the names of all of the builtins.
   void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Jun 13 20:54:56 2009
@@ -19,6 +19,7 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/TokenLexer.h"
 #include "clang/Lex/PTHManager.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
@@ -101,6 +102,9 @@
   /// the lifetime fo the preprocessor.
   SelectorTable Selectors;
 
+  /// BuiltinInfo - Information about builtins.
+  Builtin::Context BuiltinInfo;
+  
   /// PragmaHandlers - This tracks all of the pragmas that the client registered
   /// with this preprocessor.
   PragmaNamespace *PragmaHandlers;
@@ -211,6 +215,7 @@
 
   IdentifierTable &getIdentifierTable() { return Identifiers; }
   SelectorTable &getSelectorTable() { return Selectors; }
+  Builtin::Context &getBuiltinInfo() { return BuiltinInfo; }
   llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
     
   void setPTHManager(PTHManager* pm);

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Jun 13 20:54:56 2009
@@ -18,6 +18,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/RecordLayout.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
@@ -32,18 +33,15 @@
 ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
                        TargetInfo &t,
                        IdentifierTable &idents, SelectorTable &sels,
-                       bool FreeMem, unsigned size_reserve,
-                       bool InitializeBuiltins) : 
+                       Builtin::Context &builtins,
+                       bool FreeMem, unsigned size_reserve) : 
   GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 
   ObjCFastEnumerationStateTypeDecl(0), SourceMgr(SM), LangOpts(LOpts), 
   FreeMemory(FreeMem), Target(t), Idents(idents), Selectors(sels),
-  ExternalSource(0) {  
+  BuiltinInfo(builtins), ExternalSource(0) {  
   if (size_reserve > 0) Types.reserve(size_reserve);    
   InitBuiltinTypes();
   TUDecl = TranslationUnitDecl::Create(*this);
-  BuiltinInfo.InitializeTargetBuiltins(Target);
-  if (InitializeBuiltins)
-    this->InitializeBuiltins(idents);
   PrintingPolicy.CPlusPlus = LangOpts.CPlusPlus;
 }
 
@@ -86,10 +84,6 @@
   TUDecl->Destroy(*this);
 }
 
-void ASTContext::InitializeBuiltins(IdentifierTable &idents) {
-  BuiltinInfo.InitializeBuiltins(idents, LangOpts.NoBuiltin);
-}
-
 void 
 ASTContext::setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source) {
   ExternalSource.reset(Source.take());
@@ -1979,9 +1973,8 @@
   // There are two things which impact the integer rank: the width, and
   // the ordering of builtins.  The builtin ordering is encoded in the
   // bottom three bits; the width is encoded in the bits above that.
-  if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) {
+  if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T))
     return FWIT->getWidth() << 3;
-  }
 
   switch (cast<BuiltinType>(T)->getKind()) {
   default: assert(0 && "getIntegerRank(): not a built-in integer");

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Jun 13 20:54:56 2009
@@ -19,6 +19,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/IdentifierTable.h"
 #include <vector>
 

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Jun 13 20:54:56 2009
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/TargetInfo.h"
 #include <algorithm>
 using namespace clang;

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Jun 13 20:54:56 2009
@@ -16,6 +16,7 @@
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/ASTDiagnostic.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Compiler.h"

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Sat Jun 13 20:54:56 2009
@@ -18,6 +18,7 @@
 #include "clang/Analysis/PathSensitive/BugReporter.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/PrettyStackTrace.h"

Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Sat Jun 13 20:54:56 2009
@@ -30,22 +30,20 @@
   return TSRecords[ID - Builtin::FirstTSBuiltin];
 }
 
-/// \brief Load all of the target builtins. This must be called
-/// prior to initializing the builtin identifiers.
-void Builtin::Context::InitializeTargetBuiltins(const TargetInfo &Target) {
-  Target.getTargetBuiltins(TSRecords, NumTSRecords);
-}
-
 /// InitializeBuiltins - Mark the identifiers for all the builtins with their
 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
 /// such.
 void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
+                                          const TargetInfo &Target,
                                           bool NoBuiltins) {
   // Step #1: mark all target-independent builtins with their ID's.
   for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
     if (!BuiltinInfo[i].Suppressed &&
         (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
       Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
+
+  // Get the target specific builtins from the target.
+  Target.getTargetBuiltins(TSRecords, NumTSRecords);
   
   // Step #2: Register target-specific builtins.
   for (unsigned i = 0, e = NumTSRecords; i != e; ++i)

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Jun 13 20:54:56 2009
@@ -17,6 +17,7 @@
 #include "clang/AST/APValue.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/Builtins.h"
 #include "llvm/Constants.h"
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Jun 13 20:54:56 2009
@@ -21,6 +21,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sat Jun 13 20:54:56 2009
@@ -20,6 +20,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/Parse/DeclSpec.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"

Modified: cfe/trunk/test/Preprocessor/feature_tests.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/feature_tests.c?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/feature_tests.c (original)
+++ cfe/trunk/test/Preprocessor/feature_tests.c Sat Jun 13 20:54:56 2009
@@ -1,4 +1,5 @@
-// RUN: clang-cc %s --triple=i686-apple-darwin9
+// RUN: clang-cc %s --triple=i686-apple-darwin9 &&
+// RUN: clang-cc %s -E --triple=i686-apple-darwin9
 #ifndef __has_feature
 #error Should have __has_feature
 #endif

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=73319&r1=73318&r2=73319&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sat Jun 13 20:54:56 2009
@@ -2002,9 +2002,10 @@
                                       PP.getTargetInfo(),
                                       PP.getIdentifierTable(),
                                       PP.getSelectorTable(),
+                                      PP.getBuiltinInfo(),
                                       /* FreeMemory = */ !DisableFree,
-                                      /* size_reserve = */0,
-                       /* InitializeBuiltins = */ImplicitIncludePCH.empty()));
+                                      /* size_reserve = */0));
+   
   llvm::OwningPtr<PCHReader> Reader;
   llvm::OwningPtr<ExternalASTSource> Source;
     
@@ -2298,9 +2299,15 @@
                               PhonyDependencyTarget);
     }
 
-    if (ImplicitIncludePCH.empty() && 
-        InitializeSourceManager(*PP.get(), InFile))
-      continue;
+    if (ImplicitIncludePCH.empty()) {
+      if (InitializeSourceManager(*PP.get(), InFile))
+        continue;
+    
+      // Initialize builtin info.
+      PP->getBuiltinInfo().InitializeBuiltins(PP->getIdentifierTable(),
+                                              PP->getTargetInfo(),
+                                              PP->getLangOptions().NoBuiltin);
+    }
 
     if (!HTMLDiag.empty())
       ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get());





More information about the cfe-commits mailing list