News for hackers. Stuff that matters.
Re:New things in clang land (5.0.0) by ladberg on Thursday December 07, 2017 @05:50AM (#15869025)
I'm not saying add any runtime checking, but if undefined behavior can be proven at compile time, then it should flag that instead of doing something weird.
Re:New things in clang land (5.0.0) by adrianN on Thursday December 07, 2017 @06:02AM (#15869078)
That's what clang's static analyzer is for. The analysis is pretty difficult and would slow down compilation unnecessarily.
Re:New things in clang land (5.0.0) by rurban on Thursday December 07, 2017 @07:15AM (#15869397)
No, that is what -Wall is for. Nobody runs the static analyzer, there are more people using ubsan fwiw.
Re:New things in clang land (5.0.0) by mikeash on Thursday December 07, 2017 @08:52AM (#15869934)
The static analyzer is extremely useful. Why aren’t people running it?
Re:New things in clang land (5.0.0) by pjmlp on Thursday December 07, 2017 @09:48AM (#15870377)
Because reasons.

See Herb Sutter's talk at CppCon 2015. At a given moment he asks the audience if they use any kind of static analysis tools.

About 1% of the audience said they were using one.

Which is why everything that requires external tooling, instead of being part of the language is easily ignored.

Re:New things in clang land (5.0.0) by mikeash on Thursday December 07, 2017 @10:51AM (#15871072)
Would it help if the static analyzer were folded into clang itself and enabled with a flag (-Wanalyze?) rather than using a separate tool? That way it could just be a slight tweaking of build flags, and left enabled if it performs well on a given code base, rather than requiring extra work and thought.
Re:New things in clang land (5.0.0) by pjmlp on Thursday December 07, 2017 @11:44AM (#15871562)
Well it helped when XCode came out with integrated clang static analysis, vs with the largely ignored lint.
Re:New things in clang land (5.0.0) by cwzwarich on Thursday December 07, 2017 @12:01PM (#15871714)
The main reason people avoid static analysis is excessive false positives.
Re:New things in clang land (5.0.0) by 2trill2spill on Thursday December 07, 2017 @08:39AM (#15869844)
> No, that is what -Wall is for. Nobody runs the static analyzer, there are more people using ubsan fwiw.

How do you know what other people are using? I personally use the clang static analyzer all the time. Also it seems like you think these options are mutually exclusive they are not.

Re:New things in clang land (5.0.0) by rurban on Thursday December 07, 2017 @06:09PM (#15875243)
Because I know a lot of software.

Everybody uses -Wall, some -Wextra and even -pedantic, a few asan or ubsan, nobody uses clang specific analyze.

Re:New things in clang land (5.0.0) by 2trill2spill on Thursday December 07, 2017 @06:33PM (#15875385)
> nobody uses clang specific analyze.

That's a pretty bold claim. I use it for all my C projects, FreeBSD use's it[1], Chromium uses it[2]. It seems your basing this whole claim on personal anecdotes which by definition is unreliable.

[1]: https://chromium.googlesource.com/chromium/src/+/lkcr/docs/c...

[2]: https://github.com/freebsd/freebsd-ci/tree/master/scan-build

Re:New things in clang land (5.0.0) by rurban on Monday December 18, 2017 @05:43AM (#15950749)
Which other software probes for a static analyzer? Is there a autoconf or cmake probe? FreeBSD and chromium are islands unfortunately.
Re:New things in clang land (5.0.0) by jhasse on Thursday December 07, 2017 @08:03AM (#15869619)
> The analysis is pretty difficult and would slow down compilation unnecessarily.
Re:New things in clang land (5.0.0) by mehrdadn on Thursday December 07, 2017 @05:55AM (#15869041)
Are you imagining Clang actually did detect it and merely didn't tell you? That seems possible but it seems more likely that it didn't.
Re:New things in clang land (5.0.0) by Joky on Thursday December 07, 2017 @12:23PM (#15871884)
So to take an example, signed integer arithmetic can't overflow (or it is UB), would you like a compiler that flag for every single arithmetic operation on int when it can't prove it won't overflow? So we couldn't compile `int foo(int a, int b) { return a + b; }` right?