diff options
author | Alan Zhao <ayzhao@google.com> | 2022-05-11 22:54:09 +0200 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2022-05-11 23:04:36 +0200 |
commit | 6398f3f2e9045cb38c73425fcc4dddbfb8933a57 (patch) | |
tree | c8ce32d2b82f39c5e33e9918df9d3f985669b430 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 772b0c44a4296a34cbc072c2a7cf294410d07a1a (diff) | |
download | llvm-6398f3f2e9045cb38c73425fcc4dddbfb8933a57.zip llvm-6398f3f2e9045cb38c73425fcc4dddbfb8933a57.tar.gz llvm-6398f3f2e9045cb38c73425fcc4dddbfb8933a57.tar.bz2 |
[clang] Add the flag -ffile-reproducible
When Clang generates the path prefix (i.e. the path of the directory
where the file is) when generating FILE, __builtin_FILE(), and
std::source_location, Clang uses the platform-specific path separator
character of the build environment where Clang _itself_ is built. This
leads to inconsistencies in Chrome builds where Clang running on
non-Windows environments uses the forward slash (/) path separator
while Clang running on Windows builds uses the backslash (\) path
separator. To fix this, we add a flag -ffile-reproducible (and its
inverse, -fno-file-reproducible) to have Clang use the target's
platform-specific file separator character.
Additionally, the existing flags -fmacro-prefix-map and
-ffile-prefix-map now both imply -ffile-reproducible. This can be
overriden by setting -fno-file-reproducible.
[0]: https://crbug.com/1310767
Differential revision: https://reviews.llvm.org/D122766
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 2e205f34..88125da 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3541,6 +3541,11 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts, else GenerateArg(Args, OPT_fno_experimental_relative_cxx_abi_vtables, SA); + if (Opts.UseTargetPathSeparator) + GenerateArg(Args, OPT_ffile_reproducible, SA); + else + GenerateArg(Args, OPT_fno_file_reproducible, SA); + for (const auto &MP : Opts.MacroPrefixMap) GenerateArg(Args, OPT_fmacro_prefix_map_EQ, MP.first + "=" + MP.second, SA); @@ -4072,6 +4077,12 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, {std::string(Split.first), std::string(Split.second)}); } + Opts.UseTargetPathSeparator = + !Args.getLastArg(OPT_fno_file_reproducible) && + (Args.getLastArg(OPT_ffile_compilation_dir_EQ) || + Args.getLastArg(OPT_fmacro_prefix_map_EQ) || + Args.getLastArg(OPT_ffile_reproducible)); + // Error if -mvscale-min is unbounded. if (Arg *A = Args.getLastArg(options::OPT_mvscale_min_EQ)) { unsigned VScaleMin; |