Don't record nested macro expansions in the preprocessing record,
it can only bring pain when dealing with preprocessor abuse (see: boost).
rdar://10898986
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151427 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 018a316..67a26d9 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -993,28 +993,7 @@
* 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
};
/**
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 3cf14e5..210c7ce 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -258,10 +258,6 @@
/// \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 @@
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 @@
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.
diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h
index b977030..e36669d 100644
--- a/include/clang/Frontend/PreprocessorOptions.h
+++ b/include/clang/Frontend/PreprocessorOptions.h
@@ -50,10 +50,6 @@
/// 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:
PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
- DetailedRecordIncludesNestedMacroExpansions(false),
DisablePCHValidation(false), DisableStatCache(false),
DumpDeserializedPCHDecls(false),
PrecompiledPreambleBytes(0, true),
diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h
index 2947c9e..a778bbe 100644
--- a/include/clang/Lex/PreprocessingRecord.h
+++ b/include/clang/Lex/PreprocessingRecord.h
@@ -284,10 +284,6 @@
/// 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 @@
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) {
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 960bf07..8c3b742 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -512,7 +512,7 @@
/// \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.
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 82255c7..3ffb6ec 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -220,7 +220,6 @@
PreambleRebuildCounter(0), SavedMainFileBuffer(0), PreambleBuffer(0),
NumWarningsInPreamble(0),
ShouldCacheCodeCompletionResults(false),
- NestedMacroExpansions(true),
CompletionCacheTopLevelHashValue(0),
PreambleTopLevelHashValue(0),
CurrentTopLevelHashValue(0),
@@ -1093,8 +1092,6 @@
// 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 @@
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 @@
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 @@
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 @@
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>
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index 8d84277..2ade1c1 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -257,8 +257,7 @@
}
if (PPOpts.DetailedRecord)
- PP->createPreprocessingRecord(
- PPOpts.DetailedRecordIncludesNestedMacroExpansions);
+ PP->createPreprocessingRecord();
InitializePreprocessor(*PP, PPOpts, getHeaderSearchOpts(), getFrontendOpts());
diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp
index 6c36e73..c87088d 100644
--- a/lib/Lex/PreprocessingRecord.cpp
+++ b/lib/Lex/PreprocessingRecord.cpp
@@ -37,10 +37,8 @@
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 @@
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())
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 75ab89d..96dfe36 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -654,12 +654,10 @@
CodeCompletionHandler::~CodeCompletionHandler() { }
-void Preprocessor::createPreprocessingRecord(
- bool IncludeNestedMacroExpansions) {
+void Preprocessor::createPreprocessingRecord() {
if (Record)
return;
- Record = new PreprocessingRecord(getSourceManager(),
- IncludeNestedMacroExpansions);
+ Record = new PreprocessingRecord(getSourceManager());
addPPCallbacks(Record);
}
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index dde54d6..efe70e0 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -1744,7 +1744,7 @@
= F.PreprocessorDetailCursor.GetCurrentBitNo();
if (!PP.getPreprocessingRecord())
- PP.createPreprocessingRecord(true);
+ PP.createPreprocessingRecord();
if (!PP.getPreprocessingRecord()->getExternalSource())
PP.getPreprocessingRecord()->SetExternalSource(*this);
break;
@@ -2288,7 +2288,7 @@
unsigned StartingID;
if (!PP.getPreprocessingRecord())
- PP.createPreprocessingRecord(true);
+ PP.createPreprocessingRecord();
if (!PP.getPreprocessingRecord()->getExternalSource())
PP.getPreprocessingRecord()->SetExternalSource(*this);
StartingID
diff --git a/test/Index/nested-macro-instantiations.cpp b/test/Index/nested-macro-instantiations.cpp
deleted file mode 100644
index 0ed84dd..0000000
--- a/test/Index/nested-macro-instantiations.cpp
+++ /dev/null
@@ -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]
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 548c40e..eee7f46 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -37,8 +37,6 @@
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;
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 53c7634..924a843 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2454,8 +2454,7 @@
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 @@
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 @@
/*RemappedFilesKeepOriginalName=*/true,
PrecompilePreamble,
TUKind,
- CacheCodeCompetionResults,
- NestedMacroExpansions));
+ CacheCodeCompetionResults));
if (NumErrors != Diags->getClient()->getNumErrors()) {
// Make sure to check that 'Unit' is non-NULL.
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 69ddc42..1aed531 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -369,7 +369,6 @@
bool CacheCodeCompletionResults = false;
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
PPOpts.DetailedRecord = false;
- PPOpts.DetailedRecordIncludesNestedMacroExpansions = false;
if (requestedToGetTU) {
OnlyLocalDecls = CXXIdx->getOnlyLocalDecls();
@@ -379,8 +378,6 @@
= TU_options & CXTranslationUnit_CacheCompletionResults;
if (TU_options & CXTranslationUnit_DetailedPreprocessingRecord) {
PPOpts.DetailedRecord = true;
- PPOpts.DetailedRecordIncludesNestedMacroExpansions
- = (TU_options & CXTranslationUnit_NestedMacroExpansions);
}
}