summaryrefslogtreecommitdiffstats
path: root/recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch')
-rw-r--r--recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch380
1 files changed, 0 insertions, 380 deletions
diff --git a/recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch b/recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch
deleted file mode 100644
index b9e67d4..0000000
--- a/recipes-devtools/clang/clang/0018-clang-Initial-implementation-of-fmacro-prefix-map-an.patch
+++ /dev/null
@@ -1,380 +0,0 @@
1From 3a6bf36829e16fd7ab1c2eb6b93ed6caa8210cd1 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 15 Feb 2019 10:02:52 -0800
4Subject: [PATCH] clang: Initial implementation of -fmacro-prefix-map and
5 -ffile-prefix-map
6
7Upstream-Status: Submitted [https://reviews.llvm.org/D49466]
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9---
10 .../clang/Basic/DiagnosticDriverKinds.td | 4 +-
11 clang/include/clang/Driver/Options.td | 6 +++
12 clang/include/clang/Lex/PreprocessorOptions.h | 3 ++
13 clang/lib/CodeGen/CGDebugInfo.cpp | 9 +++--
14 clang/lib/CodeGen/CGDebugInfo.h | 2 +-
15 clang/lib/Driver/ToolChains/Clang.cpp | 20 +++++++++-
16 clang/lib/Driver/ToolChains/FreeBSD.cpp | 14 +++++++
17 clang/lib/Driver/ToolChains/Gnu.cpp | 12 ++++++
18 clang/lib/Frontend/CompilerInvocation.cpp | 3 ++
19 clang/lib/Lex/PPMacroExpansion.cpp | 13 ++++++-
20 clang/test/CodeGen/debug-prefix-map.c | 2 +
21 clang/test/Driver/debug-prefix-map.S | 1 +
22 clang/test/Driver/debug-prefix-map.c | 37 ++++++++++++++-----
23 clang/test/Preprocessor/file_test.c | 22 +++++++++++
24 clang/test/Preprocessor/file_test.h | 2 +
25 15 files changed, 132 insertions(+), 18 deletions(-)
26 create mode 100644 clang/test/Preprocessor/file_test.c
27 create mode 100644 clang/test/Preprocessor/file_test.h
28
29diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
30index 12f1a7f6c48..0f8e94dad66 100644
31--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
32+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
33@@ -141,8 +141,8 @@ def err_drv_missing_arg_mtp : Error<
34 "missing argument to '%0'">;
35 def err_drv_invalid_libcxx_deployment : Error<
36 "invalid deployment target for -stdlib=libc++ (requires %0 or later)">;
37-def err_drv_invalid_argument_to_fdebug_prefix_map : Error<
38- "invalid argument '%0' to -fdebug-prefix-map">;
39+def err_drv_invalid_argument_to_option : Error<
40+ "invalid argument '%0' to -%1">;
41 def err_drv_malformed_sanitizer_blacklist : Error<
42 "malformed sanitizer blacklist: '%0'">;
43 def err_drv_duplicate_config : Error<
44diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
45index 4ea8bfff097..cf73c9ca465 100644
46--- a/clang/include/clang/Driver/Options.td
47+++ b/clang/include/clang/Driver/Options.td
48@@ -1866,10 +1866,16 @@ def fsplit_dwarf_inlining: Flag <["-"], "fsplit-dwarf-inlining">, Group<f_Group>
49 Flags<[CC1Option]>, HelpText<"Provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF">;
50 def fno_split_dwarf_inlining: Flag<["-"], "fno-split-dwarf-inlining">, Group<f_Group>,
51 Flags<[CC1Option]>;
52+def ffile_prefix_map_EQ
53+ : Joined<["-"], "ffile-prefix-map=">, Group<f_Group>, Flags<[CC1Option]>,
54+ HelpText<"remap file source paths in debug info and predefined preprocessor macros">;
55 def fdebug_prefix_map_EQ
56 : Joined<["-"], "fdebug-prefix-map=">, Group<f_Group>,
57 Flags<[CC1Option,CC1AsOption]>,
58 HelpText<"remap file source paths in debug info">;
59+def fmacro_prefix_map_EQ
60+ : Joined<["-"], "fmacro-prefix-map=">, Group<Preprocessor_Group>, Flags<[CC1Option]>,
61+ HelpText<"remap file source paths in predefined preprocessor macros">;
62 def g_Flag : Flag<["-"], "g">, Group<g_Group>,
63 HelpText<"Generate source-level debug information">;
64 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group<gN_Group>,
65diff --git a/clang/include/clang/Lex/PreprocessorOptions.h b/clang/include/clang/Lex/PreprocessorOptions.h
66index 1480548c7fb..712b423e679 100644
67--- a/clang/include/clang/Lex/PreprocessorOptions.h
68+++ b/clang/include/clang/Lex/PreprocessorOptions.h
69@@ -169,6 +169,9 @@ public:
70 /// build it again.
71 std::shared_ptr<FailedModulesSet> FailedModules;
72
73+ /// A prefix map for __FILE__ and __BASE_FILE__
74+ std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
75+
76 public:
77 PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
78
79diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
80index f6ee7ee26d4..8a190558533 100644
81--- a/clang/lib/CodeGen/CGDebugInfo.cpp
82+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
83@@ -475,10 +475,13 @@ CGDebugInfo::createFile(StringRef FileName,
84 }
85
86 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
87+ SmallString<256> p = Path;
88 for (const auto &Entry : DebugPrefixMap)
89- if (Path.startswith(Entry.first))
90- return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
91- return Path.str();
92+ if (llvm::sys::path::replace_path_prefix(p, Entry.first, Entry.second))
93+ break;
94+ while (llvm::sys::path::is_separator(p.back()))
95+ p.set_size(p.size() - 1);
96+ return p.str();
97 }
98
99 unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
100diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
101index 7edbea86633..7077d0f043c 100644
102--- a/clang/lib/CodeGen/CGDebugInfo.h
103+++ b/clang/lib/CodeGen/CGDebugInfo.h
104@@ -83,7 +83,7 @@ class CGDebugInfo {
105 /// Cache of previously constructed Types.
106 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
107
108- llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
109+ std::map<llvm::StringRef, llvm::StringRef, std::greater<llvm::StringRef>> DebugPrefixMap;
110
111 /// Cache that maps VLA types to size expressions for that type,
112 /// represented by instantiated Metadata nodes.
113diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
114index dd461a1976d..08165a60206 100644
115--- a/clang/lib/Driver/ToolChains/Clang.cpp
116+++ b/clang/lib/Driver/ToolChains/Clang.cpp
117@@ -618,16 +618,30 @@ static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
118
119 /// Add a CC1 and CC1AS option to specify the debug file path prefix map.
120 static void addDebugPrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs) {
121- for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
122+ for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
123+ options::OPT_fdebug_prefix_map_EQ)) {
124 StringRef Map = A->getValue();
125 if (Map.find('=') == StringRef::npos)
126- D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
127+ D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName();
128 else
129 CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
130 A->claim();
131 }
132 }
133
134+/// Add a CC1 and CC1AS option to specify the macro file path prefix map.
135+static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs) {
136+ for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
137+ options::OPT_fmacro_prefix_map_EQ)) {
138+ StringRef Map = A->getValue();
139+ if (Map.find('=') == StringRef::npos)
140+ D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName();
141+ else
142+ CmdArgs.push_back(Args.MakeArgString("-fmacro-prefix-map=" + Map));
143+ A->claim();
144+ }
145+}
146+
147 /// Vectorize at all optimization levels greater than 1 except for -Oz.
148 /// For -Oz the loop vectorizer is disabled, while the slp vectorizer is
149 /// enabled.
150@@ -1317,6 +1331,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
151 // For IAMCU add special include arguments.
152 getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
153 }
154+
155+ addMacroPrefixMapArg(D, Args, CmdArgs);
156 }
157
158 // FIXME: Move to target hook.
159diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
160index 3a0bab8d07f..6eea9f04620 100644
161--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
162+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
163@@ -12,6 +12,7 @@
164 #include "Arch/Sparc.h"
165 #include "CommonArgs.h"
166 #include "clang/Driver/Compilation.h"
167+#include "clang/Driver/DriverDiagnostic.h"
168 #include "clang/Driver/Options.h"
169 #include "clang/Driver/SanitizerArgs.h"
170 #include "llvm/Option/ArgList.h"
171@@ -30,6 +31,7 @@ void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
172 const char *LinkingOutput) const {
173 claimNoWarnArgs(Args);
174 ArgStringList CmdArgs;
175+ const auto &D = getToolChain().getDriver();
176
177 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
178 // instruct as in the base system to assemble 32-bit code.
179@@ -103,6 +105,18 @@ void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
180 }
181 }
182
183+ for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
184+ options::OPT_fdebug_prefix_map_EQ)) {
185+ StringRef Map = A->getValue();
186+ if (Map.find('=') == StringRef::npos)
187+ D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName();
188+ else {
189+ CmdArgs.push_back(Args.MakeArgString("--debug-prefix-map"));
190+ CmdArgs.push_back(Args.MakeArgString(Map));
191+ }
192+ A->claim();
193+ }
194+
195 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
196
197 CmdArgs.push_back("-o");
198diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
199index 20517a369f7..ebb315d9c15 100644
200--- a/clang/lib/Driver/ToolChains/Gnu.cpp
201+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
202@@ -874,6 +874,18 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
203 }
204 }
205
206+ for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
207+ options::OPT_fdebug_prefix_map_EQ)) {
208+ StringRef Map = A->getValue();
209+ if (Map.find('=') == StringRef::npos)
210+ D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName();
211+ else {
212+ CmdArgs.push_back(Args.MakeArgString("--debug-prefix-map"));
213+ CmdArgs.push_back(Args.MakeArgString(Map));
214+ }
215+ A->claim();
216+ }
217+
218 Args.AddAllArgs(CmdArgs, options::OPT_I);
219 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
220
221diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
222index bc54e38a1a6..ff68adb865d 100644
223--- a/clang/lib/Frontend/CompilerInvocation.cpp
224+++ b/clang/lib/Frontend/CompilerInvocation.cpp
225@@ -3180,6 +3180,9 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
226 for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
227 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
228
229+ for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
230+ Opts.MacroPrefixMap.insert(StringRef(A).split('='));
231+
232 if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
233 StringRef Value(A->getValue());
234 size_t Comma = Value.find(',');
235diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
236index 687b9a9d3b7..9fffe35d924 100644
237--- a/clang/lib/Lex/PPMacroExpansion.cpp
238+++ b/clang/lib/Lex/PPMacroExpansion.cpp
239@@ -28,6 +28,7 @@
240 #include "clang/Lex/MacroInfo.h"
241 #include "clang/Lex/Preprocessor.h"
242 #include "clang/Lex/PreprocessorLexer.h"
243+#include "clang/Lex/PreprocessorOptions.h"
244 #include "clang/Lex/Token.h"
245 #include "llvm/ADT/ArrayRef.h"
246 #include "llvm/ADT/DenseMap.h"
247@@ -1436,6 +1437,15 @@ static bool isTargetEnvironment(const TargetInfo &TI,
248 return TI.getTriple().getEnvironment() == Env.getEnvironment();
249 }
250
251+static void remapMacroPath(
252+ SmallString<256> &Path,
253+ const std::map<std::string, std::string, std::greater<std::string>>
254+ &MacroPrefixMap) {
255+ for (const auto &Entry : MacroPrefixMap)
256+ if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
257+ break;
258+}
259+
260 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
261 /// as a builtin macro, handle it and return the next token as 'Tok'.
262 void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
263@@ -1502,7 +1512,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
264 }
265
266 // Escape this filename. Turn '\' -> '\\' '"' -> '\"'
267- SmallString<128> FN;
268+ SmallString<256> FN;
269 if (PLoc.isValid()) {
270 // __FILE_NAME__ is a Clang-specific extension that expands to the
271 // the last part of __FILE__.
272@@ -1518,6 +1528,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
273 FN += PLoc.getFilename();
274 }
275 Lexer::Stringify(FN);
276+ remapMacroPath(FN, PPOpts->MacroPrefixMap);
277 OS << '"' << FN << '"';
278 }
279 Tok.setKind(tok::string_literal);
280diff --git a/clang/test/CodeGen/debug-prefix-map.c b/clang/test/CodeGen/debug-prefix-map.c
281index f755ba47a29..e57808f03f9 100644
282--- a/clang/test/CodeGen/debug-prefix-map.c
283+++ b/clang/test/CodeGen/debug-prefix-map.c
284@@ -2,6 +2,8 @@
285 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-EVIL
286 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s
287 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
288+// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
289+// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
290
291 #include "Inputs/stdio.h"
292
293diff --git a/clang/test/Driver/debug-prefix-map.S b/clang/test/Driver/debug-prefix-map.S
294index 2ba66be0edf..7d12a174797 100644
295--- a/clang/test/Driver/debug-prefix-map.S
296+++ b/clang/test/Driver/debug-prefix-map.S
297@@ -1,4 +1,5 @@
298 // RUN: %clang -### -g -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s
299+// RUN: %clang -### -g -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s
300
301 // CHECK: cc1as
302 // CHECK-SAME: -fdebug-prefix-map=old=new
303diff --git a/clang/test/Driver/debug-prefix-map.c b/clang/test/Driver/debug-prefix-map.c
304index b4f3859f982..f2c87cb7c11 100644
305--- a/clang/test/Driver/debug-prefix-map.c
306+++ b/clang/test/Driver/debug-prefix-map.c
307@@ -1,9 +1,28 @@
308-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
309-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
310-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
311-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
312-
313-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
314-// CHECK-SIMPLE: fdebug-prefix-map=old=new
315-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
316-// CHECK-EMPTY: fdebug-prefix-map=old=
317+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
318+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
319+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
320+
321+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
322+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
323+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
324+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
325+
326+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
327+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
328+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
329+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
330+
331+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
332+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
333+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
334+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
335+
336+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
337+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
338+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
339+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
340+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
341+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
342+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
343+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
344+// CHECK-MACRO-EMPTY: fmacro-prefix-map=old=
345diff --git a/clang/test/Preprocessor/file_test.c b/clang/test/Preprocessor/file_test.c
346new file mode 100644
347index 00000000000..bdc5f1df659
348--- /dev/null
349+++ b/clang/test/Preprocessor/file_test.c
350@@ -0,0 +1,22 @@
351+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
352+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
353+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
354+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
355+
356+filename: __FILE__
357+#include "file_test.h"
358+
359+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
360+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
361+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
362+// CHECK-NOT: filename:
363+
364+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
365+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
366+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
367+// CHECK-EVIL-NOT: filename:
368+
369+// CHECK-REMOVE: filename: "file_test.c"
370+// CHECK-REMOVE: filename: "file_test.h"
371+// CHECK-REMOVE: basefile: "file_test.c"
372+// CHECK-REMOVE-NOT: filename:
373diff --git a/clang/test/Preprocessor/file_test.h b/clang/test/Preprocessor/file_test.h
374new file mode 100644
375index 00000000000..c289e5c8362
376--- /dev/null
377+++ b/clang/test/Preprocessor/file_test.h
378@@ -0,0 +1,2 @@
379+filename: __FILE__
380+basefile: __BASE_FILE__