aboutsummaryrefslogtreecommitdiff
path: root/test/Modules/macros.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-10-11 00:46:49 +0000
committerDouglas Gregor <dgregor@apple.com>2012-10-11 00:46:49 +0000
commit6c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462 (patch)
treecea015c280d1666e0a42bdb2f208d8829a5f4cc9 /test/Modules/macros.c
parent8b03277b0bc18ab73be11b6067474d515fdad271 (diff)
Deserialize macro history when we deserialize an identifier that has
macro history. When deserializing macro history, we arrange history such that the macros that have definitions (that haven't been #undef'd) and are visible come at the beginning of the list, which is what the preprocessor and other clients of Preprocessor::getMacroInfo() expect. If additional macro definitions become visible later, they'll be moved toward the front of the list. Note that it's possible to have ambiguities, but we don't diagnose them yet. There is a partially-implemented design decision here that, if a particular identifier has been defined or #undef'd within the translation unit, that definition (or #undef) hides any macro definitions that come from imported modules. There's still a little work to do to ensure that the right #undef'ing happens. Additionally, we'll need to scope the update records for #undefs, so they only kick in when the submodule containing that update record becomes visible. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Modules/macros.c')
-rw-r--r--test/Modules/macros.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/test/Modules/macros.c b/test/Modules/macros.c
index d93ce35a03..168e2c6fce 100644
--- a/test/Modules/macros.c
+++ b/test/Modules/macros.c
@@ -1,8 +1,14 @@
// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_top %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_left %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_right %S/Inputs/module.map
// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros %S/Inputs/module.map
// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodule-cache-path %t %s
// RUN: %clang_cc1 -E -fmodules -x objective-c -fmodule-cache-path %t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
// FIXME: When we have a syntax for modules in C, use that.
+// These notes come from headers in modules, and are bogus.
+// FIXME: expected-note{{previous definition is here}}
+// FIXME: expected-note{{previous definition is here}}
@__experimental_modules_import macros;
@@ -37,3 +43,83 @@ void f() {
#if __building_module(macros)
# error Not building a module
#endif
+
+// None of the modules we depend on have been imported, and therefore
+// their macros should not be visible.
+#ifdef LEFT
+# error LEFT should not be visible
+#endif
+
+#ifdef RIGHT
+# error RIGHT should not be visible
+#endif
+
+#ifdef TOP
+# error TOP should not be visible
+#endif
+
+// Import left module (which also imports top)
+@__experimental_modules_import macros_left;
+
+#ifndef LEFT
+# error LEFT should be visible
+#endif
+
+#ifdef RIGHT
+# error RIGHT should not be visible
+#endif
+
+#ifndef TOP
+# error TOP should be visible
+#endif
+
+#ifdef TOP_LEFT_UNDEF
+# error TOP_LEFT_UNDEF should not be visible
+#endif
+
+void test1() {
+ int i;
+ TOP_RIGHT_REDEF *ip = &i;
+}
+
+#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}}
+
+// Import right module (which also imports top)
+@__experimental_modules_import macros_right;
+
+#undef LEFT_RIGHT_DIFFERENT3
+
+#ifndef LEFT
+# error LEFT should be visible
+#endif
+
+#ifndef RIGHT
+# error RIGHT should be visible
+#endif
+
+#ifndef TOP
+# error TOP should be visible
+#endif
+
+#ifndef TOP_LEFT_UNDEF
+# error TOP_LEFT_UNDEF should be visible
+#endif
+
+void test2() {
+ int i;
+ float f;
+ double d;
+ TOP_RIGHT_REDEF *ip = &i; // FIXME: warning
+
+ LEFT_RIGHT_IDENTICAL *ip2 = &i;
+ LEFT_RIGHT_DIFFERENT *fp = &f; // FIXME: warning
+ LEFT_RIGHT_DIFFERENT2 *dp = &d; // okay
+ int LEFT_RIGHT_DIFFERENT3;
+}
+
+#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
+
+void test3() {
+ double d;
+ LEFT_RIGHT_DIFFERENT *dp = &d; // okay
+}