Skip to content

Commit e9a7876

Browse files
committed
[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.
1 parent 75b0a99 commit e9a7876

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,8 +3163,8 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
31633163
StringRef Val = A->getValue();
31643164
if (Val.contains('=')) {
31653165
auto Split = Val.split('=');
3166-
Opts.PrebuiltModuleFiles.insert(
3167-
{std::string(Split.first), std::string(Split.second)});
3166+
Opts.PrebuiltModuleFiles.insert_or_assign(
3167+
std::string(Split.first), std::string(Split.second));
31683168
}
31693169
}
31703170
for (const auto *A : Args.filtered(OPT_fprebuilt_module_path))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Tests that we will pick the last `-fmodule-file=<module-name>=<path>` flag
2+
// for <module-name>.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
// RUN: cd %t
7+
//
8+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
9+
// RUN: %clang_cc1 -std=c++20 %t/u.cpp -fmodule-file=a=%t/unexist.pcm \
10+
// RUN: -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
11+
12+
//--- a.cppm
13+
export module a;
14+
export int a();
15+
16+
//--- u.cpp
17+
// expected-no-diagnostics
18+
import a;
19+
int u() {
20+
return a();
21+
}

0 commit comments

Comments
 (0)