Issue 184619
Summary [clang-tidy] unable to parse include directory containing trailing backslash
Labels clang-tidy
Assignees
Reporter avolden
    Hello,

I'm trying to run clang-tidy on Windows, with a custom-made compile_commands.json. When compiling the file with the command in my compile_commands.json, everything works well. But when running clang-tidy with the same command in the compile_commands, I get errors that include file cannot be found.

After investigating, I noticed this issue disappear if I convert the include directory backslashes into slashes, or if I remove the trailing backslash of the directory.

I can reproduce this issue easily, with a simple source file containing a -I argument with a directory ending with trailing backslah.

In my repro I have this file hierarchy:
```
├── A
│   └── B
|       └── C
|           └── header.h
├── src
│   └── main.cpp
└── compile_commands.json
```
With header.h containing :
```cpp
#include <stdio.h>
```
main.cpp containing :
```cpp
#include <C/header.h>

int main(int argc, char** argv)
{
	printf("Hello World\n");

	return 0;
}
```
and compile_commands.json containing :
```json
[
	{
		"file": "main.cpp",
		"directory": "C:\\Users\\ava\\Documents\\repro\\src",
		"command": "clang -c C:\\Users\\ava\\Documents\\repro\\src\\main.cpp -I\"C:\\Users\\ava\\Documents\\repro\\A\\B\\\""
	}
]
```
and when running clang-tidy with this setup, I get this output
```
C:\Users\ava\Documents\repro>clang-tidy -p compile_commands.json src\main.cpp
1 error generated.
Error while processing C:\Users\ava\Documents\repro\src\main.cpp.
C:\Users\ava\Documents\repro\src\main.cpp:1:10: error: 'C/header.h' file not found [clang-diagnostic-error]
    1 | #include <C/header.h>
      |          ^~~~~~~~~~~~
Found compiler error(s).
```

I reproduced the issue both in LLVM 21 and LLVM 22
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to