Hi Nico,

The test you added in cfe/trunk/test/Driver/clang_f_opts.c fails if a target 
does not use the integrated assembler. You can see what happens if you add 
"-fno-integrated-as" to the command line:

/home/dyung/src/upstream/363548-linux/bin/clang -### -fno-integrated-as 
-fdebug-compilation-dir . -x assembler clang_f_opts.c
clang version 9.0.0 (trunk 363548)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dyung/src/upstream/363548-linux/bin
clang-9: warning: argument unused during compilation: '-fdebug-compilation-dir 
.' [-Wunused-command-line-argument]
 "/usr/bin/as" "--64" "-o" "/tmp/clang_f_opts-f2e231.o" "clang_f_opts.c"
 "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" 
"elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "a.out" 
"/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o" 
"/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o" 
"/usr/lib/gcc/x86_64-linux-gnu/8/crtbegin.o" 
"-L/usr/lib/gcc/x86_64-linux-gnu/8" 
"-L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu" 
"-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" 
"-L/usr/lib/gcc/x86_64-linux-gnu/8/../../.." 
"-L/home/dyung/src/upstream/363548-linux/bin/../lib" "-L/lib" "-L/usr/lib" 
"/tmp/clang_f_opts-f2e231.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" 
"-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" 
"/usr/lib/gcc/x86_64-linux-gnu/8/crtend.o" 
"/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o"

Can you take a look to see if you can fix the test to work if a target does not 
use the integrated assembler?

Douglas Yung

-----Original Message-----
From: cfe-commits <cfe-commits-boun...@lists.llvm.org> On Behalf Of Nico Weber 
via cfe-commits
Sent: Monday, June 17, 2019 5:11
To: cfe-commits@lists.llvm.org
Subject: r363548 - Promote -fdebug-compilation-dir from a cc1 flag to clang and 
clang-cl driver flags

Author: nico
Date: Mon Jun 17 05:10:40 2019
New Revision: 363548

URL: http://llvm.org/viewvc/llvm-project?rev=363548&view=rev
Log:
Promote -fdebug-compilation-dir from a cc1 flag to clang and clang-cl driver 
flags

The flag is useful when wanting to create .o files that are independent from 
the absolute path to the build directory. -fdebug-prefix-map= can be used to 
the same effect, but it requires putting the absolute path to the build 
directory on the build command line, so it still requires the build command 
line to be dependent on the absolute path of the build directory. With this 
flag, "-fdebug-compilation-dir ." makes it so that both debug info and the 
compile command itself are independent of the absolute path of the build 
directory, which is good for build determinism (in the sense that the build is 
independent of which directory it happens in) and for caching compile results.
(The tradeoff is that the debugger needs explicit configuration to know the 
build directory. See also http://dwarfstd.org/ShowIssue.php?issue=171130.2)

Differential Revision: https://reviews.llvm.org/D63387

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/test/Driver/cl-options.c
    cfe/trunk/test/Driver/clang_f_opts.c

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=363548&r1=363547&r2=363548&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jun 17 05:10:40 
+++ 2019
@@ -190,8 +190,6 @@ def default_function_attr : Separate<["-
   HelpText<"Apply given attribute to all functions">;  def dwarf_version_EQ : 
Joined<["-"], "dwarf-version=">;  def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">; -def fdebug_compilation_dir : Separate<["-"], 
"fdebug-compilation-dir">,
-  HelpText<"The compilation directory to embed in the debug info.">;  def 
dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;  def 
record_command_line : Separate<["-"], "record-command-line">,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=363548&r1=363547&r2=363548&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Jun 17 05:10:40 2019
@@ -713,11 +713,14 @@ def fauto_profile_accurate : Flag<["-"],
     Group<f_Group>, Alias<fprofile_sample_accurate>;  def 
fno_auto_profile_accurate : Flag<["-"], "fno-auto-profile-accurate">,
     Group<f_Group>, Alias<fno_profile_sample_accurate>;
-def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, 
Group<f_Group>,
-    Flags<[CC1Option]>,
+def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
+    Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>,
+    HelpText<"The compilation directory to embed in the debug info.">; 
+def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">,
+    Group<f_Group>, Flags<[CC1Option]>,
     HelpText<"Emit extra debug info to make sample profile more accurate.">; 
-def fno_debug_info_for_profiling : Flag<["-"], 
"fno-debug-info-for-profiling">, Group<f_Group>,
-    Flags<[DriverOption]>,
+def fno_debug_info_for_profiling : Flag<["-"], "fno-debug-info-for-profiling">,
+    Group<f_Group>, Flags<[DriverOption]>,
     HelpText<"Do not emit extra debug info for sample profiler.">;  def 
fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
     Group<f_Group>, Flags<[CoreOption]>,

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=363548&r1=363547&r2=363548&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jun 17 05:10:40 2019
@@ -618,7 +618,11 @@ static bool shouldUseLeafFramePointer(co  /// Add a CC1 
option to specify the debug compilation directory.
 static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs,
                                const llvm::vfs::FileSystem &VFS) {
-  if (llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory()) {
+  if (Arg *A = Args.getLastArg(options::OPT_fdebug_compilation_dir)) {
+    CmdArgs.push_back("-fdebug-compilation-dir");
+    CmdArgs.push_back(A->getValue());
+  } else if (llvm::ErrorOr<std::string> CWD =
+                 VFS.getCurrentWorkingDirectory()) {
     CmdArgs.push_back("-fdebug-compilation-dir");
     CmdArgs.push_back(Args.MakeArgString(*CWD));
   }
@@ -637,7 +641,8 @@ static void addDebugPrefixMapArg(const D  }
 
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
-/// For -Oz the loop vectorizer is disable, while the slp vectorizer is 
enabled.
+/// For -Oz the loop vectorizer is disabled, while the slp vectorizer 
+is /// enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec) 
{
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
     if (A->getOption().matches(options::OPT_O4) ||

Modified: cfe/trunk/test/Driver/cl-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=363548&r1=363547&r2=363548&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Mon Jun 17 05:10:40 2019
@@ -619,6 +619,7 @@
 // RUN:     -fno-coverage-mapping \
 // RUN:     -fdiagnostics-color \
 // RUN:     -fno-diagnostics-color \
+// RUN:     -fdebug-compilation-dir . \
 // RUN:     -fdiagnostics-parseable-fixits \
 // RUN:     -fdiagnostics-absolute-paths \
 // RUN:     -ferror-limit=10 \

Modified: cfe/trunk/test/Driver/clang_f_opts.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=363548&r1=363547&r2=363548&view=diff
==============================================================================
--- cfe/trunk/test/Driver/clang_f_opts.c (original)
+++ cfe/trunk/test/Driver/clang_f_opts.c Mon Jun 17 05:10:40 2019
@@ -525,11 +525,15 @@
 // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch  // 
CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch
 
+// 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 // CHECK-DEBUG-COMPILATION-DIR: 
"-fdebug-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"
 // CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names"
-//
+
 // RUN: %clang -### -S -fmerge-all-constants %s 2>&1 | FileCheck 
-check-prefix=CHECK-MERGE-ALL-CONSTANTS %s  // RUN: %clang -### -S 
-fno-merge-all-constants %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-MERGE-ALL-CONSTANTS %s  // RUN: %clang -### -S 
-fmerge-all-constants -fno-merge-all-constants %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-MERGE-ALL-CONSTANTS %s


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

Reply via email to