Skip to content

Assure DIFiles get the directory name during IRCodeGen #22624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Assure DIFiles get the directory name during IRCodeGen #22624

wants to merge 1 commit into from

Conversation

lanza
Copy link
Contributor

@lanza lanza commented Feb 14, 2019

PDB generation assumes DIFiles have both a filename and a directory.
IRGenDebugInfoImpl currently checks if an absolute path is given for
the Filename and if not it just moves forward with only the filename
which causes PDB generation to be broken.

Clang handles a non absolute path for a file by by first querying the
DebugCompilationDir then the IGM.CWDName and lastly just getting
llvm::sys::fs::current_path. We should do the same here.

@lanza
Copy link
Contributor Author

lanza commented Feb 14, 2019

@swift-ci please test


if (!CWDName.empty())
return CWDName;
SmallString<256> CWD;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline before this line would be nice.

PDB generation assumes DIFiles have both a filename and a directory.
IRGenDebugInfoImpl currently checks if an absolute path is given for
the Filename and if not it just moves forward with only the filename
which causes PDB generation to be broken.

Clang handles a non absolute path for a file by by first querying the
DebugCompilationDir then the IGM.CWDName and lastly just getting
llvm::sys::fs::current_path. We should do the same here.
Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right place to call current_path. Instead, we should make sure that the frontend or driver is setting IGM.getOptions().DebugCompilationDir correctly.

@adrian-prantl
Copy link
Contributor

Is that feasible?

@compnerd
Copy link
Member

@adrian-prantl, hmm... the frontend already does that if you are asking for more than line tables.

  if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables) {
    llvm::SmallString<256> cwd;
    llvm:;sys::fs::current_path(cwd);
    Opts.DebugCompilationDir = cwd.str();
  }

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7334a18d2434715094ee43abc1e6db2cfc49a17e

@compnerd
Copy link
Member

Okay, so that is the DI for the synthetic main that the compiler will emit that causes the invalid DI. I think that this is the correct way to handle that @adrian-prantl

@compnerd
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7334a18d2434715094ee43abc1e6db2cfc49a17e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - dbe88b9

@adrian-prantl
Copy link
Contributor

@compnerd I'm confused. If the frontend is always setting Opts.DebugCompilationDir, why do we need to query llvm::sys::fs again here?

@compnerd
Copy link
Member

@adrian-prantl the frontend is setting it for the user requested compilation. This is the synthetic (compiler generated) [in memory] buffer that has the compiler provided main function. This is constructed in a synthetic file <compiler-generated> which does not have a compiler directory set. In such a case, the current directory is what we should be setting the directory to for the debug metadata.

@lanza
Copy link
Contributor Author

lanza commented Feb 15, 2019

In lib/FrontEnd/CompilerInvocation.cpp we have

if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables) {
  if (Args.hasArg(options::OPT_debug_info_store_invocation)) {
    ArgStringList RenderedArgs;
    for (auto A : Args)
      A->render(Args, RenderedArgs);
    CompilerInvocation::buildDebugFlags(Opts.DebugFlags,
                                        RenderedArgs, SDKPath,
                                        ResourceDir);
  }
  // TODO: Should we support -fdebug-compilation-dir?
  llvm::SmallString<256> cwd;
  llvm::sys::fs::current_path(cwd);
  Opts.DebugCompilationDir = cwd.str();
}

so this seems to still be necessary regardless.

@adrian-prantl
Copy link
Contributor

Oh, is the problem that the <compiler-generated> file doesn't have a directory but in PDB it needs one?

I still have this unmerged patch over in #22392 which brings Swift closer to Clang and it specifically handles these placeholder files differently. That patch makes every file path absolute except for <compiler-generated>. IIUC, all you really need is to disable that exception when building for PDB?

@adrian-prantl
Copy link
Contributor

Basically all you should need to do is add special handling for the PDB case here

      File = RemappedFile;
       // Leave <compiler-generated> & friends as is, without directory.
       if (!(File.startswith("<") && File.endswith(">")))
         Dir = CurDir;
     }

and substitute Opts.DebugCompilationDir

@compnerd
Copy link
Member

Not sure that I like the way that we identify the synthetic file, but sounds like your suggestion should do the trick.

@adrian-prantl
Copy link
Contributor

Agreed. A synthetic bit on the SourceLocation would be more robust.

@lanza
Copy link
Contributor Author

lanza commented Mar 11, 2019

Solved via adrian-prantl's patch.

@lanza lanza closed this Mar 11, 2019
@lanza lanza deleted the pdbpath branch March 11, 2019 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants