<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Nick,<div>I've run into a bug with -fdebug-compilation-dir and I was hoping you could help me come up with a solution.</div><div>Specifically, could tell me how gcc behaves when stat(pwd) and stat(.) differ? I'm running into this very case. If</div><div>you need a test case, I'd be happy to provide one. Also, do you know why gcc prefers ::getenv("PWD") as</div><div>opposed to something like getcwd()?</div><div><br></div><div> Chad</div><div><br></div><div><br><div><div>On Oct 20, 2011, at 7:32 PM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Author: nicholas<br>Date: Thu Oct 20 21:32:14 2011<br>New Revision: 142633<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=142633&view=rev">http://llvm.org/viewvc/llvm-project?rev=142633&view=rev</a><br>Log:<br>Take DW_AT_comp_dir from $PWD when it's present and starts with a '/'. This is<br>closer to what GCC does, except that GCC also checks that the inodes for $PWD<br>and '.' match.<br><br>Added:<br> cfe/trunk/test/CodeGen/debug-info-compilation-dir.c<br> cfe/trunk/test/Driver/debug.c<br>Modified:<br> cfe/trunk/include/clang/Driver/CC1Options.td<br> cfe/trunk/include/clang/Frontend/CodeGenOptions.h<br> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br> cfe/trunk/lib/Driver/Tools.cpp<br> cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br><br>Modified: cfe/trunk/include/clang/Driver/CC1Options.td<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=142633&r1=142632&r2=142633&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=142633&r1=142632&r2=142633&view=diff</a><br>==============================================================================<br>--- cfe/trunk/include/clang/Driver/CC1Options.td (original)<br>+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Oct 20 21:32:14 2011<br>@@ -110,6 +110,8 @@<br> HelpText<"Don't run the LLVM IR verifier pass">;<br>def disable_red_zone : Flag<"-disable-red-zone">,<br> HelpText<"Do not emit code that uses the red zone.">;<br>+def fdebug_compilation_dir : Separate<"-fdebug-compilation-dir">,<br>+ HelpText<"The compilation directory to embed in the debug info.">;<br>def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,<br> HelpText<"The string to embed in the Dwarf debug flags record.">;<br>def fforbid_guard_variables : Flag<"-fforbid-guard-variables">,<br><br>Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=142633&r1=142632&r2=142633&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=142633&r1=142632&r2=142633&view=diff</a><br>==============================================================================<br>--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)<br>+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Thu Oct 20 21:32:14 2011<br>@@ -115,6 +115,9 @@<br> /// Enable additional debugging information.<br> std::string DebugPass;<br><br>+ /// The string to embed in debug information as the current working directory.<br>+ std::string DebugCompilationDir;<br>+<br> /// The string to embed in the debug information for the compile unit, if<br> /// non-empty.<br> std::string DwarfDebugFlags;<br><br>Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=142633&r1=142632&r2=142633&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=142633&r1=142632&r2=142633&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Oct 20 21:32:14 2011<br>@@ -250,6 +250,9 @@<br>}<br><br>StringRef CGDebugInfo::getCurrentDirname() {<br>+ if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())<br>+ return CGM.getCodeGenOpts().DebugCompilationDir;<br>+<br> if (!CWDName.empty())<br> return CWDName;<br> llvm::SmallString<256> CWD;<br><br>Modified: cfe/trunk/lib/Driver/Tools.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=142633&r1=142632&r2=142633&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=142633&r1=142632&r2=142633&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>+++ cfe/trunk/lib/Driver/Tools.cpp Thu Oct 20 21:32:14 2011<br>@@ -1625,6 +1625,16 @@<br> if (ShouldDisableDwarfDirectory(Args, getToolChain()))<br> CmdArgs.push_back("-fno-dwarf-directory-asm");<br><br>+ if (const char *pwd = ::getenv("PWD")) {<br>+ // GCC also verifies that stat(pwd) and stat(".") have the same inode<br>+ // number. Not doing those because stats are slow, but we could.<br>+ if (pwd[0] == '/') {<br>+ std::string CompDir = pwd;<br>+ CmdArgs.push_back("-fdebug-compilation-dir");<br>+ CmdArgs.push_back(Args.MakeArgString(CompDir));<br>+ }<br>+ }<br>+<br> if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {<br> CmdArgs.push_back("-ftemplate-depth");<br> CmdArgs.push_back(A->getValue(Args));<br><br>Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=142633&r1=142632&r2=142633&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=142633&r1=142632&r2=142633&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Oct 20 21:32:14 2011<br>@@ -131,6 +131,10 @@<br> Res.push_back("-disable-llvm-optzns");<br> if (Opts.DisableRedZone)<br> Res.push_back("-disable-red-zone");<br>+ if (!Opts.DebugCompilationDir.empty()) {<br>+ Res.push_back("-fdebug-compilation-dir");<br>+ Res.push_back(Opts.DebugCompilationDir);<br>+ }<br> if (!Opts.DwarfDebugFlags.empty()) {<br> Res.push_back("-dwarf-debug-flags");<br> Res.push_back(Opts.DwarfDebugFlags);<br>@@ -1071,6 +1075,7 @@<br> Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);<br> Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);<br> Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);<br>+ Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);<br><br> if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {<br> StringRef Name = A->getValue(Args);<br><br>Added: cfe/trunk/test/CodeGen/debug-info-compilation-dir.c<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-compilation-dir.c?rev=142633&view=auto">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-compilation-dir.c?rev=142633&view=auto</a><br>==============================================================================<br>--- cfe/trunk/test/CodeGen/debug-info-compilation-dir.c (added)<br>+++ cfe/trunk/test/CodeGen/debug-info-compilation-dir.c Thu Oct 20 21:32:14 2011<br>@@ -0,0 +1,4 @@<br>+// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm -g %s -o - | \<br>+// RUN: grep nonsense<br>+<br>+// RUN: %clang_cc1 -emit-llvm -g %s -o - | grep %S<br><br>Added: cfe/trunk/test/Driver/debug.c<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug.c?rev=142633&view=auto">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug.c?rev=142633&view=auto</a><br>==============================================================================<br>--- cfe/trunk/test/Driver/debug.c (added)<br>+++ cfe/trunk/test/Driver/debug.c Thu Oct 20 21:32:14 2011<br>@@ -0,0 +1,8 @@<br>+// RUN: %clang -### -g %s -c 2>&1 | grep '"-fdebug-compilation-dir" "'%S'"'<br>+// RUN: PWD=/foo %clang -### -g %s -c 2>&1 | grep '"-fdebug-compilation-dir" "/foo"'<br>+<br>+// This test uses grep instead of FileCheck so that we get %S -> dirname<br>+// substitution.<br>+<br>+// "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different<br>+// path to the same directory (try a symlink).<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div><br></div></body></html>