[PATCH] D97433: [Driver] Create -ffile-compilation-dir alias

2021-02-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: MaskRay, rnk.
Herald added subscribers: jansvoboda11, dang.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97433

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/debug-info-compilation-dir.c
  clang/test/CodeGen/profile-compilation-dir.c
  clang/test/Driver/clang_f_opts.c
  clang/tools/driver/cc1as_main.cpp

Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -241,7 +241,8 @@
   Opts.DwarfDebugProducer =
   std::string(Args.getLastArgValue(OPT_dwarf_debug_producer));
   Opts.DebugCompilationDir =
-  std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir));
+  std::string(Args.getLastArgValue(OPT_ffile_compilation_dir,
+   OPT_fdebug_compilation_dir));
   Opts.MainFileName = std::string(Args.getLastArgValue(OPT_main_file_name));
 
   for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) {
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -504,6 +504,8 @@
 // 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 -### -S -ffile-compilation-dir=. %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-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
Index: clang/test/CodeGen/profile-compilation-dir.c
===
--- clang/test/CodeGen/profile-compilation-dir.c
+++ clang/test/CodeGen/profile-compilation-dir.c
@@ -1,6 +1,7 @@
 // RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: cp %s rel.c
 // RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-compilation-dir=/nonsense -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -ffile-compilation-dir=/nonsense -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
 
 // CHECK-NONSENSE: nonsense
 
Index: clang/test/CodeGen/debug-info-compilation-dir.c
===
--- clang/test/CodeGen/debug-info-compilation-dir.c
+++ clang/test/CodeGen/debug-info-compilation-dir.c
@@ -2,6 +2,7 @@
 // RUN: cp %s rel.c
 // RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm -debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
 // RUN: %clang_cc1 -fdebug-compilation-dir=/nonsense -emit-llvm -debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
+// RUN: %clang_cc1 -ffile-compilation-dir=/nonsense -emit-llvm -debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
 // CHECK-NONSENSE: nonsense
 
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-DIR %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1011,7 +1011,8 @@
   } else {
 // Use the compilation dir.
 SmallString<128> T(
-Args.getLastArgValue(options::OPT_fdebug_compilation_dir_EQ));
+Args.getLastArgValue(options::OPT_ffile_compilation_dir_EQ,
+ options::OPT_fdebug_compilation_dir_EQ));
 SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
 AddPostfix(F);
 T += F;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -618,7 +618,8 @@
 /// Add a CC1 option to specify the debug compilation directory.
 static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs,
  

[PATCH] D97433: [Driver] Create -ffile-compilation-dir alias

2021-02-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 326269.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97433/new/

https://reviews.llvm.org/D97433

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/clang_f_opts.c
  clang/tools/driver/cc1as_main.cpp


Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -240,8 +240,9 @@
   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)) {
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ 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"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1010,12 +1010,13 @@
 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);
   }
 }
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -618,7 +618,8 @@
 /// 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 @@
 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()) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1112,6 +1112,8 @@
 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 compi

[PATCH] D97433: [Driver] Create -ffile-compilation-dir alias

2021-02-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97433/new/

https://reviews.llvm.org/D97433

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97433: [Driver] Create -ffile-compilation-dir alias

2021-02-25 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e56a093eeca: [Driver] Create -ffile-compilation-dir alias 
(authored by phosek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97433/new/

https://reviews.llvm.org/D97433

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/clang_f_opts.c
  clang/tools/driver/cc1as_main.cpp


Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -240,8 +240,9 @@
   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)) {
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ 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"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1010,12 +1010,13 @@
 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);
   }
 }
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -618,7 +618,8 @@
 /// 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 @@
 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()) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1106,6 +1106,8 @@
 Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
 HelpText<"The compilation directory to embed in the coverage mapping.">,