Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 1b63e4f

Browse files
committed
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
1 parent 6b15cdc commit 1b63e4f

File tree

14 files changed

+43
-43
lines changed

14 files changed

+43
-43
lines changed

include/clang/AST/ASTContext.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
1515
#define LLVM_CLANG_AST_ASTCONTEXT_H
1616

17-
#include "clang/Basic/Builtins.h"
1817
#include "clang/Basic/IdentifierTable.h"
1918
#include "clang/Basic/LangOptions.h"
2019
#include "clang/AST/Attr.h"
@@ -55,6 +54,8 @@ namespace clang {
5554
class ObjCIvarRefExpr;
5655
class ObjCIvarDecl;
5756

57+
namespace Builtin { class Context; }
58+
5859
/// ASTContext - This class holds long-lived AST nodes (such as types and
5960
/// decls) that can be referred to throughout the semantic analysis of a file.
6061
class ASTContext {
@@ -141,6 +142,7 @@ class ASTContext {
141142
TargetInfo &Target;
142143
IdentifierTable &Idents;
143144
SelectorTable &Selectors;
145+
Builtin::Context &BuiltinInfo;
144146
DeclarationNameTable DeclarationNames;
145147
llvm::OwningPtr<ExternalASTSource> ExternalSource;
146148
clang::PrintingPolicy PrintingPolicy;
@@ -163,7 +165,6 @@ class ASTContext {
163165

164166
TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
165167

166-
Builtin::Context BuiltinInfo;
167168

168169
// Builtin Types.
169170
QualType VoidTy;
@@ -180,21 +181,12 @@ class ASTContext {
180181
QualType DependentTy;
181182

182183
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
183-
IdentifierTable &idents, SelectorTable &sels,
184-
bool FreeMemory = true, unsigned size_reserve=0,
185-
bool InitializeBuiltins = true);
184+
IdentifierTable &idents, SelectorTable &sels,
185+
Builtin::Context &builtins,
186+
bool FreeMemory = true, unsigned size_reserve=0);
186187

187188
~ASTContext();
188189

189-
/// \brief Initialize builtins.
190-
///
191-
/// Typically, this routine will be called automatically by the
192-
/// constructor. However, in certain cases (e.g., when there is a
193-
/// PCH file to be loaded), the constructor does not perform
194-
/// initialization for builtins. This routine can be called to
195-
/// perform the initialization.
196-
void InitializeBuiltins(IdentifierTable &idents);
197-
198190
/// \brief Attach an external AST source to the AST context.
199191
///
200192
/// The external AST source provides the ability to load parts of

include/clang/Basic/Builtins.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ class Context {
5555
public:
5656
Context() : TSRecords(0), NumTSRecords(0) {}
5757

58-
/// \brief Load all of the target builtins. This should be called
59-
/// prior to initializing the builtin identifiers.
60-
void InitializeTargetBuiltins(const TargetInfo &Target);
61-
6258
/// InitializeBuiltins - Mark the identifiers for all the builtins with their
6359
/// appropriate builtin ID # and mark any non-portable builtin identifiers as
6460
/// such.
65-
void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false);
61+
void InitializeBuiltins(IdentifierTable &Table, const TargetInfo &Target,
62+
bool NoBuiltins = false);
6663

6764
/// \brief Popular the vector with the names of all of the builtins.
6865
void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,

include/clang/Lex/Preprocessor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/Lex/PPCallbacks.h"
2020
#include "clang/Lex/TokenLexer.h"
2121
#include "clang/Lex/PTHManager.h"
22+
#include "clang/Basic/Builtins.h"
2223
#include "clang/Basic/Diagnostic.h"
2324
#include "clang/Basic/IdentifierTable.h"
2425
#include "clang/Basic/SourceLocation.h"
@@ -101,6 +102,9 @@ class Preprocessor {
101102
/// the lifetime fo the preprocessor.
102103
SelectorTable Selectors;
103104

105+
/// BuiltinInfo - Information about builtins.
106+
Builtin::Context BuiltinInfo;
107+
104108
/// PragmaHandlers - This tracks all of the pragmas that the client registered
105109
/// with this preprocessor.
106110
PragmaNamespace *PragmaHandlers;
@@ -211,6 +215,7 @@ class Preprocessor {
211215

212216
IdentifierTable &getIdentifierTable() { return Identifiers; }
213217
SelectorTable &getSelectorTable() { return Selectors; }
218+
Builtin::Context &getBuiltinInfo() { return BuiltinInfo; }
214219
llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
215220

216221
void setPTHManager(PTHManager* pm);

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/Expr.h"
1919
#include "clang/AST/ExternalASTSource.h"
2020
#include "clang/AST/RecordLayout.h"
21+
#include "clang/Basic/Builtins.h"
2122
#include "clang/Basic/SourceManager.h"
2223
#include "clang/Basic/TargetInfo.h"
2324
#include "llvm/ADT/StringExtras.h"
@@ -32,18 +33,15 @@ enum FloatingRank {
3233
ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
3334
TargetInfo &t,
3435
IdentifierTable &idents, SelectorTable &sels,
35-
bool FreeMem, unsigned size_reserve,
36-
bool InitializeBuiltins) :
36+
Builtin::Context &builtins,
37+
bool FreeMem, unsigned size_reserve) :
3738
GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0),
3839
ObjCFastEnumerationStateTypeDecl(0), SourceMgr(SM), LangOpts(LOpts),
3940
FreeMemory(FreeMem), Target(t), Idents(idents), Selectors(sels),
40-
ExternalSource(0) {
41+
BuiltinInfo(builtins), ExternalSource(0) {
4142
if (size_reserve > 0) Types.reserve(size_reserve);
4243
InitBuiltinTypes();
4344
TUDecl = TranslationUnitDecl::Create(*this);
44-
BuiltinInfo.InitializeTargetBuiltins(Target);
45-
if (InitializeBuiltins)
46-
this->InitializeBuiltins(idents);
4745
PrintingPolicy.CPlusPlus = LangOpts.CPlusPlus;
4846
}
4947

@@ -86,10 +84,6 @@ ASTContext::~ASTContext() {
8684
TUDecl->Destroy(*this);
8785
}
8886

89-
void ASTContext::InitializeBuiltins(IdentifierTable &idents) {
90-
BuiltinInfo.InitializeBuiltins(idents, LangOpts.NoBuiltin);
91-
}
92-
9387
void
9488
ASTContext::setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source) {
9589
ExternalSource.reset(Source.take());
@@ -1979,9 +1973,8 @@ unsigned ASTContext::getIntegerRank(Type *T) {
19791973
// There are two things which impact the integer rank: the width, and
19801974
// the ordering of builtins. The builtin ordering is encoded in the
19811975
// bottom three bits; the width is encoded in the bits above that.
1982-
if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) {
1976+
if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T))
19831977
return FWIT->getWidth() << 3;
1984-
}
19851978

19861979
switch (cast<BuiltinType>(T)->getKind()) {
19871980
default: assert(0 && "getIntegerRank(): not a built-in integer");

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/Stmt.h"
2020
#include "clang/AST/Expr.h"
2121
#include "clang/AST/PrettyPrinter.h"
22+
#include "clang/Basic/Builtins.h"
2223
#include "clang/Basic/IdentifierTable.h"
2324
#include <vector>
2425

lib/AST/Expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clang/AST/DeclTemplate.h"
2020
#include "clang/AST/RecordLayout.h"
2121
#include "clang/AST/StmtVisitor.h"
22+
#include "clang/Basic/Builtins.h"
2223
#include "clang/Basic/TargetInfo.h"
2324
#include <algorithm>
2425
using namespace clang;

lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/AST/RecordLayout.h"
1717
#include "clang/AST/StmtVisitor.h"
1818
#include "clang/AST/ASTDiagnostic.h"
19+
#include "clang/Basic/Builtins.h"
1920
#include "clang/Basic/TargetInfo.h"
2021
#include "llvm/ADT/SmallString.h"
2122
#include "llvm/Support/Compiler.h"

lib/Analysis/GRExprEngine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Analysis/PathSensitive/BugReporter.h"
1919
#include "clang/AST/ParentMap.h"
2020
#include "clang/AST/StmtObjC.h"
21+
#include "clang/Basic/Builtins.h"
2122
#include "clang/Basic/SourceManager.h"
2223
#include "clang/Basic/SourceManager.h"
2324
#include "clang/Basic/PrettyStackTrace.h"

lib/Basic/Builtins.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@ const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const {
3030
return TSRecords[ID - Builtin::FirstTSBuiltin];
3131
}
3232

33-
/// \brief Load all of the target builtins. This must be called
34-
/// prior to initializing the builtin identifiers.
35-
void Builtin::Context::InitializeTargetBuiltins(const TargetInfo &Target) {
36-
Target.getTargetBuiltins(TSRecords, NumTSRecords);
37-
}
38-
3933
/// InitializeBuiltins - Mark the identifiers for all the builtins with their
4034
/// appropriate builtin ID # and mark any non-portable builtin identifiers as
4135
/// such.
4236
void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
37+
const TargetInfo &Target,
4338
bool NoBuiltins) {
4439
// Step #1: mark all target-independent builtins with their ID's.
4540
for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
4641
if (!BuiltinInfo[i].Suppressed &&
4742
(!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
4843
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
44+
45+
// Get the target specific builtins from the target.
46+
Target.getTargetBuiltins(TSRecords, NumTSRecords);
4947

5048
// Step #2: Register target-specific builtins.
5149
for (unsigned i = 0, e = NumTSRecords; i != e; ++i)

lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/APValue.h"
1818
#include "clang/AST/ASTContext.h"
1919
#include "clang/AST/StmtVisitor.h"
20+
#include "clang/Basic/Builtins.h"
2021
#include "llvm/Constants.h"
2122
#include "llvm/Function.h"
2223
#include "llvm/GlobalVariable.h"

0 commit comments

Comments
 (0)