<div dir="ltr">+Sam who's been doing a fair bit with clang-tidy recently (Sam, feel free to add Manuel, Daniel, whomever else might be more appropriate if you prefer)<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 19, 2015 at 2:57 PM, Johann Klähn <span dir="ltr"><<a href="mailto:kljohann@gmail.com" target="_blank">kljohann@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clang-tidy seems to have problems with relative paths in command lines<br>
in compile_commands.json.<br>
<br>
Consider the following case:<br>
<br>
$ cat > test.cpp<br>
int main(int argc, char* argv[]) {<br>
    return 0;<br>
}<br>
$ cat > compile_commands.json<br>
[<br>
{<br>
  "directory": "/home/kljohann/test/build",<br>
  "command": "/usr/bin/clang++ -Wunused-parameter -o test.cpp.o -c ../test.cpp",<br>
  "file": "/home/kljohann/test/test.cpp"<br>
}<br>
]<br>
$ mkdir build<br>
$ clang-tidy test.cpp<br>
2 warnings generated.<br>
clang-tidy: ../tools/clang/lib/Basic/SourceManager.cpp:422: const<br>
clang::SrcMgr::ContentCache*<br>
clang::SourceManager::getOrCreateContentCache(const clang::FileEntry*,<br>
bool): Assertion `FileEnt && "Didn't specify a file entry to use?"'<br>
failed.<br>
[1]    23129 abort      clang-tidy test.cpp<br>
<br>
My guess is the following: In ClangTool::run we chdir() into the<br>
"directory" that is specified in compile_commands.json. Then, the<br>
relative file name is stored in ClangTidyMessage (I checked that this<br>
is the case using gdb). Eventually handleErrors() is called, but by<br>
then we already chdired back and thus in ErrorReporter::getLocation<br>
  const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);<br>
is a null pointer (checked using gdb).<br>
On the other hand this is my first venture into the clang source code,<br>
so I may very well be wrong. I hope you can reproduce this bug.<br></blockquote><div><br>Yeah, I can reproduce this. I know little about clang-tidy and what the expected behavior is here - certainly crashing isn't ideal, but even beyond that I'm not sure if the assumption is taht all the paths in the compile commands database will be absolute, or relative to some specific place, etc.<br><br>The CMake compilation database support seems to create databases with all absolute paths so I imagine this doesn't come up there.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
All the best,<br>
Johann<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>