3 ms·
Compiler writers could/should start by not treating undefined behavior as blank checks. This is so idiotic, and no, it's not a bug in Cap'n'Proto, it is very d
by mpweiher 10y ago
Compiler writers could/should start by not treating undefined behavior as blank checks.
This is so idiotic, and no, it's not a bug in Cap'n'Proto, it is very definitely a bug in the compiler (and/or the current version of the C spec. if it actually allows this).
- frederikvs 10y agoThe C standard allows the compiler to do this, so it's definitely not a bug in the compiler.
- mpweiher 10y agoAs I wrote earlier: I had a C compiler before there was C standard. So by your definition, this compiler could not have bugs? As an exercise, try to express the difference between "standards-compliant" and "bug-free".
- kutkloon7 10y agoI think the main point is that if there is a standard, an implementation should comply. If there is no standard, you have to use intuition and common sense to say what's a bug. Different people may have different expectations, so bugs become subjective. Ideally, there is a water-tight standard. In this case every deviation from the standard is a bug and vice versa.
- mpweiher 10y ago> if there is a standard, an implementation should comply Yes. However, we are talking specifically about the parts where the standard is undefined. The standard most emphatically does not require a compiler to do these crazy optimizations that remove safety critical code.
- unwind 10y agoSo rewriting code in order to "do what I mean" makes sense, since not doing what you mean is a bug in the language itself? Not sure that's a very productive approach. The spec is what it is, and it's of course rather deliberately done the way it is in order to make it possible for compilers to optimize and extract more performance.
- mpweiher 10y ago> "do what I mean" Well, the code is right there, there is no magic "do what I mean" needed. Just don't magically remove code that I wrote. > spec is [..] rather deliberately done the way it is in order to make it possible for compilers to optimize and extract more performance Yes, and it is wrong. Breaking existing programs with magic that simply removes code that is clearly there in order to eke out a bit of performance is wrong.
- masklinn 10y ago> Well, the code is right there, there is no magic "do what I mean" needed. Just don't magically remove code that I wrote. You can already do that: use a non-optimising compiler (tcc and the like) or compile without optimisations.
- staticassertion 10y ago> Just don't magically remove code that I wrote. Compile with O0. > Yes, and it is wrong. Breaking existing programs with magic that simply removes code that is clearly there in order to eke out a bit of performance is wrong. Well welcome to writing C? It's been this way for a long time and that won't change - UB is critical to performance and doesn't always lead to unsafety. If you're programming in C, don't blame the compiler when your UB leads to remote code exec, you should have known what you were getting into.
- mpweiher 10y ago> Well welcome to writing C? I've been writing C for 30 years. > UB is critical to performance Not really, no. See "What every compiler writer should know about programmers or “Optimization” based on undefined behaviour hurts performance" (referenced elsewhere in this thread) http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_2015_submission_29.pdf http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_201...