4 ms·
You can't "not allow undefined behavior in the first place" without a massive performance hit (like checking the validity of every pointer at run time). In this
by mehrdadn 9y ago
You can't "not allow undefined behavior in the first place" without a massive performance hit (like checking the validity of every pointer at run time). In this case I agree they should be able to detect it given that the whole program is available and the deduction that the pointer is null is easy to reach via a fixed-point iteration. But it just cannot be done efficiently in general in a language that inherently allows unverifiable code to begin with, and the kind of performance hit you'd get would make the language slower than a verifiable language like C# (at which point you should be using
that kind of a language instead, since that's what they're for).
- ladberg 9y agoI'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.
- mehrdadn 9y agoAre 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.
- adrianN 9y agoThat's what clang's static analyzer is for. The analysis is pretty difficult and would slow down compilation unnecessarily.
- rurban 9y agoNo, that is what -Wall is for. Nobody runs the static analyzer, there are more people using ubsan fwiw.
- jhasse 9y ago> The analysis is pretty difficult and would slow down compilation unnecessarily.
- 2trill2spill 9y ago> 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.
- rurban 9y agoBecause I know a lot of software. Everybody uses -Wall, some -Wextra and even -pedantic, a few asan or ubsan, nobody uses clang specific analyze.
- 2trill2spill 9y ago> 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/clang_static_analyzer.md https://chromium.googlesource.com/chromium/src/+/lkcr/docs/c... [2]: https://github.com/freebsd/freebsd-ci/tree/master/scan-build https://github.com/freebsd/freebsd-ci/tree/master/scan-build
- rurban 9y agoWhich other software probes for a static analyzer? Is there a autoconf or cmake probe? FreeBSD and chromium are islands unfortunately.
- mikeash 9y agoThe static analyzer is extremely useful. Why aren’t people running it?
- pjmlp 9y agoBecause 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.
- mikeash 9y agoWould 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.
- pjmlp 9y agoWell it helped when XCode came out with integrated clang static analysis, vs with the largely ignored lint.
- cwzwarich 9y agoThe main reason people avoid static analysis is excessive false positives.
- Joky 9y agoSo 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?
- IshKebab 9y agoWell.. you can. But not in C++. Most modern languages don't have undefined behaviour.