From 6398f3f2e9045cb38c73425fcc4dddbfb8933a57 Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Wed, 11 May 2022 22:54:09 +0200 Subject: [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 --- clang/lib/Frontend/CompilerInvocation.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') 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; -- cgit v1.1