summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2019-02-15 11:03:31 -0800
committerKhem Raj <raj.khem@gmail.com>2019-02-15 13:40:53 -0800
commit9b687a0924982e38d5fa450081845d655a121f44 (patch)
treeb0647c8f10d75499863009833de1221af921b280
parent1c0e9f38b8e9b805c2ba62e99da0fffd57ce1eea (diff)
downloadmeta-clang-9b687a0924982e38d5fa450081845d655a121f44.tar.gz
clang: Implement -fmacro-prefix-map
OE-core now uses it so, we have to take the patch from review system, until it is in master Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rw-r--r--recipes-devtools/clang/clang/0019-llvm-Enhance-path-prefix-mapping.patch175
-rw-r--r--recipes-devtools/clang/clang/0020-clang-Initial-implementation-of-fmacro-prefix-map-an.patch387
-rw-r--r--recipes-devtools/clang/common.inc2
3 files changed, 564 insertions, 0 deletions
diff --git a/recipes-devtools/clang/clang/0019-llvm-Enhance-path-prefix-mapping.patch b/recipes-devtools/clang/clang/0019-llvm-Enhance-path-prefix-mapping.patch
new file mode 100644
index 0000000..cbfc0be
--- /dev/null
+++ b/recipes-devtools/clang/clang/0019-llvm-Enhance-path-prefix-mapping.patch
@@ -0,0 +1,175 @@
1From 07594e15b8e9740012c3bcac00f935faf77f1c99 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 15 Feb 2019 11:32:09 -0800
4Subject: [PATCH 1/2] llvm: Enhance path prefix mapping
5
6Upstream-Status: Submitted [https://reviews.llvm.org/D56769]
7Signed-off-by: Khem Raj <raj.khem@gmail.com>
8---
9 llvm/include/llvm/Support/Path.h | 25 +++++++++++++++---
10 llvm/lib/Support/Path.cpp | 44 +++++++++++++++++++++++++-------
11 llvm/unittests/Support/Path.cpp | 29 +++++++++++++++++++++
12 3 files changed, 85 insertions(+), 13 deletions(-)
13
14diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h
15index 5c0bee58f18..20332c09852 100644
16--- a/llvm/include/llvm/Support/Path.h
17+++ b/llvm/include/llvm/Support/Path.h
18@@ -150,18 +150,35 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
19 ///
20 /// @code
21 /// /foo, /old, /new => /foo
22+/// /old, /old, /new => /new
23+/// /old, /old/, /new, false => /old
24+/// /old, /old/, /new, true => /new
25 /// /old/foo, /old, /new => /new/foo
26+/// /old/foo, /old/, /new => /new/foo
27+/// /old/foo, /old/, /new/ => /new/foo
28+/// /oldfoo, /old, /new => /oldfoo
29 /// /foo, <empty>, /new => /new/foo
30-/// /old/foo, /old, <empty> => /foo
31+/// /foo, <empty>, new => new/foo
32+/// /old/foo, /old, <empty>, false => /foo
33+/// /old/foo, /old, <empty>, true => foo
34 /// @endcode
35 ///
36 /// @param Path If \a Path starts with \a OldPrefix modify to instead
37 /// start with \a NewPrefix.
38-/// @param OldPrefix The path prefix to strip from \a Path.
39+/// @param OldPrefix The path prefix to strip from \a Path. Any trailing
40+/// path separator is ignored if strict is true.
41 /// @param NewPrefix The path prefix to replace \a NewPrefix with.
42-void replace_path_prefix(SmallVectorImpl<char> &Path,
43+/// @param style The path separator style
44+/// @param strict Strict prefix path checking
45+/// @result true if \a Path begins with OldPrefix
46+bool replace_path_prefix(SmallVectorImpl<char> &Path,
47 const StringRef &OldPrefix, const StringRef &NewPrefix,
48- Style style = Style::native);
49+ Style style = Style::native, bool strict = false);
50+static inline bool replace_path_prefix(SmallVectorImpl<char> &Path,
51+ const StringRef &OldPrefix, const StringRef &NewPrefix,
52+ bool strict, Style style = Style::native) {
53+ return replace_path_prefix(Path, OldPrefix, NewPrefix, style, strict);
54+}
55
56 /// Append to path.
57 ///
58diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
59index 8f580c66d24..e368fe0e17b 100644
60--- a/llvm/lib/Support/Path.cpp
61+++ b/llvm/lib/Support/Path.cpp
62@@ -520,27 +520,53 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
63 path.append(ext.begin(), ext.end());
64 }
65
66-void replace_path_prefix(SmallVectorImpl<char> &Path,
67+bool replace_path_prefix(SmallVectorImpl<char> &Path,
68 const StringRef &OldPrefix, const StringRef &NewPrefix,
69- Style style) {
70+ Style style, bool strict) {
71 if (OldPrefix.empty() && NewPrefix.empty())
72- return;
73+ return false;
74
75 StringRef OrigPath(Path.begin(), Path.size());
76- if (!OrigPath.startswith(OldPrefix))
77- return;
78+ StringRef OldPrefixDir;
79+
80+ if (!strict && OldPrefix.size() > OrigPath.size())
81+ return false;
82+
83+ if (!strict && OldPrefix.size() > OrigPath.size())
84+ return false;
85+
86+ // Ensure OldPrefixDir does not have a trailing separator.
87+ if (!OldPrefix.empty() && is_separator(OldPrefix.back()))
88+ OldPrefixDir = parent_path(OldPrefix, style);
89+ else
90+ OldPrefixDir = OldPrefix;
91+
92+ if (!OrigPath.startswith(OldPrefixDir))
93+ return false;
94+
95+ if (OrigPath.size() > OldPrefixDir.size())
96+ if (!is_separator(OrigPath[OldPrefixDir.size()], style) && strict)
97+ return false;
98
99 // If prefixes have the same size we can simply copy the new one over.
100- if (OldPrefix.size() == NewPrefix.size()) {
101+ if (OldPrefixDir.size() == NewPrefix.size() && !strict) {
102 llvm::copy(NewPrefix, Path.begin());
103- return;
104+ return true;
105 }
106
107- StringRef RelPath = OrigPath.substr(OldPrefix.size());
108+ StringRef RelPath = OrigPath.substr(OldPrefixDir.size());
109 SmallString<256> NewPath;
110 path::append(NewPath, style, NewPrefix);
111- path::append(NewPath, style, RelPath);
112+ if (!RelPath.empty()) {
113+ if (!is_separator(RelPath[0], style) || !strict)
114+ path::append(NewPath, style, RelPath);
115+ else
116+ path::append(NewPath, style, relative_path(RelPath, style));
117+ }
118+
119 Path.swap(NewPath);
120+
121+ return true;
122 }
123
124 void native(const Twine &path, SmallVectorImpl<char> &result, Style style) {
125diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
126index 7ce6d2d52db..eaf8557ca8d 100644
127--- a/llvm/unittests/Support/Path.cpp
128+++ b/llvm/unittests/Support/Path.cpp
129@@ -1207,7 +1207,9 @@ TEST(Support, RemoveDots) {
130 TEST(Support, ReplacePathPrefix) {
131 SmallString<64> Path1("/foo");
132 SmallString<64> Path2("/old/foo");
133+ SmallString<64> Path3("/oldnew/foo");
134 SmallString<64> OldPrefix("/old");
135+ SmallString<64> OldPrefixSep("/old/");
136 SmallString<64> NewPrefix("/new");
137 SmallString<64> NewPrefix2("/longernew");
138 SmallString<64> EmptyPrefix("");
139@@ -1227,6 +1229,33 @@ TEST(Support, ReplacePathPrefix) {
140 Path = Path2;
141 path::replace_path_prefix(Path, OldPrefix, EmptyPrefix);
142 EXPECT_EQ(Path, "/foo");
143+ Path = Path2;
144+ path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true);
145+ EXPECT_EQ(Path, "foo");
146+ Path = Path3;
147+ path::replace_path_prefix(Path, OldPrefix, NewPrefix, false);
148+ EXPECT_EQ(Path, "/newnew/foo");
149+ Path = Path3;
150+ path::replace_path_prefix(Path, OldPrefix, NewPrefix, true);
151+ EXPECT_EQ(Path, "/oldnew/foo");
152+ Path = Path3;
153+ path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
154+ EXPECT_EQ(Path, "/oldnew/foo");
155+ Path = Path1;
156+ path::replace_path_prefix(Path, EmptyPrefix, NewPrefix);
157+ EXPECT_EQ(Path, "/new/foo");
158+ Path = OldPrefix;
159+ path::replace_path_prefix(Path, OldPrefix, NewPrefix);
160+ EXPECT_EQ(Path, "/new");
161+ Path = OldPrefixSep;
162+ path::replace_path_prefix(Path, OldPrefix, NewPrefix);
163+ EXPECT_EQ(Path, "/new/");
164+ Path = OldPrefix;
165+ path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false);
166+ EXPECT_EQ(Path, "/old");
167+ Path = OldPrefix;
168+ path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
169+ EXPECT_EQ(Path, "/new");
170 }
171
172 TEST_F(FileSystemTest, OpenFileForRead) {
173--
1742.20.1
175
diff --git a/recipes-devtools/clang/clang/0020-clang-Initial-implementation-of-fmacro-prefix-map-an.patch b/recipes-devtools/clang/clang/0020-clang-Initial-implementation-of-fmacro-prefix-map-an.patch
new file mode 100644
index 0000000..a8e1c9a
--- /dev/null
+++ b/recipes-devtools/clang/clang/0020-clang-Initial-implementation-of-fmacro-prefix-map-an.patch
@@ -0,0 +1,387 @@
1From 29a090d31273e78646cc34a392fa292e63e8e4e4 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 2/2] 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 | 14 ++++++-
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, 133 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 189e0565a83..46972e7c288 100644
31--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
32+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
33@@ -114,8 +114,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 a6a6e3b5b53..b9734ea8e4d 100644
46--- a/clang/include/clang/Driver/Options.td
47+++ b/clang/include/clang/Driver/Options.td
48@@ -1838,10 +1838,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 ce48f8bb132..c5d41667487 100644
81--- a/clang/lib/CodeGen/CGDebugInfo.cpp
82+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
83@@ -470,10 +470,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 67331b65d3b..c88665d269c 100644
102--- a/clang/lib/CodeGen/CGDebugInfo.h
103+++ b/clang/lib/CodeGen/CGDebugInfo.h
104@@ -82,7 +82,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 fc95003e41b..974bc19403c 100644
115--- a/clang/lib/Driver/ToolChains/Clang.cpp
116+++ b/clang/lib/Driver/ToolChains/Clang.cpp
117@@ -613,16 +613,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 disable, while the slp vectorizer is enabled.
149 static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec) {
150@@ -1261,6 +1275,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 55586df9e2f..63d5ebe6984 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 e3d836a0b2c..02a1169772b 100644
200--- a/clang/lib/Driver/ToolChains/Gnu.cpp
201+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
202@@ -804,6 +804,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 bda8427b1a1..0f396d1cc7c 100644
223--- a/clang/lib/Frontend/CompilerInvocation.cpp
224+++ b/clang/lib/Frontend/CompilerInvocation.cpp
225@@ -3084,6 +3084,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 2e9c686b2a0..9e72596145f 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@@ -43,6 +44,7 @@
248 #include "llvm/Support/Casting.h"
249 #include "llvm/Support/ErrorHandling.h"
250 #include "llvm/Support/Format.h"
251+#include "llvm/Support/Path.h"
252 #include "llvm/Support/raw_ostream.h"
253 #include <algorithm>
254 #include <cassert>
255@@ -1455,6 +1457,15 @@ static bool isTargetEnvironment(const TargetInfo &TI,
256 return TI.getTriple().getEnvironment() == Env.getEnvironment();
257 }
258
259+static void remapMacroPath(
260+ SmallString<256> &Path,
261+ const std::map<std::string, std::string, std::greater<std::string>>
262+ &MacroPrefixMap) {
263+ for (const auto &Entry : MacroPrefixMap)
264+ if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
265+ break;
266+}
267+
268 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
269 /// as a builtin macro, handle it and return the next token as 'Tok'.
270 void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
271@@ -1518,10 +1529,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
272 }
273
274 // Escape this filename. Turn '\' -> '\\' '"' -> '\"'
275- SmallString<128> FN;
276+ SmallString<256> FN;
277 if (PLoc.isValid()) {
278 FN += PLoc.getFilename();
279 Lexer::Stringify(FN);
280+ remapMacroPath(FN, PPOpts->MacroPrefixMap);
281 OS << '"' << FN << '"';
282 }
283 Tok.setKind(tok::string_literal);
284diff --git a/clang/test/CodeGen/debug-prefix-map.c b/clang/test/CodeGen/debug-prefix-map.c
285index f755ba47a29..e57808f03f9 100644
286--- a/clang/test/CodeGen/debug-prefix-map.c
287+++ b/clang/test/CodeGen/debug-prefix-map.c
288@@ -2,6 +2,8 @@
289 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-EVIL
290 // 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
291 // 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
292+// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
293+// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
294
295 #include "Inputs/stdio.h"
296
297diff --git a/clang/test/Driver/debug-prefix-map.S b/clang/test/Driver/debug-prefix-map.S
298index 2ba66be0edf..7d12a174797 100644
299--- a/clang/test/Driver/debug-prefix-map.S
300+++ b/clang/test/Driver/debug-prefix-map.S
301@@ -1,4 +1,5 @@
302 // RUN: %clang -### -g -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s
303+// RUN: %clang -### -g -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s
304
305 // CHECK: cc1as
306 // CHECK-SAME: -fdebug-prefix-map=old=new
307diff --git a/clang/test/Driver/debug-prefix-map.c b/clang/test/Driver/debug-prefix-map.c
308index b4f3859f982..f2c87cb7c11 100644
309--- a/clang/test/Driver/debug-prefix-map.c
310+++ b/clang/test/Driver/debug-prefix-map.c
311@@ -1,9 +1,28 @@
312-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
313-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
314-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
315-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
316-
317-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
318-// CHECK-SIMPLE: fdebug-prefix-map=old=new
319-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
320-// CHECK-EMPTY: fdebug-prefix-map=old=
321+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
322+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
323+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
324+
325+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
326+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
327+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
328+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
329+
330+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
331+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
332+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
333+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
334+
335+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
336+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
337+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
338+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
339+
340+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
341+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
342+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
343+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
344+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
345+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
346+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
347+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
348+// CHECK-MACRO-EMPTY: fmacro-prefix-map=old=
349diff --git a/clang/test/Preprocessor/file_test.c b/clang/test/Preprocessor/file_test.c
350new file mode 100644
351index 00000000000..bdc5f1df659
352--- /dev/null
353+++ b/clang/test/Preprocessor/file_test.c
354@@ -0,0 +1,22 @@
355+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
356+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
357+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
358+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
359+
360+filename: __FILE__
361+#include "file_test.h"
362+
363+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
364+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
365+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
366+// CHECK-NOT: filename:
367+
368+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
369+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
370+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
371+// CHECK-EVIL-NOT: filename:
372+
373+// CHECK-REMOVE: filename: "file_test.c"
374+// CHECK-REMOVE: filename: "file_test.h"
375+// CHECK-REMOVE: basefile: "file_test.c"
376+// CHECK-REMOVE-NOT: filename:
377diff --git a/clang/test/Preprocessor/file_test.h b/clang/test/Preprocessor/file_test.h
378new file mode 100644
379index 00000000000..c289e5c8362
380--- /dev/null
381+++ b/clang/test/Preprocessor/file_test.h
382@@ -0,0 +1,2 @@
383+filename: __FILE__
384+basefile: __BASE_FILE__
385--
3862.20.1
387
diff --git a/recipes-devtools/clang/common.inc b/recipes-devtools/clang/common.inc
index f2c5d74..fec78fb 100644
--- a/recipes-devtools/clang/common.inc
+++ b/recipes-devtools/clang/common.inc
@@ -26,6 +26,8 @@ SRC_URI = "\
26 file://0016-compiler-rt-support-a-new-embedded-linux-target.patch \ 26 file://0016-compiler-rt-support-a-new-embedded-linux-target.patch \
27 file://0017-compiler-rt-Simplify-cross-compilation.-Don-t-use-na.patch \ 27 file://0017-compiler-rt-Simplify-cross-compilation.-Don-t-use-na.patch \
28 file://0018-compiler-rt-Disable-tsan-on-OE-glibc.patch \ 28 file://0018-compiler-rt-Disable-tsan-on-OE-glibc.patch \
29 file://0019-llvm-Enhance-path-prefix-mapping.patch \
30 file://0020-clang-Initial-implementation-of-fmacro-prefix-map-an.patch \
29" 31"
30 32
31# Fallback to no-PIE if not set 33# Fallback to no-PIE if not set