Issue 179354
Summary FixIt for `-Wimplicit-int` is broken.
Labels new issue
Assignees
Reporter KFAFSP
    Hi all,

I've discovered an issue with the FixIt handling of the `implicit-int` warning/error. I was looking at this neat little ANSI-C program `pi.c`, courtesy of [this paper by Jeremy Gibbons](https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf):

```c
#include <stdio.h>

a[52514],b,c=52514,d,e,f=1e4,g,h;main(){for(;b=c-=14;h=printf("%04d",
e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}
```

If you run clang 21.1.6 with `clang pi.c -Xclang -fix-what-you-can -Xclang -fixit=fixit`, you will get:

```c
#include <stdio.h>

intintintintintintintinta[52514],b,c=52514,d,e,f=1e4,g,h;intmain(){for(;b=c-=14;h=printf("%04d",
e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}
```

For reference, the expected output (which my proposed fix produces), is:

```c
#include <stdio.h>

int a[52514],b,c=52514,d,e,f=1e4,g,h;int main(){for(;b=c-=14;h=printf("%04d",
e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}
```

There are two distinct issues here:
- The FixIt is inserting the `int` type specifier without a whitespace, which leads to malformed code. If you run clang in `-ansi` mode with `-fixit`, it will actually incorrectly assume to have fixed the program and results in a linker error (`main` is undefined).
- The FixIt is inserting the `int` specifier once for every declarator of the declarator group, where it only needs to happen exactly once.

I think this is quite clearly a tiny oversight, one which I already have a proposed fix. Please give me a moment to submit a PR.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to