Pages

Wednesday, August 10, 2011

On Compilers, Insanity, and Global Variables

According to Einstein, the definition of insanity goes something like the following: "doing the same thing over and over again and expecting different results." Compilers should always produce the same code given the same input. However, I have noticed something now as well as before. I rely on gcc's predicate function for telling my analysis if a variable I am looking at is "global" or not. I have started to notice that I can run the compile once and the variable is not global (which is how the source code defines it). Although I can run the same compile again, and the variable is global?! The compiler is making me second-guess my sanity. How is this possible? Well, I know there is performance data that gcc can generate, which as I can imagine, aside from timestamps, is really the only non-deterministic event in gcc. I am not sure if this insanity-cause is from the front-end or from the middle-end. I have md5 summed my plugin and it is the same with both the "compiler thinks its global" and the "compiler thinks its not global" case. Hmmmmmmmmmm...

-Matt

4 comments:

  1. Either GCC is acting very weirdly, or you have an MD5 collision :)

    ReplyDelete
  2. I probably screwed something up. I really trust gcc. The trouble is, if I use a artificial memory environment, such as gdb, I can't recreate the "bug." I'm thinking there is some memory stomp going on.

    ReplyDelete
  3. "I'm concerned about the mission, Matt."
    With apologies to Arthur c. Clarke :)

    ReplyDelete
  4. As always, world domination...

    ReplyDelete