[Preprocessor] Iterating over all macros should include those from modules.
authorJordan Rose <jordan_rose@apple.com>
Wed, 24 Jun 2015 19:27:02 +0000 (19:27 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 24 Jun 2015 19:27:02 +0000 (19:27 +0000)
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

llvm-svn: 240571

clang/lib/Lex/Preprocessor.cpp
clang/test/CodeCompletion/macros-in-modules.c [new file with mode: 0644]
clang/test/CodeCompletion/macros-in-modules.m [new file with mode: 0644]

index 7e33f1c..e2db638 100644 (file)
@@ -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/clang/test/CodeCompletion/macros-in-modules.c b/clang/test/CodeCompletion/macros-in-modules.c
new file mode 100644 (file)
index 0000000..82ffaae
--- /dev/null
@@ -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/clang/test/CodeCompletion/macros-in-modules.m b/clang/test/CodeCompletion/macros-in-modules.m
new file mode 100644 (file)
index 0000000..8d6b375
--- /dev/null
@@ -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