[llvm] [DiagnosticInfo] Output full file path instead of relative path (PR #68027)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 08:48:06 PDT 2023


CongzheUalberta wrote:

> Member

Thanks for the comment. I think it is worthwhile clarifying the motivation of this patch a bit. Similar to what you've been meaning to do for Fuchsia, we are also doing "emit, store, and analyze optimization remarks". The problem we found during the process is that we used LTO, and the optimization remark dump at the preLTO stage and the LTO stage are not consistent in the sense that remarks at the preLTO stage output absolute file path and remarks at LTO stage output relative file path. So it is inconsistent behavior at the first place, and what this patch did is to make the behavior consistent. I've modified the summary accordingly.

Regarding supporting both modes: If necessary I can add an option that switch between the "relative path" mode and the "absolute path" mode. The code will look like the following. Would you like me to make such changes?

```
std::string DiagnosticInfoWithLocationBase::getLocationStr() const {
  StringRef Filename("<unknown>");
  unsigned Line = 0;
  unsigned Column = 0;
  if (isLocationAvailable()) {
    getLocation(Filename, Line, Column);
    if (FullPathMode)
      return (getAbsolutePath() + ":" + Twine(Line) + ":" + Twine(Column)).str();    
  }
  return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
}
```

https://github.com/llvm/llvm-project/pull/68027


More information about the llvm-commits mailing list