Index: include/clang/Sema/CodeCompleteOptions.h =================================================================== --- include/clang/Sema/CodeCompleteOptions.h +++ include/clang/Sema/CodeCompleteOptions.h @@ -36,7 +36,8 @@ unsigned IncludeBriefComments : 1; /// Hint whether to load data from the external AST to provide full results. - /// If false, namespace-level declarations from the preamble may be omitted. + /// If false, namespace-level declarations and macros from the preamble may be + /// omitted. unsigned LoadExternal : 1; /// Include results after corrections (small fix-its), e.g. change '.' to '->' Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -3302,14 +3302,14 @@ } static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results, - bool IncludeUndefined, + bool LoadExternal, bool IncludeUndefined, bool TargetTypeIsPointer = false) { typedef CodeCompletionResult Result; Results.EnterNewScope(); - for (Preprocessor::macro_iterator M = PP.macro_begin(), - MEnd = PP.macro_end(); + for (Preprocessor::macro_iterator M = PP.macro_begin(LoadExternal), + MEnd = PP.macro_end(LoadExternal); M != MEnd; ++M) { auto MD = PP.getMacroDefinition(M->first); if (IncludeUndefined || MD) { @@ -3325,7 +3325,6 @@ } Results.ExitScope(); - } static void AddPrettyFunctionResults(const LangOptions &LangOpts, @@ -3609,7 +3608,7 @@ } if (CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, false); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); @@ -3747,7 +3746,8 @@ AddPrettyFunctionResults(getLangOpts(), Results); if (CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, false, PreferredTypeIsPointer); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false, + PreferredTypeIsPointer); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -4370,7 +4370,7 @@ Results.ExitScope(); if (CodeCompleter->includeMacros()) { - AddMacroResults(PP, Results, false); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); } HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); @@ -4686,7 +4686,7 @@ AddPrettyFunctionResults(getLangOpts(), Results); if (CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, false); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); @@ -5720,7 +5720,7 @@ CodeCompleter->loadExternal()); if (CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, false); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); @@ -5949,10 +5949,9 @@ Results.ExitScope(); if (CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, false); + AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); - } void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, @@ -7965,7 +7964,9 @@ CodeCompletionContext::CCC_PreprocessorExpression); if (!CodeCompleter || CodeCompleter->includeMacros()) - AddMacroResults(PP, Results, true); + AddMacroResults(PP, Results, + CodeCompleter ? CodeCompleter->loadExternal() : false, + true); // defined () Results.EnterNewScope(); @@ -8030,7 +8031,9 @@ } if (!CodeCompleter || CodeCompleter->includeMacros()) - AddMacroResults(PP, Builder, true); + AddMacroResults(PP, Builder, + CodeCompleter ? CodeCompleter->loadExternal() : false, + true); Results.clear(); Results.insert(Results.end(),