[clang] e9a7876 - [C++20] [Modules] Chose BMI from for module m with the last
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 27 01:53:19 PDT 2023
Author: Chuanqi Xu
Date: 2023-10-27T16:52:21+08:00
New Revision: e9a7876c2c81423f2289aa85eeac32d7a55cd3c8
URL: https://github.com/llvm/llvm-project/commit/e9a7876c2c81423f2289aa85eeac32d7a55cd3c8
DIFF: https://github.com/llvm/llvm-project/commit/e9a7876c2c81423f2289aa85eeac32d7a55cd3c8.diff
LOG: [C++20] [Modules] Chose BMI from for module m with the last
-fmodule-file=<module-name>= option
Currently if we have multiple `-fmodule-file=<module-name>=<BMI-path>`
flags for the same `<module-name>`, we will pick the BMI-path from the
first flag. And this is inconsistent with what users generally expect.
e.g, we might expect the latter flags can override the former ones.
This patch changes the behavior to match user's expectation.
Added:
clang/test/Modules/duplicated-module-file-eq-module-name.cppm
Modified:
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 4e6d7bb16f51beb..fd6c250efeda2a8 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3163,8 +3163,8 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
StringRef Val = A->getValue();
if (Val.contains('=')) {
auto Split = Val.split('=');
- Opts.PrebuiltModuleFiles.insert(
- {std::string(Split.first), std::string(Split.second)});
+ Opts.PrebuiltModuleFiles.insert_or_assign(
+ std::string(Split.first), std::string(Split.second));
}
}
for (const auto *A : Args.filtered(OPT_fprebuilt_module_path))
diff --git a/clang/test/Modules/duplicated-module-file-eq-module-name.cppm b/clang/test/Modules/duplicated-module-file-eq-module-name.cppm
new file mode 100644
index 000000000000000..e86dbe2b941ef88
--- /dev/null
+++ b/clang/test/Modules/duplicated-module-file-eq-module-name.cppm
@@ -0,0 +1,21 @@
+// Tests that we will pick the last `-fmodule-file=<module-name>=<path>` flag
+// for <module-name>.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/u.cpp -fmodule-file=a=%t/unexist.pcm \
+// RUN: -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
+
+//--- a.cppm
+export module a;
+export int a();
+
+//--- u.cpp
+// expected-no-diagnostics
+import a;
+int u() {
+ return a();
+}
More information about the cfe-commits
mailing list