7 ms·
Oh, hooray. I wonder which programs are going to break because of optimizations this time?
by Filligree 11y ago
Oh, hooray. I wonder which programs are going to break because of optimizations this time?
- deleted 11y ago[deleted]
- Kristine1975 11y agoSame procedure as every year: Only programs that don't conform to the C/C++ standard. Not counting true compiler bugs of course. Edit: The release notes at https://gcc.gnu.org/gcc-6/changes.html https://gcc.gnu.org/gcc-6/changes.html mention three programs that apparently will break: Value range propagation now assumes that the this pointer of C++ member functions is non-null. This eliminates common null pointer checks but also breaks some non-conforming code-bases (such as Qt-5, Chromium, KDevelop)
- Filligree 11y agoAt least with the C standard, it's theoretically possible to learn it. I'd challenge you to find one person in your company who fully understands the C++ standard.
- pjmlp 11y agoAnd I challenge you to find someone that knows all C rules about UB across all major compilers.
- hellofunk 11y agoTrue dat. C is a smaller language and is possible to know the whole language, but not the whole spectrum of UB. C++ is a vastly larger language it is nearly impossible to know the whole language, but much more likely to understand the spectrum of UB.
- octo_t 11y agoUndefined behaviour is the same across all compilers. The compilers aren't the things which make the behaviour undefined, its the C standard.
- pjmlp 11y agoNo it is not, if you ever tried to write portable C code you should clearly be aware that each C compiler has its own flavor of undefined behavior. The C standard is very generous in terms of undefined behavior freedom.
- dsfuoi 11y agoBy definition made in the C Standard, undefined behavior is: behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements If you're using some other definition, then say so, otherwise your comments make no sense.
- pjmlp 11y agoGiven my-app.c, each C compiler out there will pick a different UB subset and not everything that is defined as UB in the standard. They are free to do that and still be compliant, after all UB means anything goes.
- lorenzhs 11y agoThat compilers may behave differently is exactly the point of UB, if they all had to behave the same it wouldn't be undefined, after all!
- octoploid 11y agoWell, just use -fsanitize=undefined and it will point out (most of) the isuses for you.
- Ace17 11y agoProvided that your test suite properly trigger the execution of tricky parts, in tricky situations (You do have a test suite, right?)
- Kristine1975 11y ago>You do have a test suite, right? Of course I do. I call it "customers".
- pjmlp 11y agoWell, not all C compilers have it.
- easytiger 11y agoStroustroup in his book claims he doesn't fully understand it.
- rleigh 11y agoWell, this is the language where Turing-complete template metaprogramming was "discovered" as an emergent property of the system!
- CyberDildonics 11y agoGiant, complicated, wildly successful.
- jordigh 11y agoOr the D standard, or the Java standard, or the Fortran standard, or the Golang standard... It is the GNU compiler collection, after all. I'm actually particularly excited about a new release of gdc myself. I've been reading Alexandrescu's excellent The D Programming Language, and I think it may be just the better C++ that I always wanted, ahead of Golang and Rust.
- lmm 11y agoGCC has an Ada implementation too - you might (or might not) consider that.
- treehau5 11y agoI think this type of thinking is cynical and unhelpful. We complain that compiler technology is not keeping pace, then when they put in god knows how many hundreds of hours of work improving, we complain when we might have to spend a few to go back through our programs and make sure everything's okay. We want everyone else to do the work for us.
- lmm 11y ago> We complain that compiler technology is not keeping pace Who was complaining about that? > when they put in god knows how many hundreds of hours of work improving, we complain when we might have to spend a few to go back through our programs and make sure everything's okay. We want everyone else to do the work for us. Their whole job is to compile our programs - what else is a compiler good for? I don't know who GCC's users are these days - people who care more about benchmarks than working code? Because that seems to be who they're optimising for. Then again I suppose that's the entirety of C/C++'s market these days.
- dave2000 11y agoAre you saying you have an example of valid c++ code which fails to compile, and that this problem is getting worse, or just that you get unexpected behaviour when write bad code?
- coldpie 11y agoCompiler bugs caused by optimizations aren't at all unheard of. We got bit by one recently: https://bugs.winehq.org/show_bug.cgi?id=38653 https://bugs.winehq.org/show_bug.cgi?id=38653 That said, I agree with treehau5.
- lmm 11y ago"Valid" in that the standard absolutely requires that compilers give them some particular meaning, no matter how rules-lawyery the compiler is? No. "Valid" in the sense that the intent is perfectly obvious to any reader? Yes, plenty. "bad"? No, unless you use the standard as your definition of good/bad.
- ben0x539 11y agoThey're helpfully listed in the release notes! > This eliminates common null pointer checks but also breaks some non-conforming code-bases (such as Qt-5, Chromium, KDevelop)
- jbb555 11y agoWe do seem to have got into a race to make C and C++ compilers less and less useful while still following the letter of the rules (but certainly NOT the spirit).
- Kristine1975 11y agoI think modern C and C++ compilers are very useful. Then again I know that these languages are full of huge pitfalls, so I know what I'm getting into, and when I make a mistake I blame myself, not the compilers. I also use the features of modern C/C++ compilers such as warnings (-Weverything on clang, then turn off those warnings I'm not interested in) and sanitizers (Undefined Behavior Sanitizer, Address Sanitizer).
- wtetzner 11y agoI was under the impression that the whole point of undefined behavior in the spec was to give implementers flexibility. Am I wrong? If not, then it sounds like it's very much in the spirit of the rules.
- jordigh 11y agoThat's implementation-defined behaviour (do something nonstandard and document it) or unspecified behaviour (do something specific and nonstandard but don't have to document it). Undefined behaviour allows the compiler writer to have the code do anything unreliable and unpredictable and not document it. Its purpose is to allow compiler writers to completely ignore the erroneous code that results in UB and not spend effort trying to diagnose it or implement it. Most compilers still make an effort to diagnose some UB anyway, though.
- lmm 11y agoThe original reason was to ensure the standard was compatible with existing compilers (i.e. to leave behaviour which varied between existing compilers unstandardized) and to allow hardware-native behaviour for things like integer overflow and extended shifts, not to allow aggressive optimizations.
- DannyBee 11y agoActually, some: "Type-based alias analysis now disambiguates accesses to different pointers. This improves precision of the alias oracle by about 20-30% on higher-level C++ programs. Programs doing invalid type punning of pointer types may now need -fno-strict-aliasing to work correctly."