Slashdot Mirror


Examining the User-Reported Issues With Upgrading From GCC 4.7 To 4.8

Nerval's Lobster writes "Developer and editor Jeff Cogswell writes: 'When I set out to review how different compilers generate possibly different assembly code (specifically for vectorized and multicore code), I noticed a possible anomaly when comparing two recent versions of the g++ compiler, 4.7 and 4.8. When I mentioned my concerns, at least one user commented that he also had a codebase that ran fine after compiling with 4.6 and 4.7, but not with 4.8.' So he decided to explore the difference and see if there was a problem between 4.7 and 4.8.1, and found a number of issues, most related to optimization. Does this mean 4.8 is flawed, or that you shouldn't use it? 'Not at all,' he concluded. 'You can certainly use 4.8,' provided you keep in mind the occasional bug in the system."

148 comments

  1. So in other words.... by Anonymous Coward · · Score: 1

    If it ain't broke, don't fix it. No need to upgrade.

    1. Re: So in other words.... by Anonymous Coward · · Score: 0

      what moron changes his compiler in the middle of a production run?
      You all know the old cranky dba that sits on his ass all day as the other departments execute their mission critical disaster plans day after day?
      Put him in charge.

    2. Re: So in other words.... by sunderland56 · · Score: 1

      what moron changes his compiler in the middle of a production run?

      Having unxeplainable bugs in your code isn't any fun, whether it's the beginning or middle or end of a project.

      Most projects I've been on run regression tests - to make sure that your new release doesn't break some functionality of your old one. Sometimes that's hard to do; but in the case of a compiler, it's extremely easy, and easy to automate. The fact that GCC isn't running any form of quality control is pretty staggering.

  2. Complete waste of time. by Anonymous Coward · · Score: 5, Informative

    Thanks for another worthless uninformative article.

    1. Re:Complete waste of time. by Anonymous Coward · · Score: 0

      'You can certainly use 4.8,' provided you keep in mind the occasional Neo in the system."

      Now it's much more informative.

    2. Re:Complete waste of time. by Anonymous Coward · · Score: 0

      Thanks for another worthless uninformative article.

      The takeaway is pretty simple- If your code relies on the specific optimization features in previous version of the compiler, then you might have issues.

      For example, there was an improvement in the optimization in one situation, where instead of stuffing data into two registers, only one is actually needed. So if your code assumed the optimization would use two registers, and then added a bit of inline assembly to tinker with just one of them, it's going to be completely busted with the new version because only one register is used.

      Frankly speaking, if your code is relying on a specific behavior of the compiler in order to work, then of course you don't want to rush out and upgrade to a new version, because that behavior might very well have changed. If you got through previous upgrades without issue, then you were simply lucky.

  3. Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 2

    Holy fuck, I sure won't be using this for anything mission-critical.

    1. Re:Keep in mind the occasional bug in the system? by iggymanz · · Score: 1

      terrible news for you that will shatter your world-view: all compilers of any language and of any version have bugs

    2. Re:Keep in mind the occasional bug in the system? by NoNonAlphaCharsHere · · Score: 4, Insightful

      99.2% of the people who use the phrase "mission critical" don't have anything "mission critical".

    3. Re:Keep in mind the occasional bug in the system? by rudy_wayne · · Score: 2

      This is something I've wondered about for a long time. All software has bugs. It's impossible to write non-trivial software that is absolutely 100% perfect. And that would include compilers. Especially compilers because they are very complex programs. I wonder how many crashes/bugs in software are actually the result of bugs in the compiler?

    4. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 1

      I wonder how many crashes/bugs in software are actually the result of bugs in the compiler?

      Far fewer than the ones due to bugs in your actual code. If you want to start blaming the compiler or the hardware for your problems, you better be damn sure.

    5. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      "Mission Critical" is not a very good phrase. It's too subjective.

      As much as I go to work to do good work and make life easier on someone else, my real mission is to go there to make money for myself and to be allowed to go back the next day, so having a comfortable chair and a working computer are actually pretty mission critical.

    6. Re:Keep in mind the occasional bug in the system? by 0123456 · · Score: 2

      I wonder how many crashes/bugs in software are actually the result of bugs in the compiler?

      I think I've seen two in twenty years. So they happen, but not often, and usually only when they run into very unusual code.

    7. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      It's impossible to write non-trivial software that is absolutely 100% perfect.

      "It's impractical to write non-trivial software that is absolutely 100% perfect."

      See: https://www.google.com/search?q=provably+correct+code

    8. Re:Keep in mind the occasional bug in the system? by ThePhilips · · Score: 2

      Do what I do: replace any mention of "mission critical" with "business critical".

      But even then, miscompiles do happen with literally every compiler and are hardly "business critical". One miscompile can't bring the company down. Unlike, for example one melt-down nuclear reactor.

      If tests haven't exposed the problem, then it is rather lack of testing which is the problem.

      --
      All hope abandon ye who enter here.
    9. Re:Keep in mind the occasional bug in the system? by msobkow · · Score: 1

      But virtually 100% of the people using the phrase "mission critical" are the ones who approve your paycheques and thereby determine your priorities.

      --
      I do not fail; I succeed at finding out what does not work.
    10. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      If it depends on your job, your company, your gov't, your power plant... or even effects your family (aka your job).... it's pretty much mission critical to you. My point is mission critical means a lot of things to lots of people, some more selfish than others. And with gcc, being as general as the English language... mission critical should be defined with the context in mind. And we're not talking just rocket science as mentioned in the TFA.

    11. Re:Keep in mind the occasional bug in the system? by gl4ss · · Score: 3, Funny

      obviously you're not an ex-symbian developer!

      --
      world was created 5 seconds before this post as it is.
    12. Re:Keep in mind the occasional bug in the system? by tibit · · Score: 1

      Based on a non-article? I sure hope your mission itself isn't all that critical, 'cuz you fail at reading, and Cogswell fails at articulating his thoughts, if he has any worth articulating, that is.

      --
      A successful API design takes a mixture of software design and pedagogy.
    13. Re:Keep in mind the occasional bug in the system? by gnasher719 · · Score: 3, Interesting

      I think I've seen two in twenty years. So they happen, but not often, and usually only when they run into very unusual code.

      That's about my rate. Including one where the compiler gave a warning, which didn't match the actual C code, but did match the code generated by the compiler. But add a few occasions where a few people did swear it was a compiler bug and were proved wrong. One where converting -sizeof (int) to "long" produced a value of 65534. One (many years ago) where actually Sun compiler engineers explained sequence points to us :-( One where the same header file was included with different #defines which changed the size of a struct - for that one I could have killed someone.

    14. Re:Keep in mind the occasional bug in the system? by Immerman · · Score: 1

      Come now, it should be obvious that just because it's theoretically possible to prove that code is correct does not necessarily imply that it's theoretically possible to write such code in the first place.

      Spec: Given a number between one and ten, calculate the volume of the rectangular prism I'm thinking of.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    15. Re:Keep in mind the occasional bug in the system? by cheesybagel · · Score: 2

      I've seen two and in both cases it was VC 6.0.

    16. Re:Keep in mind the occasional bug in the system? by Immerman · · Score: 1

      Actually no, it's not subjective at all, it's just usually used hyperbolically to mean "really important" or even "I want this" instead. If your mission is to write software, a computer (or at least some punch cards or something) is mission critical - the mission *CANNOT* be completed without it. Things like a chair, desk, or shelter from the weather may increase productivity and employe retention at, but are not actually *critical* to the mission of writing software.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    17. Re:Keep in mind the occasional bug in the system? by 0123456 · · Score: 3, Informative

      Yeah, most of the bugs that initially looked like compiler bugs turned out to be code bugs, or undefined behaviour. I don't remember which real compiler bugs we ran into, but they were real bugs that the vendor admitted to and eventually fixed.

    18. Re:Keep in mind the occasional bug in the system? by 0123456 · · Score: 1

      Come now, it should be obvious that just because it's theoretically possible to prove that code is correct does not necessarily imply that it's theoretically possible to write such code in the first place.

      The bigger problem is that, even if your code is perfect, you're linking with libraries that have bugs, which interact with an operating system that has bugs, and run on a CPU that has bugs. Most of the major bugs in projects I've been involved with lately have come from third-party libraries, hardware or hardware drivers, not our code.

    19. Re:Keep in mind the occasional bug in the system? by NatasRevol · · Score: 1

      Known bugs vs unknown bugs.

      One you can work around, one you work through.

      --
      There are two types of people in the world: Those who crave closure
    20. Re:Keep in mind the occasional bug in the system? by chaim79 · · Score: 4, Interesting

      I wonder how many crashes/bugs in software are actually the result of bugs in the compiler?

      I think I've seen two in twenty years. So they happen, but not often, and usually only when they run into very unusual code.

      You see them more often in the Embedded world than on full computers. A big one I ran into recently was with Freescale 68HC12, an ancient processor and compiler. It would randomly decide if incrementing or decrementing (var++; or var--;) would be done as integer increment/decrement (add/subtract 1) or pointer increment/decrement (add/subtract 2). We had a lot of interesting bugs where it would randomly decide that a for loop would do pointer math instead of integer math and we'd skip half the work.

      This was very recent, and with latest patches (for some definition of latest... they were concentrating on their new eclipse based IDE with it's GCC compiler so this one wasn't being worked on).

      --
      DEMETRIUS: Villain, what hast thou done?
      AARON: Villain, I have done thy mother.
      Shakespeare invents 'your mom'
    21. Re:Keep in mind the occasional bug in the system? by Mashdar · · Score: 1

      Just because the mission isn't critical does not mean that nothing is mission critical. :)

    22. Re:Keep in mind the occasional bug in the system? by Bert64 · · Score: 1

      I've had a few where code has to be compiled with optimzation turned off, or set to a lower than usual level in order for the program to work..

      --
      http://spamdecoy.net - free throwaway anonymous email - avoid spam!
    23. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 1

      If you want to start blaming the compiler or the hardware for your problems, you better be damn sure.

      I've seen a few compiler errors (in 30+ years). Most memorable was back when C++ was so new we used the precompiler to generate C code and compiled that. On archicture it generated (correct) C code which broke the compiler. We got a new version of the C compiler from the vendor to increase some internal limits.

      I've seen one hardware error (not counting assorted Pentium bugs). It was a numerical error on one instance of the particular CPU (DEC microVAX), where some calculations were coming out wrong. Took a while but we boiled it down to a minimal program which would reproduce the bug and we showed it didn't happen on other boxes. DEC replaced it.

      OTOH, back in the day I worked on campus as a "programmer on duty" to help kids with their programs. If I had a buck for every one that came to me with:
      Kid: "But it worked last week!"
      Me: "What did you change?"
      Kid: "Nothing! It must have been the computer! (compiler, etc)"
      Me: (thinks: then why re-run it?) "So you'll buy me a case of beer if I find a difference between what you did then and now?"
      Kid: "Er, uh, maybe I did change one thing...." wanders off

    24. Re:Keep in mind the occasional bug in the system? by residents_parking · · Score: 1

      Seconded - years ago I worked with a particularly awful PIC compiler. It would be fine until my compiled output size crossed an unknown threshold. Then it wouldn't just break - it would shatter. Terrible crap. I wasted 6 weeks massaging that POS before I demanded a better compiler. I was new back then.

      But there's a twist - my boss was able to make it work, probably because his code lacked any structure and used all global variables. And he STILL uses it for PIC work. But working on bigger projects has gotten him out of many of those bad habits.

      These days I experience many more silicon bugs than compiler bugs. And that's on mainstream devices from Microchip and NXP.

    25. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      Then apply the proofs to each library or lower level as necessary for your particular application.

    26. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      First, many programmers happen to write 100% bug-free code by accident, though not very often. Second, correctness of code is proved customarily for high integrity systems. Of course that doesn't necessarily mean that the code will perform correctly unless the whole operating system and the compiler have been formally verified as well. Anyway, it's a good start. It's also very expensive.

    27. Re:Keep in mind the occasional bug in the system? by pentagramrex · · Score: 1

      Bad idea to use HC12 with GCC. It never had proper support (thinking way back). The commercial compilers were expensive though.

    28. Re:Keep in mind the occasional bug in the system? by 0123456 · · Score: 1

      Then apply the proofs to each library or lower level as necessary for your particular application.

      Yeah, good luck with that.

    29. Re:Keep in mind the occasional bug in the system? by sjames · · Score: 1

      I've seen a few more, but they generally show up when aggressive optimizations are enabled and go away when they're turned off.

      I did once find one that happened in any case. I ended up changing a couple lines of code to equivalent ones that didn't seem to trip up the compiler.

    30. Re: Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      I've seen one and it was VC10 (Visual Studio 2010).

      http://archive.msdn.microsoft.com/KB2280741

    31. Re:Keep in mind the occasional bug in the system? by lgw · · Score: 1

      Circular argument ("begs the question", for real). A code prover is non-trivial code. If I assert that all non-trivial code has bugs, then you can't use a prover to prove otherwise (and anyhow, there's not a proven-correct stack to run it on).

      Static analysis tools are a useful part of code review, but nothing more than that.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    32. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      The mission may not be critical in the sense of 'critical to humanity', but the piece of code may still be critical to the trivial mission at hand - like keeping a system running and keeping your job...

    33. Re:Keep in mind the occasional bug in the system? by gargleblast · · Score: 2

      Took a while but we boiled it down to a minimal program which would reproduce the bug

      I did that once to demonstrate a bug in a COBOL compiler. The vendor had trouble understanding what such a short COBOL program did.

    34. Re:Keep in mind the occasional bug in the system? by AdamInParadise · · Score: 3, Informative

      Not true. Check this out: CompCert, a formally proven C compiler (i.e. 100% perfect).

      And you can use it today, for free (GPL), on real programs.

      --
      Nobox: Only simple products.
    35. Re:Keep in mind the occasional bug in the system? by serviscope_minor · · Score: 2

      Oh god vendor compilers.

      The horror, the horror.

      Seriously I don't understand it. Hardware companies make nice hardware then ship these amazingly shoddy compilers. Not only that they make them super-extra-mega-proprietary as if there is some great trade secret whereas they should be using such protction to hide their richly deserved shame.

      Why do they get so uptight about the software which they are clearly so bad at?

      Ah, when GCC started taking over from those it was sheer joy. And because of the GPL they seemed to realise that there wasn't much worth doing to it (though few of them seem to be able to resist fucking up GC a bit---almost all ICEs I've had have been with vendor-shittified GCC).

      I hope the BSD license of LLVM doesn't give them funny ideas about how they can be all proprietary again. That would be a return to the bad old days.

      --
      SJW n. One who posts facts.
    36. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      The vendor had trouble understanding what such a short COBOL program did.

      IEFBR14 ?

    37. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      I wonder how many crashes/bugs in software are actually the result of bugs in the compiler?

      Long ago, I worked at a place where we supported many different platforms and we discovered many bugs (resulting in wrong answers and SEGVs) in vendor compilers with high optimization levels - several each year. They often got fixed fairly quickly but we usually worked around them by cranking down the optimization level for the offending module on the offending platform.

      For dev we used gcc because gdb worked well with objects compiled with gcc but not so well with objects compiled with the vendor compilers (esp w/SEGVs et al) and we didn't want to remember the syntax for ten different vendor debuggers or put up with their sometimes very limited functionality. But for production builds (and, of course, QA testing of those builds) we used the vendor compilers because they usually produced better optimized code. Of course most of these vendors (such as Unisys, Sun, SGI, DEC) and platforms no longer exist.

    38. Re:Keep in mind the occasional bug in the system? by wiredlogic · · Score: 1

      You should have been using GCC all along if the commercial compiler is so crusty that it can't be trusted.

      --
      I am becoming gerund, destroyer of verbs.
    39. Re:Keep in mind the occasional bug in the system? by ChunderDownunder · · Score: 1

      What about a compiler that has been mathematically proven to be correct?

      http://compcert.inria.fr/

    40. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      What compiler did you switch to? XC16? Please share! I have a moderate-sized PIC project with of course this exact problem, on C16 (the project's legacy compiler).

      C16 has a few "fun" bugs in it that aren't related to space/memory layout, too. I had one where an absolutely nonsensical error was generated for valid, standards-compliant C... but not when two particular consecutive non-interacting lines were exchanged.

    41. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      Very interesting, thanks.

    42. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      I ran into a fun one in a Bell Labs C compiler in the late 80's/early 90's. Moving a function in a source file caused a compilation error. It was due to the way that input was buffered -- I had moved the function so it spanned buffers just the wrong way and BOOM. That was a real head-scratcher, but it being Bell Labs I had access to the source.

    43. Re:Keep in mind the occasional bug in the system? by Anonymous Coward · · Score: 0

      CompCert isn't free software: "The CompCert C compiler is not free software. This release can be used for evaluation, research and education purposes, but not for commercial purposes. See the License for more information. " (from http://compcert.inria.fr/download.html). You might have looked in the LICENSE file and seen that a subset of the files are GPL dual-licensed, but that's not a big help.

    44. Re:Keep in mind the occasional bug in the system? by iggymanz · · Score: 1

      that's nonsense, the C specification deliberately leaves many things to implementation, and those things alone create many bugs. but this is what I would expect from ivory tower types who have never done systems programming and have no real world experience

  4. Trust the compiler by Anonymous Coward · · Score: 0

    Once upon a time I hear someone say "Trust the compiler, the compiler is your friend."
    In theory that sounds fine but the more I compile the more I lean towards that it is absolutely necessary for C and C++ users to know assembler and preferably have a good idea of what the compiler will output. Problems can occur and abstractions makes them harder to analyze.
    This is even more important when working with microcontrollers where the compilers generally aren't as tried and tested as one would wish.

    1. Re:Trust the compiler by NoNonAlphaCharsHere · · Score: 1

      And that's true: for microcontrollers. Knowing the assembly language is useful because you can actually know what is going to happen next in terms of instructions fetched, decoded and executed. It's a whole different ballgame with multiple cores, dynamic scheduling, out-of-order execution, several layers of on-die cache and pre-executed branches. While the compiler (in this case) may not always get it 100% right (yet), at least it's going to do things *consistently*.

    2. Re:Trust the compiler by Immerman · · Score: 1

      Ah, you must have gotten the condensed version, I think the complete quote is supposed to be something along the lines of:

      Trust the compiler, the compiler is your friend. But it's one of those asshole friends that will draw on your face if it catches you sleeping, and will sometimes make stupid mistakes with the best of intentions. So you probably want a good understanding of at least the basics of what it's doing, and the most common ways it gets confused.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    3. Re:Trust the compiler by Anonymous Coward · · Score: 0

      I think it is just a matter of bad hearing.
      It should really be "Thrust the compiler, the compiler is a dick."

    4. Re: Trust the compiler by Anonymous Coward · · Score: 0

      I disable all optimizations on my micro code. I'll write it myself, bbecause if my dick is going to be cut off, I'm going to be the one who does it.

  5. Flawed logic? by bogaboga · · Score: 0

    Does this mean 4.8 is flawed, or that you shouldn't use it? 'Not at all,' he concluded. 'You can certainly use 4.8,' provided you keep in mind the occasional bug in the system."

    It reminds me of the [in]famous Windows 9x BSOD whenever I wanted to print some particular Word document. If I wanted it to print without throwing the BSOD, all I had to do was to remove the leading space at the begining of the header. The same document prints fine in Windows XP.

    With this kind of logic, it just doesn't make sense!

  6. And importantly is your code standards compliant? by queazocotal · · Score: 4, Informative

    Though the code behaves differently with, and without optimisation, and does not work on the new compiler whereas it did on the old,
    this does not mean it is a bug in the compiler.

    GCC, Clang, acc, armcc, icc, msvc, open64, pathcc, suncc, ti, windriver, xlc all do varying optimisations that vary across version, and
    that rely on exact compliance with the C standard. If your code is violating this standard, it risks breaking on upgrade.

    http://developers.slashdot.org/story/13/10/29/2150211/how-your-compiler-can-compromise-application-security
    http://pdos.csail.mit.edu/~xi/papers/stack-sosp13.pdf
    Click on the PDF, and scroll to page 4 for a nice table of optimisations vs compiler and optimisation level.

    _All_ modern compilers do this as part of optimisation.

    GCC 4.2.1 for example, with -o0 (least optimisation) will eliminate if(p+100p)

    This doesn't on first glance seem insane code to check if a buffer will overflow if you put some data into it. However the C standard says that an overflowed
      pointer is undefined, and this means the compiler is free to assume that it never occurs, and it can safely omit the result of the test.

  7. Compiler bugs by Dan+East · · Score: 2

    I've only run into a few compiler bugs (like the one in this article, most always due to the optimizers), and it was always so incredibly aggravating, because it's easy to believe that compilers are always perfect. Granted, they might not produce the most efficient code, but bugs? No way! Of course I know better now, and most of the bugs I came across were back in the Pocket PC days when we had to maintain 3 builds (SH3, MIPS and ARM) for the various platforms (and of course the bugs were specific to an individual platform's compiler, which made it a little easier actually to spot a compiler bug, when a simple piece of code worked on 2 of 3 architectures).

    --
    Better known as 318230.
  8. Use it, sure - it's not a bug, it's a feature by taikedz · · Score: 1

    Some people see "bugs," others see "features."

    I've seen solution features designed around security holes before, and when we finally patched the breach, we received emails demanding that the decision be reversed and how dare we break customer solutions by surreptitiously patching things!

    Sometimes you never can win.

    --
    -- "Simplicity is prerequisite for reliability." --Dijkstra
    1. Re:Use it, sure - it's not a bug, it's a feature by QRDeNameland · · Score: 5, Funny
      --
      Momentarily, the need for the construction of new light will no longer exist.
    2. Re:Use it, sure - it's not a bug, it's a feature by Immerman · · Score: 1

      That has got to be one of the most dead-on appropriate "obligatories" I've seen in a long time.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    3. Re:Use it, sure - it's not a bug, it's a feature by fahrbot-bot · · Score: 3, Funny

      Obligatory XKCD

      That has got to be one of the most dead-on appropriate "obligatories" I've seen in a long time.

      For sure. Even as a long, long time Emacs user, I didn't know you could program it for that.

      --
      It must have been something you assimilated. . . .
    4. Re:Use it, sure - it's not a bug, it's a feature by gmhowell · · Score: 1

      Obligatory XKCD

      That has got to be one of the most dead-on appropriate "obligatories" I've seen in a long time.

      For sure. Even as a long, long time Emacs user, I didn't know you could program it for that.

      For God's sake, you mean you've been doing 'M-x increase-CPU-temp' the whole time?

      --
      Jesus was all right but his disciples were thick and ordinary. -John Lennon
  9. Duh? by Fwipp · · Score: 5, Informative

    The article basically says:
    "GCC 4.8 includes new optimizations! Because of this, the generated assembly code is different! This might be BAD."

    Like, duh? Do you expect optimizations to somehow produce the same assembly as before, except magically faster?

    The linked "bug" is here: http://stackoverflow.com/questions/19350097/pre-calculating-in-gcc-4-8-c11 - which says, "Hey, this certain optimization isn't on by default anymore?" And to which the answer is, "Yeah, due to changes in C++11, you're supposed to explicitly flag that you want that optimization in your code."

    So, yeah. Total non-story.

    1. Re:Duh? by CadentOrange · · Score: 3, Interesting

      It's by Jeff Cogswell. I ignore any of the "articles" he writes as they're either misleading bullshit or chock full of Captain Obvious statements.

    2. Re:Duh? by Fwipp · · Score: 1

      Oh, thanks for the heads-up. I'll be sure to ignore him in the future, then. :)

    3. Re:Duh? by Anonymous Coward · · Score: 0

      The article basically says:
      "GCC 4.8 includes new optimizations! Because of this, the generated assembly code is different! This might be BAD."

      Uh, the absurd intonation is yours, not Cogswell's. Go re-read his article. He is presenting useful information on how the codegen differs between versions, and what compiler switches can be used to control optimizer behavior.

      If you have a stick up your butt before you read an article, chances are you'll have the same stick up your butt afterwards.

    4. Re:Duh? by Fwipp · · Score: 4, Insightful

      On the surface, this code appears quite different. Due to space (and my unwillingness to bore readers any more than necessary), I won’t reproduce the resulting assembly code here. But I will say the 4.8 version, for just the loops, is about ten lines shorter. In both cases the code is vectorized. The vectorized portion, which is basically this line of C++ code—
        x[i + j * SIZE] += y[i + j * SIZE];
      —is almost the same, except for a minor difference in how the data is moved in and out of the registers. (The 4.7 version uses two registers; the 4.8 version uses only 1.)
      The rest of the difference centers on how the loop is optimized. Now remember: The code runs in both cases. It doesn’t have a bug. What we’re dealing with here, then, is a matter of the developers revising the assembly code generation and optimizing algorithms. Nevertheless, the code is different.

      This is the entirety of his comparison.
      "this code appears quite different ... the 4.8 version is about ten lines shorter ... [vectorization] is almost the same ... The [rest is] how the loop is optimized... it doesn't have a bug ... Nevertheless, the code is different."

      Reading the summary, in which he claims he "found a number of issues," it seems like he might have, y'know, taken the time to mention some of those issues. I guess zero is a number.

    5. Re:Duh? by twdorris · · Score: 1

      The linked "bug" is here: http://stackoverflow.com/questions/19350097/pre-calculating-in-gcc-4-8-c11 - which says, "Hey, this certain optimization isn't on by default anymore?" And to which the answer is, "Yeah, due to changes in C++11, you're supposed to explicitly flag that you want that optimization in your code."

      That linked "bug" appears to be an actual "bug" since a fix for it was posted to 4.8.2. See here.

      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57511

    6. Re:Duh? by Anonymous Coward · · Score: 0

      It's not a bug in the sense that you get wrong results. It's a "bug" in the sense of an optimization regression. But optimization regressions aren't usually considered bugs, at least by end users.

      The phrase "compiler bug" normally strikes fear into the heart of a C or C++ developer. Like learning your mother is psychotic and might randomly stick a knife into your belly at any moment. Optimization regressions... not nearly as big a deal.

    7. Re:Duh? by MurukeshM · · Score: 1

      Wasn't he the one who started out with that ridiculous Java vs C# comparison? http://slashdot.org/topic/cloud/java-vs-c-which-performs-better-in-the-real-world/ I usually ignore any article with his name on it, but I am studying GCC for a course. Turns out, I should have continued ignoring.

    8. Re:Duh? by hermitdev · · Score: 1

      I am studying GCC for a course.

      Curious, can you elaborate on the course? Is it about compiler architecture & theory? If not, what?

    9. Re:Duh? by MurukeshM · · Score: 1

      I misspoke, I am not studying GCC for a course, the course is GCC: CS 715 at IIT Bombay - Design and and Implementation of GNU Compiler Generation Framework taught by Prof. Uday Khedkar.
      The course plan includes studying the various passes (analysis, optimizations, etc.) that GCC makes, adding/modifying passes, and implementing a machine description for GCC. The languages analyzed are C and C++, with initial activity on x86 systems and then on spim, the MIPS simulator.

  10. Affects me by Anonymous Coward · · Score: 3, Interesting

    One of the projects I work on will compile and run perfectly with GCC 4.6 and any recent version of Clang. However, compiling under GCC 4.7 or 4.8 causes the program to crash, seemingly at random. We have received several bug reports about this and, until we can track down all the possible causes, we have to tell people to use older versions of GCC (or Clang). Individual users are typically fine with this, but Linux distributions standardize on one version of GCC (usually the latest one) and they can't/won't change, meaning they're shipping binaries of our project known to be bad.

    1. Re:Affects me by tibit · · Score: 0

      You probably have buggy code that depended on implementation-defined behavior (or even undefined behavior), and it came back to bite you. It's on you to instrument your app to get crash reports and figure out what went wrong - if it's "broken" under both 4.7 and 4.8, it's very likely your own bug.

      --
      A successful API design takes a mixture of software design and pedagogy.
    2. Re:Affects me by cheesybagel · · Score: 2, Informative

      Run your program under valgrind and fix the damned bugs.

    3. Re:Affects me by Anonymous Coward · · Score: 1

      In addition to the previously mentioned valgrind, try compiling with "-Wall -Wextra -pedantic" under recent versions of GCC and Clang.

    4. Re:Affects me by jmv · · Score: 1

      There's about a 99% chance that the "problem" with gcc >=4.7 is that your code isn't compliant with the C standard (e.g. relies on undefined behaviour) and there's a new gcc optimization that makes a new (legal) assumption that your program violates.

  11. Optimization by necro81 · · Score: 2

    So, as has always been the case: use optimizers with caution, and verify the results. This is standard software development procedure. Some aspects of optimization are deterministic and straightforward, and are therefore pretty low risk; others optimizations can have unpredictable results that can break code.

  12. New version slightly different, may cause issues by Anonymous Coward · · Score: 0

    OMG, you mean when you revise code, add features and alter functionality, it may result in bugs?

  13. The bigger problem is undefined behavior by Daniel+Hoffmann · · Score: 0

    Undefined behavior is a very big problem in C and C++. It causes major headaches in producing cross-compiler code. I don't have much experience with multi-threaded in GCC but it must cause major headaches because of all the timing involved.

    1. Re:The bigger problem is undefined behavior by Anonymous Coward · · Score: 0

      Oh, BS! I *do* have experience with multi-threaded code (about 25 yrs.). Both C and C++ have a standard that defines their respective behavior with portable code. People just write sh*tty code and blame it on the language and/or compiler. "Timing" has nothing to do with writing deterministic code.

    2. Re:The bigger problem is undefined behavior by Anonymous Coward · · Score: 0

      "Timing" has nothing to do with writing deterministic code.

      Timing has everything to do with deterministic code. Deterministic means 2 things. Does the same thing every time. Does it in X amt of time. Not x+/-y depending on compilers or other factors in the system.

      "Timing" comes into play with multi-threading because most OS schedulers are non deterministic. So you can be running 2 programs on your system and get result 1. Run 3 and get result 2.

      There are non-deterministic behaviors in C. They have fixed many of them in the newer versions of the language. But we do not always have the luxury of using a compiler from the future. In many cases current compilers do not even meet spec. So you need to know what your compiler will do. In some cases you need to know what 4 different versions of GCC will do as well as VS and llvm.

      I met one guy who would proceed every true/false statement x=!!y; He could not prove that would work on all compilers. In fact I spent 2 weeks ripping it out because a specific ARM compiler would mess it up 10-20% of the time but it worked fine in x86 and mips world. Lucky we quickly got him off the project as he liked side effect programming.

      Most of the bugs I see out of compilers is when you are trying to do something clever with your code. Because they can not figure out what to do so they emit junk. Then when someone figures out that there is a bug there many times you can 'fix' the compiler bug by just writing simpler easier for humans to understand code.

    3. Re:The bigger problem is undefined behavior by Megol · · Score: 1
      Yes undefined behavior is a problem however I'd say the current drive to use that problem as an excuse to generate thoroughly invalid code like in GCC and LLVM/CLANG is a much larger one.

      Just because invoking an undefined case can essentially cause any effect (even launching nuclear missiles) doesn't mean doing that is a goal.

    4. Re:The bigger problem is undefined behavior by Immerman · · Score: 1

      Agreed. Iit seems like "This code may cause undefined behavior" would be one of the single most time- and aggravation-saving warnings a compiler could possibly emit. Granted 100% detection might be challenging, but even detecting the 80% of most common and non-obvious culprits could save millions of man-hours hunting down obscure bugs.

      Heck, it would seem to me that any time n optimizer is able to completely eliminate *anything* from my code (outside of instances of inlined or templated functions) then there's probably a problem - either I've written pointless code, or I've invoked undefined behavior. Even if the tie to source lines is tenuous at that point a "Optimization has completely eliminated some code in function Foo" warning would be valuable draw attention to potential problem spots, though I imagine false-positives might be a major issue for a naive warning implementation.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    5. Re:The bigger problem is undefined behavior by Immerman · · Score: 0

      > "Timing" has nothing to do with writing deterministic code.

      Actually yes, it does. Actual deterministic code will of course be designed to avoid timing issues, but virtually every possible way of causing a deadlock is *explicitly* a timing issue, and there's plenty of other less obvious bugs that can be introduced by timing issues exposed by naively programming as though for a single-threaded environment.

      You can't just claim timing is a non-issue when industry best practices are explicitly built upon avoiding timing issues. Mocking those who don't actually adhere to those best practices is of course permitted, but generally doesn't accomplish much beyond making you look like an asshole.

      Tell you what, I'll start this meeting of Imperfect Programmers Anonymous:
      Hello, my handle is Immerman, and I'm an excellent programmer. But every once in a while I accidentally write code with a really stupid bug in it.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    6. Re:The bigger problem is undefined behavior by Anonymous Coward · · Score: 0

      If you want this kind of deterministic behavior you really should use Ada instead of C and never dynamically allocate memory. Otherwise you're just fooling yourself.

    7. Re:The bigger problem is undefined behavior by Anonymous Coward · · Score: 0

      Writing deterministic behavior in C is possible. There are whole books/organizations that show how to do it. I have seen it done a few dozen times. Many micro-controllers need it. For the other 99% of code out there I dont care about race conditions. I usually only care at thread/shared boundary. Which *can* be the memory pool (but usually only for lock contention I care). But most of the time I still dont care. Learn to find what is really shared and worry about that.

      Most requirements do not care about something finishing in 3ns. Usually they care the font is the right color on the form in which case I would be using a compiler suite that is better for that like .net and has a decent library to back it up.

      Not everything has to be the fastest code *evar*!1!!!. Just the stuff that matters (like video games) :)

    8. Re:The bigger problem is undefined behavior by lgw · · Score: 1

      Optimizers "completely eliminate" code all the time, at least for good code. You'd drown in such warnings in the last C codebase I worked on. E.g., our standard called for all variables to be initialized at declaration, in some trivial way that can't itself have errors. So you get a lot of:
      int foo = 0; ...
      foo = NonTrivialFunction(bar); // do something with foo

      We expect the optimizer to remove the "= 0" wherever it's redundant, so there's no performance cost to this helpful technique.

      Or again
      MyClass *pFoo = NULL; ...
      pFoo = FindIt("bar");
      if (pFoo == NULL)
      {
          return ERROR;
      }

      Perhaps the compiler can prove that FindIt will always return a non-null value for the constant input, and can optimize away the null check. That doesn't in any way make the null check bad code (nor the initial NULL assignment, which likely got optimized away as well).

      --
      Socialism: a lie told by totalitarians and believed by fools.
    9. Re:The bigger problem is undefined behavior by lgw · · Score: 1

      Wow, slashcode randomly removes newlines in code blocks. WTF? Well, there's always tt.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    10. Re:The bigger problem is undefined behavior by hermitdev · · Score: 1

      Um, the multi-threaded memory model for C++ was just recently defined in C++11. Prior to that standard, there wasn't even an acknowledgement of multithreading/concurrency.

    11. Re:The bigger problem is undefined behavior by Immerman · · Score: 1

      Ugh, okay. I might still argue that the compiler is in fact detecting a problem, but there's no need to make the programmers drown in warnings they're not allowed to fix.

      But... point made. There would need to be a sanity line in there somewhere - like say if he compiler uses non-trivial contextual information to judge that things could safely be eliminated. Or if the elimination is only made possible by the choices made in interpreting undefined behavior. But the optimizer may well have already lost the contextual information necessary to make those calls.

      Yeah, that newline thing is annoying. IIRC it mostly applies to "..." and possibly some other punctuation. And might not be restricted to code, let's see:
      line 1 ...
      line 3

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    12. Re:The bigger problem is undefined behavior by hermitdev · · Score: 1

      Just because *you* write undefined behavior, doesn't make the code generated by the compiler any less or more valid. The compiler/optimizer are trying their best to generate the fasted code possible from the information given (by you). If you give it invalid or incomplete information, don't be surprised that the behavior isn't what you expected.

    13. Re:The bigger problem is undefined behavior by Anonymous Coward · · Score: 0

      That's a bad coding standard, IMO, as you may accidentally use foo prior to the *real* initialization (with a nonsense zero value) instead of letting the compiler warn you about it.

    14. Re:The bigger problem is undefined behavior by Daniel+Hoffmann · · Score: 1

      Your compiler will then also be able to program your application, mission accomplished I guess.

    15. Re:The bigger problem is undefined behavior by Immerman · · Score: 1

      Wait, what? How do you figure? All I'm saying is that the optimizer, which is already exploiting all manner of non-obvious opportunities for code elimination, could include a heuristic to warn about optimizations which may cause unintended behavior.

      And apparently the STACK project sort of does this already, though it isn't actually compiler per se. If I understand correctly it detects "dangerous" code by:
      1) Performing all normal, boring dead-code elimination
      2) Performing optimizing code elimination on (1), without the benefit of exploiting undefined behavior
      3) Performing optimizing code elimination on (1), while allowing maximum exploitation of undefined behavior.
      4) Reporting any code eliminated by (3) but not (2) as a likely problem spot

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    16. Re:The bigger problem is undefined behavior by lgw · · Score: 1

      In the bigger picture it's the right thing to do (it's mostly about pointers). You init the pointer to NULL in the init block. If you accidentally use it before initialization, you get a well-understood error condition, and you follow a well defined pattern in your exit block of freeing-if-not-NULL. It rarely comes up for ints, really.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  14. Rubbish summary, very little in the blog by gnasher719 · · Score: 5, Informative

    He actually observed that different assembler code was generated - well how do you think can you generate _faster_ assembler code without generating _different_ assembler code?

    The article does _not_ make any claim that any code would be working incorrectly, or give different results. The article _doesn't_ examine any user-reported issues. So on two accounts, the article summary is totally wrong.

    1. Re:Rubbish summary, very little in the blog by TheRaven64 · · Score: 5, Interesting

      Add to that, when we test compiler optimisations we do it on some body of code, on some set of microarchitectures, and enable it if it is a net benefit over our sample set. We don't (and can't) test every possible combination of code and microarchitectures. One of my favourite stories in this regard is actually a CPU optimisation rather than a compiler one. A newer generation of ARM core improved the branch predictor, and most things got faster. One core library used by a certain mobile phone OS got noticeably slower. It turned out that in the old CPU, the wrong branch was being predicted at a specific point that caused a load instruction to be speculatively executed and then discarded. When they improved the prediction, the correct path was taken. The value of the load was required some time later in this case. The bad behaviour was costing them a pipeline flush, but pulling the data into the cache. The good behaviour was causing them to block for a memory read. A stall of a dozen or so cycles became a stall of a hundred or so cycles, even though the new behaviour was effectively better.

      For compilers, you'll see similar problems. A few years ago, I found that my Smalltalk compiler was generating faster code than gcc for a fibonacci microbenchmark. It turned out that gcc just happened to hit a pathological case for cache layout in their code, which was triggering a load of instruction cache misses. Trivial tweaks to the C code made it an order of magnitude faster.

      If you really care about performance for your code, you should be regularly building it with the trunk revision of your favourite compiler and reporting regressions early. Once there's a test case, we have something to work with.

      --
      I am TheRaven on Soylent News
    2. Re:Rubbish summary, very little in the blog by tibit · · Score: 1

      It's even worse: I just have no idea what the article's point is, other than having a stab at some poor-man's innuendo. It's like if the author set out to write something, then promptly forgot what. Definitely doesn't cog well, that one.

      --
      A successful API design takes a mixture of software design and pedagogy.
    3. Re:Rubbish summary, very little in the blog by Megol · · Score: 5, Informative
      Not assembler code - assembly code. Assembler = compiler for assembly code.

      (Pet peeve - sorry)

    4. Re:Rubbish summary, very little in the blog by Anonymous Coward · · Score: 0

      Um, the summary just quotes what Cogswell wrote in the second blog piece.

    5. Re:Rubbish summary, very little in the blog by Anonymous Coward · · Score: 0

      I thought it just turned on the Turbo button.

    6. Re:Rubbish summary, very little in the blog by Anonymous Coward · · Score: 0

      A newer generation of ARM core improved the branch predictor, and most things got faster. One core library used by a certain mobile phone OS got noticeably slower. It turned out that in the old CPU, the wrong branch was being predicted at a specific point that caused a load instruction to be speculatively executed and then discarded. When they improved the prediction, the correct path was taken. The value of the load was required some time later in this case. The bad behaviour was costing them a pipeline flush, but pulling the data into the cache. The good behaviour was causing them to block for a memory read. A stall of a dozen or so cycles became a stall of a hundred or so cycles, even though the new behaviour was effectively better.

      http://www.google.com/patents/US5642493

    7. Re:Rubbish summary, very little in the blog by Darinbob · · Score: 1

      As an undergrad we'd get a variety of new machines for my particular year, so every new class it seems we were on a different machine that the department just acquired rather than tried and true VAXen. One of the machines was a new RISC-like computer (Pyramid) and was used by our compilter course. Every so often however the machine would crash and leave all the students in the terminal lab milling about until it came back up. The computer center staff were stumped by this until they tracked it down to one student's code emitted by his compiler. One particular type of divide instruction had not been tested well and some inputs would crash the machine hard; the company's own compilers never generated that instruction.

      Earlier on there was a mainframe stack based computer from Burroughs. And students were not allowed to write assembly for it without permission because there were all sorts of things that could crash the computer.

    8. Re:Rubbish summary, very little in the blog by Anonymous Coward · · Score: 0

      Assemblers process a lot of data and the operations are fairly independent. Doesn't it make sense to vectorize them?

  15. But I use Gentoo, how does this affect me? by NoNonAlphaCharsHere · · Score: 1

    I _cannot wait_ to see how much hilarity ensues in the Gentoo world, where it's real common for random clowns with no debugging (or bug reporting) ability to have -Oeverything set.

    1. Re:But I use Gentoo, how does this affect me? by Anonymous Coward · · Score: 0

      Dear $diety - how old is that meme?

  16. Re:Meh, fuck off you damn dirty apes. by Anonymous Coward · · Score: 0

    You stopped taking your meds again, didn't you? Maybe you should have a cookie and a glass of milk and then maybe a little nap.

  17. Undefined behaviour by Anonymous Coward · · Score: 0

    If you depend on undefined behaviour, and it seems to work, you're just lucky.

    The problem isn't the language, it's the offenders bad coding practices.

    1. Re:Undefined behaviour by Daniel+Hoffmann · · Score: 1

      Well you are correct, but other languages just throw an exception or error when you do something that ought to be undefined behavior. Many C / C++ undefined behaviors allow your program to keep running when you do something stupid.

      I'm not saying the problem is the language, if it did the same things the other languages do to prevent that kind of stuff the performance hit would be noticeable.

    2. Re:Undefined behaviour by Anonymous Coward · · Score: 0

      That's because C and C++ (there is no such thing as C/C++) aren't toy languages. They expect the programmer to know what his is doing.

    3. Re:Undefined behaviour by Daniel+Hoffmann · · Score: 1

      I forgot to mention that some compilers leave to the operating system to crash your application on some undefined behaviors. Which brings its own cross-platform problems.

    4. Re:Undefined behaviour by gnasher719 · · Score: 1

      Well you are correct, but other languages just throw an exception or error when you do something that ought to be undefined behavior. Many C / C++ undefined behaviors allow your program to keep running when you do something stupid.

      Well, in some cases. Problems like a [i] = i++; go away in Java because it defines what should happen: The expression is evaluated strictly left to right, so the old value of i is stored into a [i], then i is increased by 1. Bad array indexes an nil pointers throw exceptions (which themselves will cause trouble if this was unexpected). But there are things like "restrict" in C which causes undefined behaviour if used wrong, but that is explicitly intended because it allows serious compiler optimisations.

    5. Re:Undefined behaviour by Grishnakh · · Score: 1

      (there is no such thing as C/C++)

      This is Slashdot, not HRhangout. We know they're two different languages. We also know they're closely related and share a lot of similarities, since C++ is, after all, a descendant of C (with a lot of big changes, obviously). So "C/C++" is a convenient way to save some keystrokes.

      We can't help it if a bunch of HR morons think they're the same language.

    6. Re:Undefined behaviour by Immerman · · Score: 1

      Humans occasionally make mistakes, invariably. Regardless of talent, skill, intelligence, or experience.

      There's no need to change the language, a simple "this code may invoke undefined behavior" compiler warning would eliminate countless hours of debugging.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
  18. 4.8.1 has bugs, some of these have been fixed by inglorion_on_the_net · · Score: 4, Informative

    Having been somewhat involved in the migration of a lot of C++ code from older versions of gcc to gcc 4.8.1, I can tell you that 4.8.1 definitely has bugs, in particular with -ftree-slp-vectorize. This doesn't appear to be a huge problem in that almost all the (correct) C++ code we threw at the compiler produced good compiler output, meaning that the quality of the compiler is very good overall. If you do find a bug, and you have some code that reproduces the problem, file a bug report, and the gcc devs will fix the problem. At any rate, gcc 4.8.2 has been out for a number of months now, so if you're still on 4.8.1, you may want to upgrade.

    --
    Please correct me if I got my facts wrong.
    1. Re:4.8.1 has bugs, some of these have been fixed by Anonymous Coward · · Score: 0

      Has the "(2 < 2) is true" bug been fixed ?

  19. Re:Meh, fuck off you damn dirty apes. by tibit · · Score: 1

    Protip: Don't confuse compiler devs with people who specify programming languages. It makes you look stupid.

    --
    A successful API design takes a mixture of software design and pedagogy.
  20. cmpxchg8b by little1973 · · Score: 1, Informative

    I haven't tried this with the latest version by even a version 4.x GCC cannot generate inline code with the 8 bytes version of cmpxchg with 32bit code. Doing this in a function is OK.

    I think the problem is that this instruction almost takes up all of the registers and GCC cannot cope with this if you want to do it inline.

    cmpxchg8b is useful for lock-free code.

    --
    Government cannot make man richer, but it can make him poorer. - Ludwig von Mises
  21. Re:Meh, fuck off you damn dirty apes. by Megol · · Score: 1

    Here's some others: Don't confuse undefined behavior with useless behavior. Don't confuse undefined behavior with a free ticket to generate whatever crap code you'd want.

  22. Protect from yourself. by Anonymous Coward · · Score: 0

    C does what you tell it to.
    If you tell it to do something stupid, it will still try to do it.

    It's up to YOU to not tell it to do stupid things.

    Maybe you need a static code checker?

    1. Re:Protect from yourself. by Waffle+Iron · · Score: 2

      C does what you tell it to.
      If you tell it to do something stupid, it will still try to do it.

      If it's stupid, then the compiler should have issued an error.

      It's up to YOU to not tell it to do stupid things.

      Which is silly, because the reason computers exist in the first place is to help us slow, error-prone humans by doing logical computations for us.

      Maybe you need a static code checker?

      Yes, but the static code checker should have been built into the compiler from day one.

    2. Re:Protect from yourself. by lgw · · Score: 1

      Well, it kindof is, but the spec doesn't try to call out every stupid thing you need to warn users about. Compiling with warnings, extra warnings, and pedantic warnings enabled will find a lot of stuff. But those are warnings, not errors, for a reason: sometimes you really do know better.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  23. Re:And importantly is your code standards complian by Immerman · · Score: 1

    >GCC 4.2.1 for example, with -o0 (least optimisation) will eliminate if(p+100p)
    Seriously? Wait, no, I thing Slashdot just ate your &lt, and that should be if(p+100 &lt p)

    edit: Wait, Slashdot silently swallows malformed "HTML tags", but doesn't parse &lt properly? How the $#@! are you supposed to include a less-than sign?

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
  24. Re:And importantly is your code standards complian by Muad'Dave · · Score: 4, Informative

    << LIke This >>

    Hint: the trailing ';' is not optional.

    --
    Tiller's Rule: Never use a word in written form that you've only heard and never read. You will end up looking foolish.
  25. How to locate optimization bugs? by Immerman · · Score: 1

    On a related note, does anyone have any suggestion on how to track down such bugs? Are there for example code-analysis tools that will highlight code with undefined behavior likely to give different results when optimized, or valid code that may trigger known compiler bugs? It seems like such a thing would be immensely valuable - if I have a compiler-related mystery bug *somewhere* in my codebase, being able to narrow that down to even the 0.1% of lines containing "suspicious" code could make the difference between it being impossible to solve and merely difficult.

    In fact I'm rather surprised that "this code may cause undefined behavior" isn't a standard compiler warning. I mean C and C++ are performance-oriented languages that practically invite developers to come up with "clever" solutions, a warning that they have exceeded the sometimes non-obvious limits of defined behavior would probably save more debugging hours than any other warning on the planet.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
    1. Re:How to locate optimization bugs? by MtHuurne · · Score: 1

      A project specifically about finding undefined behavior is STACK. It didn't find any problems on the two projects I tried it on, but one of those is rather small and the other is pretty mature, so maybe most of the undefined behavior has been fixed already.

      Just setting the warning levels a bit higher ("-Wall -Wextra" in GCC; despite the name "-Wall" doesn't actually enable all warnings) will already help a lot in spotting potentially dangerous constructs.

      Also useful is Clang's analyzer mode ("clang --analyze"), maybe not so much for undefined behavior, but it did find a few cases of wrong pointer use (such as a potential null pointer dereference) in code I tried it on.

      For C++ there is also Cppcheck, which is good at finding potential problems related to classes, for example data members that are not initialized by a constructor: initialization of class types is enforced, but C++ does allow data members of primitive types to be uninitialized after construction, for some reason.

    2. Re:How to locate optimization bugs? by Immerman · · Score: 1

      Thanks!

      I've been playing with cppcheck for a while now, it should be interesting seeing how STACK (ahem) stacks up. I find myself almost hoping it finds some nasty bugs-waiting-to-happen in my code just to see it in action "firsthand" as it were.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
  26. Re:Meh, fuck off you damn dirty apes. by Immerman · · Score: 1

    > counting backwards is faster because comparing to the static value 0 is faster
    Quite so. However if you're counting there's a pretty good chance that you're traversing an array, in which case caching optimizations that presume a forward traversal will tend to completely overwhelm any potential gains from comparing to a constant instead of a variable.

    While we're ranting, why is _++ even a distinct operator from ++_? Are there really that many situations where i++ can streamline the code significantly? We're only human, it's physically impossible for us to retain and apply every subtly of an 800+ page language specification indefinitely, even if it were completely unambiguous to begin with.

    As for your example, actually there's a very good reason for it to be undefined behavior: The fewer restrictions placed on the order of evaluations of generally non-interacting elements, the more opportunities are exposed for optimization, especially once you bring parallel and vectorized CPUs into the equation. And imposing deterministic evaluation order only when side effects may be present then introduces numerous special cases which require expanding the standard and drastically complicating compiler implementation, with a corresponding increase in bugs and reduction in optimizations due to excessive caution. Warnings would be nice though. Even if the fact that Funky( Foo(), Bar() ) causes undefined behavior because of side effects buried 63 function-calls down would likely still slip by, at least the most obvious problems would be caught and perhaps serve as a reminder that caution must be exercised.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
  27. C++ Re-write by turgid · · Score: 1

    Is gcc 4.8 the one where the compiler source was completely converted to C++?

    /me ducks.

  28. Flight Critical Software by Anonymous Coward · · Score: 0

    If you're using virtual memory, you're doing it wrong. Malloc() my ass.

  29. Re:And importantly is your code standards complian by Darinbob · · Score: 1

    The start of the summary was just so bizarre to me. Of course different versions generate different code, that's what happens when you change how code is optimized. Why would someone set out to investigate this, except as a question about how it improves the code.

    Now if there's a bug that's a different issue, and all compilers are going to have some sort of bugs somewhere as these are complex pieces of code. But a change in the output should never be treated as evidence of a bug.

  30. Re:And importantly is your code standards complian by Anonymous Coward · · Score: 0

    This.

    I've seen a few cases where I've inherited code working on 4.7 that broke on 4.8. In all cases compiling with -Wall -Wextra -Werror and then correcting all the mistakes it flagged up removed the errors. Basically the only reason it was working in the first place was the original developer was making assumptions about how the specific compiler would behave in undefined circumstances. By cleaning up the code it was now only relying on defined behaviour.

  31. Re:Meh, fuck off you damn dirty apes. by lgw · · Score: 1

    While we're ranting, why is _++ even a distinct operator from ++_?

    Some platforms has a preincrement and postdecrement opcodes, but not the converse. Some vice versa. Once upon a time, a programmer would care about such things, and C would never have gained the acceptance it did without the ability to use what looked fast on your platform. Heck, there are still coders who use the "register" keyword, as if that still did anything.

    --
    Socialism: a lie told by totalitarians and believed by fools.
  32. GCC 4.8 disaster by Anonymous Coward · · Score: 0

    The real issue with GCC 4.8 is it uses C++ as implementation language, so now I need a C++ compiler to compile a C compiler. Fuuuuuuuuuck.

  33. Re:And importantly is your code standards complian by hermitdev · · Score: 1

    The GP has a valid point. Most people complaining of these optimizer "bugs" likely have undefined behavior. In C & C++, the compiler/optimizer/linker is given full freedom on what to do. Often, the compiler will just eliminate the code. It could, in theory, format your hard drive. Yes, compiler bugs do happen, but they tend to be rare and infrequent. Last GCC bug I saw was on a minor revision of 4.1.2 that caused an ICE (internal compiler error) when you had an anonymous namespace at the global namespace level.

  34. Re:Meh, fuck off you damn dirty apes. by Immerman · · Score: 1

    Ah, that would explain it.

    And I imagine there's some compilers for embedded systems that still take "register" seriously.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
  35. Re:And importantly is your code standards complian by Anonymous Coward · · Score: 0

    GCC 4.2.1 for example, with -o0 (least optimisation) will eliminate if (p+100<p)

    With pointers that's fairly reasonable, because they practically never overflow like that anyway, but it applies to signed integers as well and there it's fairly dangerous optimization. Many overflow checks etc are easiest to do with wraparound arithmetic and it's terribly easy to forget the unsigned keyword there (thus invoking UB) and the resulting bugs get promoted from lurking portability issues to actual live security hazards.

  36. Are you an idiot? by Anonymous Coward · · Score: 0

    Nm, rhetorical question, you ARE an idiot. GCC has extensive regression tests, any patch that you send in MUST come with tests, and if you RTFA you will see that it doesn't mention any actual bugs. Most complaints about GCC 4.8 optimizations are from users who wrote code that did stuff that the C standard said would cause undefined behavior, but in older compilers happened to do predictable things so the buggy user code went into production without anyone noticing. GCC 4.8 optimizes more aggressively and if your code does undefined operations, all the dire warnings about that will ACTUALLY COME TO PASS instead of being FUD. Of course there ARE compiler bugs but the more common case is user code bugs that newer compilers actually trigger. C is just a bloody dangerous language and people unwilling to deal with that shouldn't be writing in it. See blog.regehr.org for much more.

  37. Run with KCC by Anonymous Coward · · Score: 0

    to find undefined behaviour, using Clang static analyzer or something like Coverity, etc. are all approaches to pursue.

    Some info about KCC is here: http://blog.regehr.org/archives/523

    Basically the code that comes out of it is slower than crap, but it checks just about every error condition and undefined behaviour you can imagine, and tells you if it hits such a thing. I want to start using it (haven't yet).

  38. Risk Bjarne's wrath at your own risk. by Anonymous Coward · · Score: 0

    Even Stroustrup hates seeing C/C++.

    C++ in an intersection, not a subset, of C.

    If you are writing your C++ code with a C mindset, you are doing it wrong and should get the fuck out.

  39. Script Kiddie by Anonymous Coward · · Score: 0

    Get back to Python you script kiddie piece of shit.

  40. wtf? by Anonymous Coward · · Score: 0

    You need the compiler to do everything for you?

    If you don't know if something is stupid, GTFO.

  41. WTF? by Anonymous Coward · · Score: 0

    Now the compiler is supposed to reason out your intent?

    What are you smoking, numbnuts.