<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58695>58695</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy doesn't respect -fdiagnostics-absolute-paths
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RReverser
      </td>
    </tr>
</table>

<pre>
    A minimal repro:

```bash
mkdir -p dir{1,2}
echo "int foo;" > dir1/module.c
echo "int bar;" > dir2/module.c
cat << EOF > compile_commands.json
[
  {
    "arguments": [
      "cc",
      "-c",
      "-fdiagnostics-absolute-paths",
      "-o",
      "module.o",
      "module.c"
    ],
    "directory": "$PWD/dir1",
    "file": "module.c"
  },
  {
    "arguments": [
      "cc",
      "-c",
      "-fdiagnostics-absolute-paths",
      "-o",
      "module.o",
      "module.c"
    ],
    "directory": "$PWD/dir2",
    "file": "module.c"
  }
]
EOF
run-clang-tidy -checks=-*,cppcoreguidelines-avoid-non-const-global-variables
```

Output:

```
Enabled checks:
    cppcoreguidelines-avoid-non-const-global-variables

clang-tidy-15 -checks=-*,cppcoreguidelines-avoid-non-const-global-variables -p=/home/rreverser/clang-tidy-test /home/rreverser/clang-tidy-test/dir2/module.c
module.c:1:5: warning: variable 'bar' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
int bar;
    ^
1 warning generated.
clang-tidy-15 -checks=-*,cppcoreguidelines-avoid-non-const-global-variables -p=/home/rreverser/clang-tidy-test /home/rreverser/clang-tidy-test/dir1/module.c
module.c:1:5: warning: variable 'foo' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
int foo;
    ^
1 warning generated.
```

You can see that both warnings have a format of `module.c:1:5: `, making it difficult to discern which `module.c` the warning is coming from. While human can look at the compile command, it's a bit less obvious, and harder to integrate with IDE problem matchers. That's where `-fdiagnostics-absolute-paths` in the `compile_commands.json` should've helped, but seems to be ignored.

It's also ignored when passed explicitly via `-extra-arg`, but then, interestingly, it does work as expected when using `clang-tidy` directly and passing Clang parameters via `--`:

```bash
clang-tidy dir{1,2}/module.c -checks=-*,cppcoreguidelines-avoid-non-const-global-variables -- -fdiagnostics-absolute-paths
```

```
1 warning generated.
2 warnings generated.
/home/rreverser/clang-tidy-test/dir1/module.c:1:5: warning: variable 'foo' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
int foo;
    ^
/home/rreverser/clang-tidy-test/dir2/module.c:1:5: warning: variable 'bar' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
int bar;
    ^
```

Of course, the problem with this approach is that it completely ignores the file list and all the other parameters from `compile_commands.json` unless you pass them explicitly after `--` as well. Ideally `run-clang-tidy` should just respect the flags.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztV01v4zYQ_TX2ZSBDpi07OfiQxDGQ0xaLAoueCkqiJCaUKJCUvf73fdSH5ThO2g320C4KODY_hjNvZjhvmFinx80dlbKSJVdkRG30ZHE3CbeTcPhehd0n5rbolsqXVBoKasLPZH0_n7AHNllvu02RFJomjMnKUaah7R4TmiwevTREd6VOGyVmyVvxmJvX4uyNeMIdNh_woccvu1Yu0WUtlfgTvyWvUjt7trrqsUf33YAIOIcheXvc5E0pKmcxhsd0JtpLJInfYg8Xy8E7y1kqeV5p62RiAx5brRongpq7wl4_oK8u9-5-uNkiGJ2Jtq8ksYnQicRpcxyc88qWv32D4K7LArs8kiGEo_QVQz7B45n_wzmGk302nP0d7Qe4z93ANFWQKF7lgZPpkYKkEMmLnSy2wYTdwVBS14k2Im9kKpSsBOKz1zINKo1zurIuyJWOuQr23EgeK2EvKvm8vL80rm7cezXfI6u8lpQGIHejq5_G0lXzyctgHv0MR0FKOI60FLpE_HfGiL0wVhiMz4w5YUEj_0TqlOELHjrNFndz_EU-0QduKlnlfj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