GCC 14 is still in development, but it has a wonderful new feature in its static analyzer (-fanalyzer
).
It can now draw beautiful Unicode diagrams showing exactly how you went out-of-bounds.
See https://inbox.sourceware.org/gcc-patches/20230531180630.3127108-1-dmalcolm@redhat.com/ too.
Thank you to the wonderful David Malcolm for implementing this - who also does a tonne of work with mentoring for GCC's GSoC programme, and working on docs to help new people get into GCC: https://gcc-newbies-guide.readthedocs.io/en/latest/index.html.
For all the people who still held any illusions that they are good at writing C:
"Look, human. This is where your weird human brain decided to introduce a fence-post error again.
Here, I have drawn you a picture. Sorry, crayons were out."
@thesamesam @gnutools I won’t pretend to really understand this, but I just have to say:
IT LOOKS SO COOL. Plus, visualizing things can greatly help folks who process better visually, so I’m a huge fan!
$ scan-build clang /tmp/foo.c -o /tmp/foo
scan-build: Using '/usr/lib/llvm/16/bin/clang-16' for static analysis
/tmp/foo.c:5:20: warning: format specifies type 'char *' but the argument has type 'char' [-Wformat]
printf("bar: %s", foo[3]);
~~ ^~~~~~
%c
/tmp/foo.c:5:20: warning: array index 3 is past the end of the array (that has type 'char[2]') [-Warray-bounds]
printf("bar: %s", foo[3]);
^ ~
/tmp/foo.c:4:2: note: array 'foo' declared here
char foo[2] = "a";
^
2 warnings generated.
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2023-07-14-041437-3476-1' because it contains no reports.
scan-build: No bugs found.
I should also say that if you want a distribution that makes it very easy to have multiple GCCs installed at once and is recognised for its high-quality toolchain maintenance, you know where we are 😉