[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
Sat Oct 24 23:05:45 PDT 2026
MaskRay wrote:
Current behavior with a relative "directory", for reference.
```
proj/compile_commands.json -> build/compile_commands.json
proj/build/compile_commands.json
proj/build/include/config.h
proj/src/a.c # #include "config.h"
[{"directory": ".", "arguments": ["clang", "-Iinclude", "-c", "../src/a.c", "-o", "a.o"], "file": "../src/a.c"}]
```
Before this patch:
```
$ clang-check -p proj/build proj/src/a.c
Skipping /tmp/t/compdb/proj/src/a.c. Compile command not found.
$ clangd --check=proj/src/a.c
Loaded compilation database from /tmp/t/compdb/proj/compile_commands.json
Generic fallback command is: [/tmp/t/compdb/proj/src] /usr/bin/clang -resource-dir=... -- /tmp/t/compdb/proj/src/a.c
[pp_file_not_found] Line 1: 'config.h' file not found
All checks completed, 2 errors
```
After this patch:
```
$ clang-check -p proj/build proj/src/a.c # exit 0
$ clang-check -p proj proj/src/a.c # exit 0, via the symlink
$ clangd --check=proj/src/a.c
Compile command from CDB is: [/tmp/t/compdb/proj/build] /usr/bin/clang -Iinclude -c -o a.o -resource-dir=... -- /tmp/t/compdb/proj/src/a.c
All checks completed, 0 errors
```
https://github.com/llvm/llvm-project/pull/235400
More information about the cfe-commits
mailing list