<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54551>54551</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang diagnostics: carrot and squiggles are sometimes off by one character with -fdiagnostics-print-source-range-info and TABS for indentation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bfrg
</td>
</tr>
</table>
<pre>
The carrots and squiggles are not printed at the correct position when the file uses tabs for indentation and `-fdiagnostics-print-source-range-info` is enabled.
Example:
```cpp
int main(int argc, char* argv[])
{
int arr[] = {1,2,3,4,5};
double sum = 0;
for (int i = 0; i < 5u; ++i)
sum += i;
return sum;
}
```
```
$ clang -Wall -Wextra -fdiagnostics-print-source-range-info test.c
test.c:3:6: warning: unused variable 'arr' [-Wunused-variable]
int arr[] = {1,2,3,4,5};
^
test.c:1:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
^
test.c:1:26: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char* argv[])
^
test.c:6:20:{6:18-6:19}{6:22-6:24}: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
for (int i = 0; i < 5u; ++i)
~ ^ ~~
4 warnings generated.
```
The byte indexes seem to be correct, it's just the carrot and squiggles that are off by one character. It doesn't matter how many levels of indentation, their position is always off by one character. Converting tabs to spaces or omitting the `-fdiagnostics-print-source-range-info` option prints them at the correct position.
Tested with latest clang 15: https://wandbox.org/permlink/yMyfaUii4aqbqmLM
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VU1zmzwQ_jX4soMHC2PMgUOcpDOdaU9Np2cBC1YLkiMJO_733RVOHLvJO8nl9SCzaFerZz_0qDLNsXzYItTSWuMdSN2AexxV1_VIXxZBGw87q7THBqQHz8bGWqxp2jjlldFw2KIOmlb1CKOjpV5WDlpjQekGt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