[clang] [clang-tools-extra] [Tooling] Resolve relative "directory" against the compilation database (PR #235400)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 21:32:42 PST 2026
================
@@ -409,19 +412,26 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
ErrorMessage = "Missing key: \"directory\".";
return false;
}
+ SmallString<8> DirectoryStorage;
+ SmallString<128> DirectoryPath(Directory->getValue(DirectoryStorage));
+ if (!BaseDirectory.empty() && !DirectoryPath.empty() &&
+ !llvm::sys::path::is_absolute(DirectoryPath)) {
+ llvm::sys::path::make_absolute(BaseDirectory, DirectoryPath);
+ llvm::sys::path::remove_dots(DirectoryPath);
----------------
MaskRay wrote:
I'd keep `..` here.
```
proj/link -> ../real/build
proj/link/compile_commands.json # "directory": "../out"
real/out/a.c
```
The OS resolves `proj/link/../out` by following the symlink first, so it reaches `real/out`, the correct directory. `remove_dot_dot=true` rewrites the path to `proj/out`, which doesn't exist, and ClangTool aborts with Cannot chdir.
https://github.com/llvm/llvm-project/pull/235400
More information about the cfe-commits
mailing list