Hacker News new | ask | show | jobs
by ufo 2236 days ago
What do you love the most about the new analyzer pass? I haven't had a chance to try it out for myself yet but I'm looking forward to it.
2 comments

I like not having to run another commercial tool[1] that will likely not be in use whenever I move on to the next project because no one has heard of it.

Biggest advantage I see is it's integrated into the compiler and so sees the same things the compiler does.

Having gcc do this out of the box helps people port their experience/skills with static analysis to other companies.

We already have clang-tidy and I like it too but it's nice to have a fall-back to compare when one produces a strange result. And a bit of competition is always good to have between such projects. And on most big projects it's not like you can just change the build system to use another compiler.

Also I found some interesting cases which valgrind didn't see because it was in an unreachable branch.

[1] https://news.ycombinator.com/item?id=22712338

An example to detect use-after-free: https://godbolt.org/z/zhiNLW

Basically this replicates what clang-tidy did

Too bad it doesn't detect the mismatch between new and free.
And if you fix it to use delete instead of free, you get "can't delete void *" errors. Perhaps not the best example code.
and if you fix the void->int, the warning goes away.
yeah that's why I changed int* to void* in the example, but I forgot to change new to malloc