[cfe-commits] r142633 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CGDebugInfo.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/debug-info-compilation-dir.c test/Driver/debug.c

Chad Rosier mcrosier at apple.com
Thu Mar 28 10:24:43 PDT 2013


Hi Nick,
I've run into a bug with -fdebug-compilation-dir and I was hoping you could help me come up with a solution.
Specifically, could tell me how gcc behaves when stat(pwd) and stat(.) differ?  I'm running into this very case.  If
you need a test case, I'd be happy to provide one.  Also, do you know why gcc prefers ::getenv("PWD") as
opposed to something like getcwd()?

 Chad


On Oct 20, 2011, at 7:32 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Author: nicholas
> Date: Thu Oct 20 21:32:14 2011
> New Revision: 142633
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=142633&view=rev
> Log:
> Take DW_AT_comp_dir from $PWD when it's present and starts with a '/'. This is
> closer to what GCC does, except that GCC also checks that the inodes for $PWD
> and '.' match.
> 
> Added:
>    cfe/trunk/test/CodeGen/debug-info-compilation-dir.c
>    cfe/trunk/test/Driver/debug.c
> Modified:
>    cfe/trunk/include/clang/Driver/CC1Options.td
>    cfe/trunk/include/clang/Frontend/CodeGenOptions.h
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>    cfe/trunk/lib/Driver/Tools.cpp
>    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> 
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=142633&r1=142632&r2=142633&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Oct 20 21:32:14 2011
> @@ -110,6 +110,8 @@
>   HelpText<"Don't run the LLVM IR verifier pass">;
> def disable_red_zone : Flag<"-disable-red-zone">,
>   HelpText<"Do not emit code that uses the red zone.">;
> +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 fforbid_guard_variables : Flag<"-fforbid-guard-variables">,
> 
> Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=142633&r1=142632&r2=142633&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Thu Oct 20 21:32:14 2011
> @@ -115,6 +115,9 @@
>   /// Enable additional debugging information.
>   std::string DebugPass;
> 
> +  /// The string to embed in debug information as the current working directory.
> +  std::string DebugCompilationDir;
> +
>   /// The string to embed in the debug information for the compile unit, if
>   /// non-empty.
>   std::string DwarfDebugFlags;
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=142633&r1=142632&r2=142633&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Oct 20 21:32:14 2011
> @@ -250,6 +250,9 @@
> }
> 
> StringRef CGDebugInfo::getCurrentDirname() {
> +  if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
> +    return CGM.getCodeGenOpts().DebugCompilationDir;
> +
>   if (!CWDName.empty())
>     return CWDName;
>   llvm::SmallString<256> CWD;
> 
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=142633&r1=142632&r2=142633&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Thu Oct 20 21:32:14 2011
> @@ -1625,6 +1625,16 @@
>   if (ShouldDisableDwarfDirectory(Args, getToolChain()))
>     CmdArgs.push_back("-fno-dwarf-directory-asm");
> 
> +  if (const char *pwd = ::getenv("PWD")) {
> +    // GCC also verifies that stat(pwd) and stat(".") have the same inode
> +    // number. Not doing those because stats are slow, but we could.
> +    if (pwd[0] == '/') {
> +      std::string CompDir = pwd;
> +      CmdArgs.push_back("-fdebug-compilation-dir");
> +      CmdArgs.push_back(Args.MakeArgString(CompDir));
> +    }
> +  }
> +
>   if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
>     CmdArgs.push_back("-ftemplate-depth");
>     CmdArgs.push_back(A->getValue(Args));
> 
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=142633&r1=142632&r2=142633&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Oct 20 21:32:14 2011
> @@ -131,6 +131,10 @@
>     Res.push_back("-disable-llvm-optzns");
>   if (Opts.DisableRedZone)
>     Res.push_back("-disable-red-zone");
> +  if (!Opts.DebugCompilationDir.empty()) {
> +    Res.push_back("-fdebug-compilation-dir");
> +    Res.push_back(Opts.DebugCompilationDir);
> +  }
>   if (!Opts.DwarfDebugFlags.empty()) {
>     Res.push_back("-dwarf-debug-flags");
>     Res.push_back(Opts.DwarfDebugFlags);
> @@ -1071,6 +1075,7 @@
>   Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
>   Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
>   Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
> +  Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
> 
>   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
>     StringRef Name = A->getValue(Args);
> 
> Added: cfe/trunk/test/CodeGen/debug-info-compilation-dir.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-compilation-dir.c?rev=142633&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/debug-info-compilation-dir.c (added)
> +++ cfe/trunk/test/CodeGen/debug-info-compilation-dir.c Thu Oct 20 21:32:14 2011
> @@ -0,0 +1,4 @@
> +// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm -g %s -o - | \
> +// RUN:   grep nonsense
> +
> +// RUN: %clang_cc1 -emit-llvm -g %s -o - | grep %S
> 
> Added: cfe/trunk/test/Driver/debug.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug.c?rev=142633&view=auto
> ==============================================================================
> --- cfe/trunk/test/Driver/debug.c (added)
> +++ cfe/trunk/test/Driver/debug.c Thu Oct 20 21:32:14 2011
> @@ -0,0 +1,8 @@
> +// RUN: %clang -### -g %s -c 2>&1 | grep '"-fdebug-compilation-dir" "'%S'"'
> +// RUN: PWD=/foo %clang -### -g %s -c 2>&1 | grep '"-fdebug-compilation-dir" "/foo"'
> +
> +// This test uses grep instead of FileCheck so that we get %S -> dirname
> +// substitution.
> +
> +// "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different
> +// path to the same directory (try a symlink).
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130328/3b0f179a/attachment.html>


More information about the cfe-commits mailing list