<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61839>61839</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
incorrect source location for builtin functions in the clang AST.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hokein
</td>
</tr>
</table>
<pre>
Given the following case:
```
int test(unsigned __x) {
return __builtin_popcount(1); // line 2
}
int test2(unsigned __x) {
return __builtin_popcount(1);
}
void foo() {
__builtin^_popcount(1ul); // calling go-to-definition in clangd will jump to line2.
}
```
The `__builtin_popcount` FunctionDecl looks like, its source location points to the first call site (line 2, col 10). The source location is suspicious (I think it should be an invalid source loc).
```
`-FunctionDecl 0x560139b6dd20 <col:10> col:10 implicit used __builtin_popcount 'int (unsigned int) noexcept' extern
| |-ParmVarDecl 0x560139b6de20 <<invalid sloc>> <invalid sloc> 'unsigned int'
| |-BuiltinAttr 0x560139b6ddc8 <<invalid sloc>> Implicit 378
| |-NoThrowAttr 0x560139b6de90 <col:10> Implicit
| `-ConstAttr 0x560139b6deb8 <col:10> Implicit
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVEtv4zYQ_jXUZWCDIm09Djo4TlzspSjQoFdDoihrNjRH4CNJ_31B2d5U9hZbwCBNgfM9ZobTeo8nq3XDtk9s-5y1MYzkmpHeNNqso_7v5jd81xbCqGEgY-gD7QlU6zWTO8afGb-tBb_-5iPaAEH7wEQV7czRw_H4yUQNwMonuNwCcDpEZ-F47CKagPY40aQo2hSYM1Ez-QRMHJg4gEGrQVzZyuclj_gF0f_guUO-rO-EPQxETFQJkpXXa19IbPuyAItmKVu1xqScnWgVaNXrAS0GJAtoQZnWnnr4QGPgezxPEGi2Kdb3YpbZvayvowZW8J94KjgcolWJ5lkrA4bozYPBN83EHjB48BSd0mBItbOYidAGn_jnSqPzYVYOHoMGJqpr9sUeFBnIORP1GpKCeyT04KOfUCFFnyK_QRjRvgEG8CNF00OnoU3-31uD_b8AEuZPewp-nFcLX_xzW_Bc1l3R94IDk3tFhsldzpl8gdt_wPNkUGGA6OfuuM8XMFHivH31EKZq1mBJfyo9BSZK0J9BO3urzB5YuV_90brzX627V6Mvapjc_3CZ_MmXpOvxaxKwZC6_aGAmerpo3oXgFrZV9d9E326-ZVktZf9Or6Ojj3s0XT8k8Yax0FPw1Z6sDw_xXfWL-FtFs76RfS3rNtNNXlQ8r0S1kdnYbIbttq7actj0Ne91rrtKFpuhqMqiH_K8yrARXEguJc-lKIVcV1qUnG9zJfiG171iG67PLZq1Me_nNblTht5H3RR5JevMtJ02fp53Qszvj8nd4MgGbXsmRJqCrkmhqy6ePNtwgz74L7CAwegGrSLntAoP_T-Qg2uDwXBtVp8ee3pYMyHs_nxdZ9GZZgxh8mmQzqPihGGM3VrRmYlD4rtuq8nRd60CE4fZiWfiMJv5JwAA__8u18IU">