From: Jordan Rose Date: Wed, 24 Jun 2015 19:27:02 +0000 (+0000) Subject: [Preprocessor] Iterating over all macros should include those from modules. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=096560832fb493d875541c67895eb8a8620b68ed;p=clang [Preprocessor] Iterating over all macros should include those from modules. So, iterate over the list of macros mentioned in modules, and make sure those are in the master table. This isn't particularly efficient, but hopefully it's something that isn't done too often. PR23929 and rdar://problem/21480635 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240571 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 7e33f1ccb4..e2db638a33 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -286,6 +286,10 @@ Preprocessor::macro_begin(bool IncludeExternalMacros) const { ExternalSource->ReadDefinedMacros(); } + // Make sure we cover all macros in visible modules. + for (const ModuleMacro &Macro : ModuleMacros) + CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState())); + return CurSubmoduleState->Macros.begin(); } diff --git a/test/CodeCompletion/macros-in-modules.c b/test/CodeCompletion/macros-in-modules.c new file mode 100644 index 0000000000..82ffaae7cb --- /dev/null +++ b/test/CodeCompletion/macros-in-modules.c @@ -0,0 +1,11 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: echo 'module Foo { header "foo.h" }' > %t/module.modulemap +// RUN: echo '#define FOO_MACRO 42' > %t/foo.h +// RUN: c-index-test -code-completion-at=%s:9:1 -I %t %s | FileCheck %s +// RUN: c-index-test -code-completion-at=%s:9:1 -I %t -fmodules %s | FileCheck %s + +#include "foo.h" +int x = +/*here*/1; + +// CHECK: FOO_MACRO diff --git a/test/CodeCompletion/macros-in-modules.m b/test/CodeCompletion/macros-in-modules.m new file mode 100644 index 0000000000..8d6b3753d0 --- /dev/null +++ b/test/CodeCompletion/macros-in-modules.m @@ -0,0 +1,10 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: echo 'module Foo { header "foo.h" }' > %t/module.modulemap +// RUN: echo '#define FOO_MACRO 42' > %t/foo.h +// RUN: c-index-test -code-completion-at=%s:8:1 -I %t -fmodules %s | FileCheck %s + +@import Foo; +int x = +/*here*/1; + +// CHECK: FOO_MACRO