title: Why is Clang optimizing this code out?
body: <p>The purpose of the code is to find the total number of 32-bit floating point bit patterns which represent values between 0 and 1. It seems to me this should work, but for some reason the assembly output from Clang is basically the equivalent of <code>return 0;</code>.</p>
  
  <p>I compiled this with Clang 3.3 and Clang 3.4.1, using <code>-std=c++1y -Wall -Wextra -pedantic -O2</code> and <code>-std=c++1y -Wall -Wextra -pedantic -O3</code></p>
  
  <p>Clang 3.4 optimizes everything away with -O2 and -O3.</p>
  
  <p>Clang 3.3 only optimizes everything away with -O3.</p>
  
  <p>By "optimizes everything away" I mean that this is the assembly output of the program:</p>
  
  <pre><code>main:                                   # @main
      xorl    %eax, %eax
      ret
  </code></pre>
  
  <pre class="lang-c++ prettyprint-override"><code>#include &lt;limits&gt;
  #include &lt;cstring&gt;
  #include &lt;cstdint&gt;
  
  template &lt;class TO, class FROM&gt;
  inline TO punning_cast(const FROM &amp;input)
  {
      TO out;
      std::memcpy(&amp;out, &amp;input, sizeof(TO));
      return out;
  }
  
  int main()
  {
      uint32_t i = std::numeric_limits&lt;uint32_t&gt;::min();
      uint32_t count = 0;
  
      while (1)
      {
          float n = punning_cast&lt;float&gt;(i);
          if(n &gt;= 0.0f &amp;&amp; n &lt;= 1.0f)
              count++;
          if (i == std::numeric_limits&lt;uint32_t&gt;::max())
              break;
          i++;
      }
  
      return count;
  }
  </code></pre>