Live data from Hacker News

Improvements to static analysis in GCC 14

developers.redhat.com

141–147 of 147 posts

Re: Improvements to static analysis in GCC 14

#141

Earlier quoted context omitted.

> It's impossible to avoid "sanitizing" input if you have a conversion step from a library provided char* to a strbuf type. Any use of the strbuf API is guaranteed to be correct. I agree: having a datatype beats sanitising input (I think there's a popular essay somewhere about parsing input vs sanitising input which makes pretty much the same point as you do), but it's still only partially correct. To get to fully co…

Sure but now we're talking about a universal problem across languages, rather than a C-specific problem.

> Sure but now we're talking about a universal problem across languages, rather than a C-specific problem.

Of course, but that's my point - C already gives you the ability to fix the incorrect typing problem, using the existing foundational `str*` functions.

A team who is not using the compiler's ability to warn when mixing types are still going to mix types when there is a safe strbuf_t type.

The problem with the `str*` functions can be fixed today without modifying the language or it's stdlib.

Most C programmers don't do it (myself included). I think that, in one sense, you are correct in that removing the existing string representation (and functions for them) and replacing them with len+data representation for strings will fix some problems.

Trouble is, a lot of useful tokenising/parsing/etc string problems are not possible in a len+data representation (each strtok() type function, for example, needs to make a copy of what it returns) so programmers are just going to do their best to bypass them.

Having programmers trained to create new string types using existing C is just easier, because then you solve the whole 'mixing types' problem even when looking at replacements for things like `strtok`.

Or ... maybe I'm completely off-base and the reason that programmers don't create different types for string-stored data is because it is too much work in current C-as-we-know-it.

Re: Improvements to static analysis in GCC 14

#142
post #62

Earlier quoted context omitted.

gotos are fine if used judiciously. strcpy and strcat are “fine” in that they work when you know your code is correct and you have big problems if you don’t. But this describes most of C, unfortunately.

> gotos are fine if used judiciously Is there a language feature that is not? :)

If you use trigraphs in your code I will be very upset

Re: Improvements to static analysis in GCC 14

#143

To me fanalyzer is one of GCC killer features over clang. It makes programming C much easier by explaining errors. The error messages also began to feel similar to Rust in terms of being developer friendly.

I'm quite surprised to hear this. What do you get from GCC's analyser that Clang's static analyser doesn't already report?

I tried to use GCC's analyser several times, but I couldn't find any good front ends to it that make the output readable. Clang has multiple (reasonably good HTML output, CodeChecker, Xcode integration, etc.). How do you read the output?

Furthermore, I find that GCC produces many more false positives than Clang.

Re: Improvements to static analysis in GCC 14

#144

I wish there was a better output format for the analysis, because this is hell for screen readers.

FWIW I implemented SARIF output in GCC 13 which is viewable by e.g. VS Code (via a plugin) - though the ASCII art isn't. You can see an example of the output here: https://godbolt.org/z/aan6Kfxds (that's the first example from the article, with -fdiagnostics-format=sarif-stderr added to the command-line options) I experimented with SVG output for the diagrams, but didn't get this in good enough shape for GCC 14.

I find that the biggest practical issue with using GCC's analyser is that it's just so darn difficult to set it up and have readable output. Have you considered focusing on this a bit more? Writing documentation (or even producing tools) for integrating analysis into one's usual workflow, integrating with common build systems (e.g. CMake), making the output properly readable in the context of the source code? I feel that at this point this would be much more helpful than ASCII art or more kinds of warnings ...

I did attempt to use the SARIF output just after your previous blog post a year ago, with a CMake based project, but after an hour I still wasn't able get the warnings to show within the context of the source code.

The -fdiagnostics-format option isn't even in the GCC documentation, your blog post is the only place where I saw it mentioned.

In short: I'd love to use GCC's analyser, and tried it several times, but my bottleneck is usability, ease of setup, and a proper interface to help sort out the many false positives from the true issues.

Re: Improvements to static analysis in GCC 14

#145

To me fanalyzer is one of GCC killer features over clang. It makes programming C much easier by explaining errors. The error messages also began to feel similar to Rust in terms of being developer friendly.

I'm quite surprised to hear this. What do you get from GCC's analyser that Clang's static analyser doesn't already report? I tried to use GCC's analyser several times, but I couldn't find any good front ends to it that make the output readable. Clang has multiple (reasonably good HTML output, CodeChecker, Xcode integration, etc.). How do you read the output? Furthermore, I find that GCC produces many more false posit…

While I wish GCC would implement integrations and/or a language server, I usually do C programming in the terminal (with entr to trigger automatic rebuild on save).

I do find some false positives, but I haven't had many of them to be a deal breaker for me. Aside from what I mentioned about the errors being descriptive, I do like the defaults and that it's part of the compilation process.

for example, possible malloc null warning is on by default (which i don't think is on clang).

Re: Improvements to static analysis in GCC 14

#146

To me fanalyzer is one of GCC killer features over clang. It makes programming C much easier by explaining errors. The error messages also began to feel similar to Rust in terms of being developer friendly.

Clang has a similar tool, the Clang Static Analyzer: https://clang-analyzer.llvm.org/

And had it for much much longer than GCC.

Re: Improvements to static analysis in GCC 14

#147
post #65

Earlier quoted context omitted.

Isn't sort of like pulling the battery out of your carbon monoxide detector because the constant beeping is giving you a headache and making you sleepy?

No. -Wstringop-overflow is really broken with a huge amount of false positives. At $JOB we disable it on a line by line basis, but I'm not sure it is worth the effort.

I disable it in normal builds but track new occurances in builds specifically for high positive rate but still potentially useful warnings.
Post reply on HN