]> granicus.if.org Git - clang/commitdiff
Sink the BuiltinInfo object from ASTContext into the
authorChris Lattner <sabre@nondot.org>
Sun, 14 Jun 2009 01:54:56 +0000 (01:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Jun 2009 01:54:56 +0000 (01:54 +0000)
preprocessor and initialize it early in clang-cc.  This
ensures that __has_builtin works in all modes, not just
when ASTContext is around.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73319 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
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

index a41347219c31acee68a88671c7d58532a4cc0c5e..f4313f4dbffff3c9d5d6494a79e4105fc2872e32 100644 (file)
@@ -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 @@ namespace clang {
   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 @@ public:
   TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
+  Builtin::Context &BuiltinInfo;
   DeclarationNameTable DeclarationNames;
   llvm::OwningPtr<ExternalASTSource> ExternalSource;
   clang::PrintingPolicy PrintingPolicy;
@@ -163,7 +165,6 @@ public:
 
   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
 
-  Builtin::Context BuiltinInfo;
 
   // Builtin Types.
   QualType VoidTy;
@@ -180,21 +181,12 @@ public:
   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
index a18faf688ffe6cbce3e392257884d6c20c0bdbd1..6463a4f6e51bc901723ea4076eaad8a405533409 100644 (file)
@@ -55,14 +55,11 @@ class Context {
 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,
index 4831b9bb25bd99e891b995883879774d77a6a61c..f229881bfc44a7e67361d1fc5693f811a8e5a510 100644 (file)
@@ -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 @@ class Preprocessor {
   /// 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 @@ public:
 
   IdentifierTable &getIdentifierTable() { return Identifiers; }
   SelectorTable &getSelectorTable() { return Selectors; }
+  Builtin::Context &getBuiltinInfo() { return BuiltinInfo; }
   llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
     
   void setPTHManager(PTHManager* pm);
index 4891fd3f73387eba2fe218a4105e0f856aa73acf..7ed9e45fcee906505d87bbbd234c7c7b98ea3d9e 100644 (file)
@@ -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 @@ enum FloatingRank {
 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 @@ ASTContext::~ASTContext() {
   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 @@ unsigned ASTContext::getIntegerRank(Type *T) {
   // 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");
index dfec1061c25a4f1ea25e4d02fb21cb1a66451137..a3e406b2452e204e627c12d01578386809a6bf1e 100644 (file)
@@ -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>
 
index c12dd6747c6d2fafd62fa0315a5135e7a34e8228..309be4175ffaa30d3ccb6ed41118e5bbebe40a8c 100644 (file)
@@ -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;
index 8e3c3ce2d309e15bcfe22a7bef619a88b0f81165..ff00bc24b391658e1d1b918b794e4e9d0c085162 100644 (file)
@@ -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"
index e8c5be51d6ac3e24e78cbf3a5f7512014cd51a3c..7a8fef58bb2152c225f3a1a219137f2a1dc90e30 100644 (file)
@@ -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"
index 7f9122642457a1821429fbb35febcbf875a91f92..ebe0514fa0084d2ba6a0302d8dfe369ecaab6530 100644 (file)
@@ -30,22 +30,20 @@ const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const {
   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)
index b30bafb51051c34504158852beea4c501c20e08a..0e21a00f30fe2c0d05c0c50dc30c0355c7c861fe 100644 (file)
@@ -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"
index 16d0ec95825867dabe23771e2f455611911cd871..82156e9ffa5c1bf4e890c6764cb1c045224da894 100644 (file)
@@ -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"
index 6212449744ca369dd859efafb88bf8dc9cacc3ed..1d26845fd8e41a5c9fd96cf8fc137b9d0d6bfa8f 100644 (file)
@@ -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"
index edca17819222253183d841dbda38d2737dfd8650..9a29ab96c93e58c0a32793f07de3e0b475e1ab5c 100644 (file)
@@ -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
index c58340c3eee7ed38407709e71fbd9cf8d5b0bc51..840f0157cf9800aa8de70e2b85594a68a4f70c61 100644 (file)
@@ -2002,9 +2002,10 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
                                       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 @@ int main(int argc, char **argv) {
                               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());