r342528 - [Sema] Do not load macros from preamble when LoadExternal is false.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 19 02:34:56 PDT 2018
Author: ioeric
Date: Wed Sep 19 02:34:55 2018
New Revision: 342528
URL: http://llvm.org/viewvc/llvm-project?rev=342528&view=rev
Log:
[Sema] Do not load macros from preamble when LoadExternal is false.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D52079
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-pch-skip.cpp
Modified: cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteOptions.h?rev=342528&r1=342527&r2=342528&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteOptions.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteOptions.h Wed Sep 19 02:34:55 2018
@@ -36,7 +36,8 @@ public:
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 '->'
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=342528&r1=342527&r2=342528&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Sep 19 02:34:55 2018
@@ -3304,14 +3304,14 @@ CXCursorKind clang::getCursorKindForDecl
}
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) {
@@ -3327,7 +3327,6 @@ static void AddMacroResults(Preprocessor
}
Results.ExitScope();
-
}
static void AddPrettyFunctionResults(const LangOptions &LangOpts,
@@ -3611,7 +3610,7 @@ void Sema::CodeCompleteOrdinaryName(Scop
}
if (CodeCompleter->includeMacros())
- AddMacroResults(PP, Results, false);
+ AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(),Results.size());
@@ -3749,7 +3748,8 @@ void Sema::CodeCompleteExpression(Scope
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());
}
@@ -4372,7 +4372,7 @@ void Sema::CodeCompleteCase(Scope *S) {
Results.ExitScope();
if (CodeCompleter->includeMacros()) {
- AddMacroResults(PP, Results, false);
+ AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
}
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(), Results.size());
@@ -4688,7 +4688,7 @@ void Sema::CodeCompleteAfterIf(Scope *S)
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());
@@ -5722,7 +5722,7 @@ void Sema::CodeCompleteObjCPassingType(S
CodeCompleter->loadExternal());
if (CodeCompleter->includeMacros())
- AddMacroResults(PP, Results, false);
+ AddMacroResults(PP, Results, CodeCompleter->loadExternal(), false);
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(), Results.size());
@@ -5951,10 +5951,9 @@ void Sema::CodeCompleteObjCMessageReceiv
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,
@@ -7967,7 +7966,9 @@ void Sema::CodeCompletePreprocessorExpre
CodeCompletionContext::CCC_PreprocessorExpression);
if (!CodeCompleter || CodeCompleter->includeMacros())
- AddMacroResults(PP, Results, true);
+ AddMacroResults(PP, Results,
+ CodeCompleter ? CodeCompleter->loadExternal() : false,
+ true);
// defined (<macro>)
Results.EnterNewScope();
@@ -8141,7 +8142,9 @@ void Sema::GatherGlobalCodeCompletions(C
}
if (!CodeCompleter || CodeCompleter->includeMacros())
- AddMacroResults(PP, Builder, true);
+ AddMacroResults(PP, Builder,
+ CodeCompleter ? CodeCompleter->loadExternal() : false,
+ true);
Results.clear();
Results.insert(Results.end(),
Modified: cfe/trunk/test/Index/complete-pch-skip.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-pch-skip.cpp?rev=342528&r1=342527&r2=342528&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-pch-skip.cpp (original)
+++ cfe/trunk/test/Index/complete-pch-skip.cpp Wed Sep 19 02:34:55 2018
@@ -4,19 +4,26 @@ int bar;
int main() { return ns:: }
int main2() { return ns::foo(). }
+int main3() { PREAMBLE_ }
-// RUN: echo "namespace ns { struct foo { int baz }; }" > %t.h
+// RUN: printf "namespace ns { struct foo { int baz }; }\n#define PREAMBLE_MAC" > %t.h
// RUN: c-index-test -write-pch %t.h.pch -x c++-header %t.h
//
// RUN: c-index-test -code-completion-at=%s:5:26 -include %t.h %s | FileCheck -check-prefix=WITH-PCH %s
// WITH-PCH: {TypedText bar}
// WITH-PCH: {TypedText foo}
+// RUN: c-index-test -code-completion-at=%s:7:24 -include %t.h %s | FileCheck -check-prefix=WITH-PCH-MACRO %s
+// WITH-PCH-MACRO: {TypedText PREAMBLE_MAC}
+
// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:5:26 -include %t.h %s | FileCheck -check-prefix=SKIP-PCH %s
// SKIP-PCH-NOT: foo
// SKIP-PCH: {TypedText bar}
// SKIP-PCH-NOT: foo
+// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:7:24 -include %t.h %s | FileCheck -check-prefix=SKIP-PCH-MACRO %s
+// SKIP-PCH-MACRO-NOT: {TypedText PREAMBLE_MAC}
+
// Verify that with *no* preamble (no -include flag) we still get local results.
// SkipPreamble used to break this, by making lookup *too* lazy.
// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:5:26 %s | FileCheck -check-prefix=NO-PCH %s
More information about the cfe-commits
mailing list