[libcxx-commits] [libcxx] bae14bc - [libc++][modules] Improves export validation.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 31 09:39:05 PDT 2023


Author: Mark de Wever
Date: 2023-07-31T18:38:52+02:00
New Revision: bae14bcd1d9eba2cfae0d755c9d6b61e6ed3a6ca

URL: https://github.com/llvm/llvm-project/commit/bae14bcd1d9eba2cfae0d755c9d6b61e6ed3a6ca
DIFF: https://github.com/llvm/llvm-project/commit/bae14bcd1d9eba2cfae0d755c9d6b61e6ed3a6ca.diff

LOG: [libc++][modules] Improves export validation.

Adds tests to guard against the issue solved in D156592.

Depends on D156592

Reviewed By: ChuanqiXu, #libc, philnik

Differential Revision: https://reviews.llvm.org/D156594

Added: 
    

Modified: 
    libcxx/test/libcxx/module_std.gen.py
    libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/module_std.gen.py b/libcxx/test/libcxx/module_std.gen.py
index 787317888d20d0..534da5398c6e0e 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -225,3 +225,10 @@
 
 # Compare the sum of the parts with the main module.
 print(f"// RUN{BLOCKLIT}: 
diff  -u %t.all_partitions %t.module")
+
+# Basic smoke test. Import a module and try to compile when using all
+# exported names. This validates the clang-tidy script does not accidentally
+# add named declarations to the list that are not available.
+print(f"// RUN{BLOCKLIT}: echo 'import std;' > %t.compile.pass.cpp")
+print(f"// RUN{BLOCKLIT}: cat %t.all_partitions >> %t.compile.pass.cpp")
+print(f"// RUN{BLOCKLIT}: %{{cxx}} %{{flags}} %{{compile_flags}} -fsyntax-only %t.compile.pass.cpp")

diff  --git a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
index 9f2a667c67b16a..f691f4ee6392ab 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -228,6 +228,11 @@ void header_exportable_declarations::check(const clang::ast_matchers::MatchFinde
       if (clang::Module* M = decl->getOwningModule(); M && M->Kind != clang::Module::ModulePartitionInterface)
         return;
 
+    // For module partitions only take exported declarations.
+    if (file_type_ == FileType::ModulePartition)
+      if (decl->getModuleOwnershipKind() != clang::Decl::ModuleOwnershipKind::VisibleWhenImported)
+        return;
+
     if (decls_.contains(name)) {
       // For modules avoid exporting the same named declaration twice. For
       // header files this is common and valid.


        


More information about the libcxx-commits mailing list