aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-14 01:54:56 +0000
committerChris Lattner <sabre@nondot.org>2009-06-14 01:54:56 +0000
commit1b63e4f732dbc73d90abf886b4d21f8e3a165f6d (patch)
treeceacec3ea792cf65e407e1c2988ef31a9d1bc359
parent6b15cdc1312f8fc45c86ee75e2a85106700e97f6 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73319 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ASTContext.h20
-rw-r--r--include/clang/Basic/Builtins.h7
-rw-r--r--include/clang/Lex/Preprocessor.h5
-rw-r--r--lib/AST/ASTContext.cpp17
-rw-r--r--lib/AST/Decl.cpp1
-rw-r--r--lib/AST/Expr.cpp1
-rw-r--r--lib/AST/ExprConstant.cpp1
-rw-r--r--lib/Analysis/GRExprEngine.cpp1
-rw-r--r--lib/Basic/Builtins.cpp10
-rw-r--r--lib/CodeGen/CGExprConstant.cpp1
-rw-r--r--lib/CodeGen/CodeGenModule.cpp1
-rw-r--r--lib/Sema/SemaLookup.cpp1
-rw-r--r--test/Preprocessor/feature_tests.c3
-rw-r--r--tools/clang-cc/clang-cc.cpp17
14 files changed, 43 insertions, 43 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index a41347219c..f4313f4dbf 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -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
diff --git a/include/clang/Basic/Builtins.h b/include/clang/Basic/Builtins.h
index a18faf688f..6463a4f6e5 100644
--- a/include/clang/Basic/Builtins.h
+++ b/include/clang/Basic/Builtins.h
@@ -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,
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 4831b9bb25..f229881bfc 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -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);
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 4891fd3f73..7ed9e45fce 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -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");
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index dfec1061c2..a3e406b245 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -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>
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index c12dd6747c..309be4175f 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -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;
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 8e3c3ce2d3..ff00bc24b3 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -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"
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index e8c5be51d6..7a8fef58bb 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -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"
diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp
index 7f91226424..ebe0514fa0 100644
--- a/lib/Basic/Builtins.cpp
+++ b/lib/Basic/Builtins.cpp
@@ -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)
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index b30bafb510..0e21a00f30 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -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"
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 16d0ec9582..82156e9ffa 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -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"
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 6212449744..1d26845fd8 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -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"
diff --git a/test/Preprocessor/feature_tests.c b/test/Preprocessor/feature_tests.c
index edca178192..9a29ab96c9 100644
--- a/test/Preprocessor/feature_tests.c
+++ b/test/Preprocessor/feature_tests.c
@@ -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
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index c58340c3ee..840f0157cf 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -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());