[clang] de4a796 - [Clang] Use the last macro prefix map for duplicate prefixes (#249124)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 4 23:39:27 PST 2026
Author: Dillon Amburgey
Date: 2026-12-05T07:39:21Z
New Revision: de4a7960af3838397a93faf534d5002f80d0ebca
URL: https://github.com/llvm/llvm-project/commit/de4a7960af3838397a93faf534d5002f80d0ebca
DIFF: https://github.com/llvm/llvm-project/commit/de4a7960af3838397a93faf534d5002f80d0ebca.diff
LOG: [Clang] Use the last macro prefix map for duplicate prefixes (#249124)
Use the last destination when multiple macro prefix maps have the same
source prefix. This makes repeated -ffile-prefix-map options consistent
with their debug and coverage mappings.
Fixes #157721
Assisted-by: OpenAI Codex
Added:
Modified:
clang/docs/ReleaseNotes.md
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Preprocessor/file_test.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 67f00e57a85d3..b4acef0654002 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1064,6 +1064,7 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
- Fixed `#embed` of a missing file not being diagnosed if `-MD` is used. (#GH247359)
- Fixed `__has_embed` return value with `limit` greater than the file size. (#GH247344)
- Fixed a C2y rejects-valid where only a single `label:` per loop can be used with `break label;`. (#GH246505)
+- Fixed `-ffile-prefix-map` and `-fmacro-prefix-map` to use the last destination when the same source prefix is specified more than once, matching GCC. (#GH157721)
#### Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 194ce26e0b5bb..cbc5b1acb14b4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4629,8 +4629,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ)) {
auto Split = StringRef(A).split('=');
- Opts.MacroPrefixMap.insert(
- {std::string(Split.first), std::string(Split.second)});
+ Opts.MacroPrefixMap.insert_or_assign(std::string(Split.first),
+ std::string(Split.second));
}
Opts.UseTargetPathSeparator =
diff --git a/clang/test/Preprocessor/file_test.c b/clang/test/Preprocessor/file_test.c
index 1e7e1dfe96dd9..cc4a2df866068 100644
--- a/clang/test/Preprocessor/file_test.c
+++ b/clang/test/Preprocessor/file_test.c
@@ -1,6 +1,8 @@
// UNSUPPORTED: system-windows, system-cygwin
// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -ffile-prefix-map=%p=/first -ffile-prefix-map=%p=/UNLIKELY_PATH/empty %s | FileCheck %s
+// RUN: %clang -E -ffile-prefix-map=%p=/first -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty %s | FileCheck %s
// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
// RUN: %clang -E -fno-file-reproducible -fmacro-prefix-map=%p/= -target x86_64-pc-win32 -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
More information about the cfe-commits
mailing list