forked from OSchip/llvm-project
Don't record nested macro expansions in the preprocessing record,
it can only bring pain when dealing with preprocessor abuse (see: boost). rdar://10898986 llvm-svn: 151427
This commit is contained in:
parent
ef31f376bb
commit
335c5a42e9
|
@ -993,28 +993,7 @@ enum CXTranslationUnit_Flags {
|
|||
* Note: this is a *temporary* option that is available only while
|
||||
* we are testing C++ precompiled preamble support. It is deprecated.
|
||||
*/
|
||||
CXTranslationUnit_CXXChainedPCH = 0x20,
|
||||
|
||||
/**
|
||||
* \brief Used to indicate that the "detailed" preprocessing record,
|
||||
* if requested, should also contain nested macro expansions.
|
||||
*
|
||||
* Nested macro expansions (i.e., macro expansions that occur
|
||||
* inside another macro expansion) can, in some code bases, require
|
||||
* a large amount of storage to due preprocessor metaprogramming. Moreover,
|
||||
* its fairly rare that this information is useful for libclang clients.
|
||||
*/
|
||||
CXTranslationUnit_NestedMacroExpansions = 0x40,
|
||||
|
||||
/**
|
||||
* \brief Legacy name to indicate that the "detailed" preprocessing record,
|
||||
* if requested, should contain nested macro expansions.
|
||||
*
|
||||
* \see CXTranslationUnit_NestedMacroExpansions for the current name for this
|
||||
* value, and its semantics. This is just an alias.
|
||||
*/
|
||||
CXTranslationUnit_NestedMacroInstantiations =
|
||||
CXTranslationUnit_NestedMacroExpansions
|
||||
CXTranslationUnit_CXXChainedPCH = 0x20
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -258,10 +258,6 @@ private:
|
|||
|
||||
/// \brief Whether we should be caching code-completion results.
|
||||
bool ShouldCacheCodeCompletionResults;
|
||||
|
||||
/// \brief Whether we want to include nested macro expansions in the
|
||||
/// detailed preprocessing record.
|
||||
bool NestedMacroExpansions;
|
||||
|
||||
/// \brief The language options used when we load an AST file.
|
||||
LangOptions ASTFileLangOpts;
|
||||
|
@ -707,8 +703,7 @@ public:
|
|||
bool CaptureDiagnostics = false,
|
||||
bool PrecompilePreamble = false,
|
||||
TranslationUnitKind TUKind = TU_Complete,
|
||||
bool CacheCodeCompletionResults = false,
|
||||
bool NestedMacroExpansions = true);
|
||||
bool CacheCodeCompletionResults = false);
|
||||
|
||||
/// LoadFromCommandLine - Create an ASTUnit from a vector of command line
|
||||
/// arguments, which must specify exactly one source file.
|
||||
|
@ -735,8 +730,7 @@ public:
|
|||
bool RemappedFilesKeepOriginalName = true,
|
||||
bool PrecompilePreamble = false,
|
||||
TranslationUnitKind TUKind = TU_Complete,
|
||||
bool CacheCodeCompletionResults = false,
|
||||
bool NestedMacroExpansions = true);
|
||||
bool CacheCodeCompletionResults = false);
|
||||
|
||||
/// \brief Reparse the source files using the same command-line options that
|
||||
/// were originally used to produce this translation unit.
|
||||
|
|
|
@ -50,10 +50,6 @@ public:
|
|||
/// record of all macro definitions and
|
||||
/// expansions.
|
||||
|
||||
/// \brief Whether the detailed preprocessing record includes nested macro
|
||||
/// expansions.
|
||||
unsigned DetailedRecordIncludesNestedMacroExpansions : 1;
|
||||
|
||||
/// The implicit PCH included at the start of the translation unit, or empty.
|
||||
std::string ImplicitPCHInclude;
|
||||
|
||||
|
@ -162,7 +158,6 @@ public:
|
|||
|
||||
public:
|
||||
PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
|
||||
DetailedRecordIncludesNestedMacroExpansions(false),
|
||||
DisablePCHValidation(false), DisableStatCache(false),
|
||||
DumpDeserializedPCHDecls(false),
|
||||
PrecompiledPreambleBytes(0, true),
|
||||
|
|
|
@ -284,10 +284,6 @@ namespace clang {
|
|||
/// expanded, etc.
|
||||
class PreprocessingRecord : public PPCallbacks {
|
||||
SourceManager &SourceMgr;
|
||||
|
||||
/// \brief Whether we should include nested macro expansions in
|
||||
/// the preprocessing record.
|
||||
bool IncludeNestedMacroExpansions;
|
||||
|
||||
/// \brief Allocator used to store preprocessing objects.
|
||||
llvm::BumpPtrAllocator BumpAlloc;
|
||||
|
@ -353,7 +349,7 @@ namespace clang {
|
|||
|
||||
public:
|
||||
/// \brief Construct a new preprocessing record.
|
||||
PreprocessingRecord(SourceManager &SM, bool IncludeNestedMacroExpansions);
|
||||
explicit PreprocessingRecord(SourceManager &SM);
|
||||
|
||||
/// \brief Allocate memory in the preprocessing record.
|
||||
void *Allocate(unsigned Size, unsigned Align = 8) {
|
||||
|
|
|
@ -512,7 +512,7 @@ public:
|
|||
|
||||
/// \brief Create a new preprocessing record, which will keep track of
|
||||
/// all macro expansions, macro definitions, etc.
|
||||
void createPreprocessingRecord(bool IncludeNestedMacroExpansions);
|
||||
void createPreprocessingRecord();
|
||||
|
||||
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
|
||||
/// which implicitly adds the builtin defines etc.
|
||||
|
|
|
@ -220,7 +220,6 @@ ASTUnit::ASTUnit(bool _MainFileIsAST)
|
|||
PreambleRebuildCounter(0), SavedMainFileBuffer(0), PreambleBuffer(0),
|
||||
NumWarningsInPreamble(0),
|
||||
ShouldCacheCodeCompletionResults(false),
|
||||
NestedMacroExpansions(true),
|
||||
CompletionCacheTopLevelHashValue(0),
|
||||
PreambleTopLevelHashValue(0),
|
||||
CurrentTopLevelHashValue(0),
|
||||
|
@ -1093,8 +1092,6 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
|
|||
// If the main file has been overridden due to the use of a preamble,
|
||||
// make that override happen and introduce the preamble.
|
||||
PreprocessorOptions &PreprocessorOpts = Clang->getPreprocessorOpts();
|
||||
PreprocessorOpts.DetailedRecordIncludesNestedMacroExpansions
|
||||
= NestedMacroExpansions;
|
||||
if (OverrideMainBuffer) {
|
||||
PreprocessorOpts.addRemappedFile(OriginalSourceFile, OverrideMainBuffer);
|
||||
PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size();
|
||||
|
@ -1832,8 +1829,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
|
|||
bool CaptureDiagnostics,
|
||||
bool PrecompilePreamble,
|
||||
TranslationUnitKind TUKind,
|
||||
bool CacheCodeCompletionResults,
|
||||
bool NestedMacroExpansions) {
|
||||
bool CacheCodeCompletionResults) {
|
||||
// Create the AST unit.
|
||||
OwningPtr<ASTUnit> AST;
|
||||
AST.reset(new ASTUnit(false));
|
||||
|
@ -1844,7 +1840,6 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
|
|||
AST->TUKind = TUKind;
|
||||
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
|
||||
AST->Invocation = CI;
|
||||
AST->NestedMacroExpansions = NestedMacroExpansions;
|
||||
|
||||
// Recover resources if we crash before exiting this method.
|
||||
llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
|
||||
|
@ -1867,8 +1862,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
|
|||
bool RemappedFilesKeepOriginalName,
|
||||
bool PrecompilePreamble,
|
||||
TranslationUnitKind TUKind,
|
||||
bool CacheCodeCompletionResults,
|
||||
bool NestedMacroExpansions) {
|
||||
bool CacheCodeCompletionResults) {
|
||||
if (!Diags.getPtr()) {
|
||||
// No diagnostics engine was provided, so create our own diagnostics object
|
||||
// with the default options.
|
||||
|
@ -1926,7 +1920,6 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
|
|||
AST->StoredDiagnostics.swap(StoredDiagnostics);
|
||||
AST->Invocation = CI;
|
||||
CI = 0; // Zero out now to ease cleanup during crash recovery.
|
||||
AST->NestedMacroExpansions = NestedMacroExpansions;
|
||||
|
||||
// Recover resources if we crash before exiting this method.
|
||||
llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
|
||||
|
|
|
@ -257,8 +257,7 @@ void CompilerInstance::createPreprocessor() {
|
|||
}
|
||||
|
||||
if (PPOpts.DetailedRecord)
|
||||
PP->createPreprocessingRecord(
|
||||
PPOpts.DetailedRecordIncludesNestedMacroExpansions);
|
||||
PP->createPreprocessingRecord();
|
||||
|
||||
InitializePreprocessor(*PP, PPOpts, getHeaderSearchOpts(), getFrontendOpts());
|
||||
|
||||
|
|
|
@ -37,10 +37,8 @@ InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
|
|||
this->FileName = StringRef(Memory, FileName.size());
|
||||
}
|
||||
|
||||
PreprocessingRecord::PreprocessingRecord(SourceManager &SM,
|
||||
bool IncludeNestedMacroExpansions)
|
||||
: SourceMgr(SM), IncludeNestedMacroExpansions(IncludeNestedMacroExpansions),
|
||||
ExternalSource(0)
|
||||
PreprocessingRecord::PreprocessingRecord(SourceManager &SM)
|
||||
: SourceMgr(SM), ExternalSource(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -331,7 +329,8 @@ MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) {
|
|||
|
||||
void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI,
|
||||
SourceRange Range) {
|
||||
if (!IncludeNestedMacroExpansions && Id.getLocation().isMacroID())
|
||||
// We don't record nested macro expansions.
|
||||
if (Id.getLocation().isMacroID())
|
||||
return;
|
||||
|
||||
if (MI->isBuiltinMacro())
|
||||
|
|
|
@ -654,12 +654,10 @@ CommentHandler::~CommentHandler() { }
|
|||
|
||||
CodeCompletionHandler::~CodeCompletionHandler() { }
|
||||
|
||||
void Preprocessor::createPreprocessingRecord(
|
||||
bool IncludeNestedMacroExpansions) {
|
||||
void Preprocessor::createPreprocessingRecord() {
|
||||
if (Record)
|
||||
return;
|
||||
|
||||
Record = new PreprocessingRecord(getSourceManager(),
|
||||
IncludeNestedMacroExpansions);
|
||||
Record = new PreprocessingRecord(getSourceManager());
|
||||
addPPCallbacks(Record);
|
||||
}
|
||||
|
|
|
@ -1744,7 +1744,7 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
|
|||
= F.PreprocessorDetailCursor.GetCurrentBitNo();
|
||||
|
||||
if (!PP.getPreprocessingRecord())
|
||||
PP.createPreprocessingRecord(true);
|
||||
PP.createPreprocessingRecord();
|
||||
if (!PP.getPreprocessingRecord()->getExternalSource())
|
||||
PP.getPreprocessingRecord()->SetExternalSource(*this);
|
||||
break;
|
||||
|
@ -2288,7 +2288,7 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
|
|||
|
||||
unsigned StartingID;
|
||||
if (!PP.getPreprocessingRecord())
|
||||
PP.createPreprocessingRecord(true);
|
||||
PP.createPreprocessingRecord();
|
||||
if (!PP.getPreprocessingRecord()->getExternalSource())
|
||||
PP.getPreprocessingRecord()->SetExternalSource(*this);
|
||||
StartingID
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#define FOO(x) x
|
||||
#define BAR(x) FOO(x)
|
||||
#define WIBBLE(x) BAR(x)
|
||||
|
||||
WIBBLE(int x);
|
||||
|
||||
// RUN: env CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s
|
||||
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s
|
||||
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s
|
||||
// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:14]
|
||||
// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14]
|
||||
// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro expansion=FOO:1:9 Extent=[2:16 - 5:14]
|
||||
// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14]
|
||||
|
||||
// RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s
|
||||
// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s
|
||||
// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s
|
||||
// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:14]
|
||||
// CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14]
|
||||
// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14]
|
|
@ -37,8 +37,6 @@ static unsigned getDefaultParsingOptions() {
|
|||
options |= clang_defaultEditingTranslationUnitOptions();
|
||||
if (getenv("CINDEXTEST_COMPLETION_CACHING"))
|
||||
options |= CXTranslationUnit_CacheCompletionResults;
|
||||
if (getenv("CINDEXTEST_NESTED_MACROS"))
|
||||
options |= CXTranslationUnit_NestedMacroExpansions;
|
||||
if (getenv("CINDEXTEST_COMPLETION_NO_CACHING"))
|
||||
options &= ~CXTranslationUnit_CacheCompletionResults;
|
||||
|
||||
|
|
|
@ -2454,8 +2454,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
|
|||
const char * const *command_line_args,
|
||||
unsigned num_unsaved_files,
|
||||
struct CXUnsavedFile *unsaved_files) {
|
||||
unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord |
|
||||
CXTranslationUnit_NestedMacroExpansions;
|
||||
unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord;
|
||||
return clang_parseTranslationUnit(CIdx, source_filename,
|
||||
command_line_args, num_command_line_args,
|
||||
unsaved_files, num_unsaved_files,
|
||||
|
@ -2557,12 +2556,9 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
|
|||
Args->push_back(source_filename);
|
||||
|
||||
// Do we need the detailed preprocessing record?
|
||||
bool NestedMacroExpansions = false;
|
||||
if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
|
||||
Args->push_back("-Xclang");
|
||||
Args->push_back("-detailed-preprocessing-record");
|
||||
NestedMacroExpansions
|
||||
= (options & CXTranslationUnit_NestedMacroExpansions);
|
||||
}
|
||||
|
||||
unsigned NumErrors = Diags->getClient()->getNumErrors();
|
||||
|
@ -2579,8 +2575,7 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
|
|||
/*RemappedFilesKeepOriginalName=*/true,
|
||||
PrecompilePreamble,
|
||||
TUKind,
|
||||
CacheCodeCompetionResults,
|
||||
NestedMacroExpansions));
|
||||
CacheCodeCompetionResults));
|
||||
|
||||
if (NumErrors != Diags->getClient()->getNumErrors()) {
|
||||
// Make sure to check that 'Unit' is non-NULL.
|
||||
|
|
|
@ -369,7 +369,6 @@ static void clang_indexSourceFile_Impl(void *UserData) {
|
|||
bool CacheCodeCompletionResults = false;
|
||||
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
|
||||
PPOpts.DetailedRecord = false;
|
||||
PPOpts.DetailedRecordIncludesNestedMacroExpansions = false;
|
||||
|
||||
if (requestedToGetTU) {
|
||||
OnlyLocalDecls = CXXIdx->getOnlyLocalDecls();
|
||||
|
@ -379,8 +378,6 @@ static void clang_indexSourceFile_Impl(void *UserData) {
|
|||
= TU_options & CXTranslationUnit_CacheCompletionResults;
|
||||
if (TU_options & CXTranslationUnit_DetailedPreprocessingRecord) {
|
||||
PPOpts.DetailedRecord = true;
|
||||
PPOpts.DetailedRecordIncludesNestedMacroExpansions
|
||||
= (TU_options & CXTranslationUnit_NestedMacroExpansions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue