[clang] 4259301 - Support #__private_macro and #__public_macro in local submodule
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 23 16:54:46 PDT 2021
Author: Richard Smith
Date: 2021-03-23T16:54:28-07:00
New Revision: 4259301aaf58c13b004d968dfbd20428bf978b32
URL: https://github.com/llvm/llvm-project/commit/4259301aaf58c13b004d968dfbd20428bf978b32
DIFF: https://github.com/llvm/llvm-project/commit/4259301aaf58c13b004d968dfbd20428bf978b32.diff
LOG: Support #__private_macro and #__public_macro in local submodule
visibility mode.
Added:
clang/test/Modules/Inputs/lsv-private-macro/mod.map
clang/test/Modules/Inputs/lsv-private-macro/other.h
clang/test/Modules/Inputs/lsv-private-macro/self.h
clang/test/Modules/lsv-private-macro.cpp
Modified:
clang/lib/Lex/PPDirectives.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 252697b2fd35..a771b7c5d122 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1045,12 +1045,12 @@ void Preprocessor::HandleDirective(Token &Result) {
break;
case tok::pp___public_macro:
- if (getLangOpts().Modules)
+ if (getLangOpts().Modules || getLangOpts().ModulesLocalVisibility)
return HandleMacroPublicDirective(Result);
break;
case tok::pp___private_macro:
- if (getLangOpts().Modules)
+ if (getLangOpts().Modules || getLangOpts().ModulesLocalVisibility)
return HandleMacroPrivateDirective();
break;
}
diff --git a/clang/test/Modules/Inputs/lsv-private-macro/mod.map b/clang/test/Modules/Inputs/lsv-private-macro/mod.map
new file mode 100644
index 000000000000..62b92fb63e79
--- /dev/null
+++ b/clang/test/Modules/Inputs/lsv-private-macro/mod.map
@@ -0,0 +1,7 @@
+module self {
+ header "self.h"
+}
+
+module other {
+ header "other.h"
+}
diff --git a/clang/test/Modules/Inputs/lsv-private-macro/other.h b/clang/test/Modules/Inputs/lsv-private-macro/other.h
new file mode 100644
index 000000000000..356eccaec27f
--- /dev/null
+++ b/clang/test/Modules/Inputs/lsv-private-macro/other.h
@@ -0,0 +1,7 @@
+#define OTHER_PRIVATE
+#__private_macro OTHER_PRIVATE
+
+#define OTHER_PUBLIC
+#__public_macro OTHER_PUBLIC
+
+#define OTHER_DEFAULT
diff --git a/clang/test/Modules/Inputs/lsv-private-macro/self.h b/clang/test/Modules/Inputs/lsv-private-macro/self.h
new file mode 100644
index 000000000000..5a361308a10d
--- /dev/null
+++ b/clang/test/Modules/Inputs/lsv-private-macro/self.h
@@ -0,0 +1,7 @@
+#define SELF_PRIVATE
+#__private_macro SELF_PRIVATE
+
+#define SELF_PUBLIC
+#__public_macro SELF_PUBLIC
+
+#define SELF_DEFAULT
diff --git a/clang/test/Modules/lsv-private-macro.cpp b/clang/test/Modules/lsv-private-macro.cpp
new file mode 100644
index 000000000000..6564558453e3
--- /dev/null
+++ b/clang/test/Modules/lsv-private-macro.cpp
@@ -0,0 +1,53 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 %s \
+// RUN: -fmodules-local-submodule-visibility \
+// RUN: -fmodule-map-file=%S/Inputs/lsv-private-macro/mod.map \
+// RUN: -I%S/Inputs/lsv-private-macro -fmodule-name=self \
+// RUN: -verify=expected-lsv
+//
+// RUN: %clang_cc1 %s \
+// RUN: -fmodules -fmodules-cache-path=%t \
+// RUN: -fmodule-map-file=%S/Inputs/lsv-private-macro/mod.map \
+// RUN: -I%S/Inputs/lsv-private-macro -fmodule-name=self \
+// RUN: -verify=expected-nolsv
+//
+// RUN: %clang_cc1 %s \
+// RUN: -fmodules -fmodules-cache-path=%t \
+// RUN: -fmodules-local-submodule-visibility \
+// RUN: -fmodule-map-file=%S/Inputs/lsv-private-macro/mod.map \
+// RUN: -I%S/Inputs/lsv-private-macro -fmodule-name=self \
+// RUN: -verify=expected-lsv
+
+#include "self.h"
+
+// With local submodule visibility enabled, private macros don't leak out of
+// their respective submodules, even within the same top-level module.
+// expected-lsv-no-diagnostics
+
+// expected-nolsv-error at +2 {{SELF_PRIVATE defined}}
+#ifdef SELF_PRIVATE
+#error SELF_PRIVATE defined
+#endif
+
+#ifndef SELF_PUBLIC
+#error SELF_PUBLIC not defined
+#endif
+
+#ifndef SELF_DEFAULT
+#error SELF_DEFAULT not defined
+#endif
+
+#include "other.h"
+
+#ifdef OTHER_PRIVATE
+#error OTHER_PRIVATE defined
+#endif
+
+#ifndef OTHER_PUBLIC
+#error OTHER_PUBLIC not defined
+#endif
+
+#ifndef OTHER_DEFAULT
+#error OTHER_DEFAULT not defined
+#endif
More information about the cfe-commits
mailing list