<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/167384>167384</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang suggests invalid fixits when warning `-Wunguarded-availability-new` is emitted
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics,
TBAA
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ahatanak
</td>
</tr>
</table>
<pre>
$ cat test.c
```
int g __attribute__((availability(macosx,introduced=15)));
void foo(int);
void test1(void) {
int i1 = 1, i2 = g;
foo(i2);
foo(i1);
}
void test2(void) {
int i1 = g;
int i2 = i1;
foo(i2);
}
```
$ clang -c test.c -target arm64-apple-macosx14.0.0 -fdiagnostics-parseable-fixits
```
test.c:5:20: warning: 'g' is only available on macOS 15 or newer [-Wunguarded-availability-new]
5 | int i1 = 1, i2 = g;
| ^
test.c:1:5: note: 'g' has been marked as being introduced in macOS 15 here, but the deployment target is macOS
14.0.0
1 | int g __attribute__((availability(macosx,introduced=15)));
| ^
test.c:5:20: note: enclose 'g' in a __builtin_available check to silence this warning
5 | int i1 = 1, i2 = g;
| ^
6 | foo(i2);
|
fix-it:"test.c":{5:3-5:3}:"if (__builtin_available(macOS 15, *)) {\n "
fix-it:"test.c":{6:11-6:11}:"\n } else {\n // Fallback on earlier versions\n }"
test.c:11:12: warning: 'g' is only available on macOS 15 or newer [-Wunguarded-availability-new]
11 | int i1 = g;
| ^
test.c:1:5: note: 'g' has been marked as being introduced in macOS 15 here, but the deployment target is macOS
14.0.0
1 | int g __attribute__((availability(macosx,introduced=15)));
| ^
test.c:11:12: note: enclose 'g' in a __builtin_available check to silence this warning
11 | int i1 = g;
| ^
12 | int i2 = i1;
|
fix-it:"test.c":{11:3-11:3}:"if (__builtin_available(macOS 15, *)) {\n "
fix-it:"test.c":{12:15-12:15}:"\n } else {\n // Fallback on earlier versions\n }"
```
The second and the fourth fixits are incorrect as they would cause compilation errors.
`fix-it:"test.c":{6:11-6:11}:"\n } else {\n // Fallback on earlier versions\n }"` should be applied on line 7 so that `foo(i1);` is placed within the same scope as the declaration of `i1`.
`fix-it:"test.c":{12:15-12:15}:"\n } else {\n // Fallback on earlier versions\n }"` should be applied on line 13 so that `foo(i2);` is placed within the same scope as the declaration of `i2`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVs2O6jgTfRqzKQXFDklgkQU0H9tvMVeaJXKcIqlpYyPbgdtvP3KSBoZuobvo27MZFOE4sevnnDpxSe-pNYgVyzcs385kHzrrKtnJII18ndW2eauYWICSAQL6MFcsXbMina50TSZAC_u9DMFR3Qfc75lYMrGUZ0la1qQpvDGxPEpl_U8mXsgEZ5teYcOyLc-ZWE1XtmHp-mypgYO1TCzJhOvj9zcxBM7EMk6YWAEr41uAGAVxYNkWOBMvQGK4b1m2gWHBZFJcLV4f8ZuTcvvgSjx3dTM_PBx9En9wIB4d3KEXr4iulqaFRE0QQxKkazGAdMdikcjTSWMyAsgX83SeQnJoSLbG-kDKJyfpPMpaY3KgnxT8g5OJt2yds2wtUpat4SKdIdPGWybKlokSyIM1-g0m3jSCNXCU6v9_AM_BOjB4QQcs3yR_9qbtpWuwSe5ZTgxeWL4dcgfIgZUv8AvUxN-49MOP5f-7j59POYCxAe9j76SHGjHG616xgWFKpoVbsQHdZdOhwxhL3QcIHUKDJ23fjmgCTMiTH1dfIxyBn6Z8CPiLS_-GxEPaN9re80ajtPV4486AhP2-7kkHMvsbhapD9QrBgieNRiGEjvyV_a8mCorp_Sdq-7iZpesD_UwosGzNhJjSFSJOy01MOkuG_yibYQkdgInlJ3mOIA_cxsiZWI_ADqLNXwxEs0_dFbG8eDIOV4fDXmDlFlBHuCdrY_hix8QOdlLrWqrXqBaUThM6OKPzZI2_bh_d3-o4FjIX3yNEzj_ye-X0gc7_9PZAz-8Q3FNCPhPZJC4ALu53Ph43n8vzedkPqWbJOHyHzgZYeZ5M429S2sMR-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