From 9e56a093eeca15704180cce3a808aec195b331d1 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Wed, 24 Feb 2021 17:48:27 -0800 Subject: [PATCH] [Driver] Create -ffile-compilation-dir alias We introduce -ffile-compilation-dir shorthand to avoid having to set -fdebug-compilation-dir and -fprofile-compilation-dir separately. This is similar to -ffile-prefix-map. Differential Revision: https://reviews.llvm.org/D97433 --- clang/include/clang/Driver/Options.td | 2 ++ clang/lib/Driver/ToolChains/Clang.cpp | 6 ++++-- clang/lib/Driver/ToolChains/CommonArgs.cpp | 7 ++++--- clang/test/Driver/clang_f_opts.c | 5 +++++ clang/tools/driver/cc1as_main.cpp | 5 +++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2724bab..ccf7d49 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1106,6 +1106,8 @@ def fprofile_compilation_dir_EQ : Joined<["-"], "fprofile-compilation-dir=">, Group, Flags<[CC1Option, CC1AsOption, CoreOption]>, HelpText<"The compilation directory to embed in the coverage mapping.">, MarshallingInfoString>; +def ffile_compilation_dir_EQ : Joined<["-"], "ffile-compilation-dir=">, Group, + HelpText<"The compilation directory to embed in the debug info and coverage mapping.">; defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling", CodeGenOpts<"DebugInfoForProfiling">, DefaultFalse, PosFlag, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 471cefd..51063b6 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -618,7 +618,8 @@ getFramePointerKind(const ArgList &Args, const llvm::Triple &Triple) { /// Add a CC1 option to specify the debug compilation directory. static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs, const llvm::vfs::FileSystem &VFS) { - if (Arg *A = Args.getLastArg(options::OPT_fdebug_compilation_dir_EQ)) { + if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, + options::OPT_fdebug_compilation_dir_EQ)) { A->render(Args, CmdArgs); } else if (llvm::ErrorOr CWD = VFS.getCurrentWorkingDirectory()) { @@ -859,7 +860,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, CmdArgs.push_back("-fcoverage-mapping"); } - if (Arg *A = Args.getLastArg(options::OPT_fprofile_compilation_dir_EQ)) { + if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, + options::OPT_fprofile_compilation_dir_EQ)) { A->render(Args, CmdArgs); } else if (llvm::ErrorOr CWD = D.getVFS().getCurrentWorkingDirectory()) { diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index e20b01a..9471639 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1010,12 +1010,13 @@ const char *tools::SplitDebugName(const JobAction &JA, const ArgList &Args, return Args.MakeArgString(T); } else { // Use the compilation dir. - SmallString<128> T( - Args.getLastArgValue(options::OPT_fdebug_compilation_dir_EQ)); + Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, + options::OPT_fdebug_compilation_dir_EQ); + SmallString<128> T(A ? A->getValue() : ""); SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput())); AddPostfix(F); T += F; - return Args.MakeArgString(F); + return Args.MakeArgString(T); } } diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 85758ae..12d59a0 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -504,8 +504,13 @@ // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s // RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s // RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s +// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=." +// RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s +// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s +// CHECK-FILE-COMPILATION-DIR: "-ffile-compilation-dir=." + // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s // CHECK-DISCARD-NAMES: "-discard-value-names" diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 273ae78..84dfb42 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -240,8 +240,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, std::string(Args.getLastArgValue(OPT_dwarf_debug_flags)); Opts.DwarfDebugProducer = std::string(Args.getLastArgValue(OPT_dwarf_debug_producer)); - Opts.DebugCompilationDir = - std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir)); + if (const Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, + options::OPT_fdebug_compilation_dir_EQ)) + Opts.DebugCompilationDir = A->getValue(); Opts.MainFileName = std::string(Args.getLastArgValue(OPT_main_file_name)); for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { -- 2.7.4