<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Optimizing loop with sizeof("literal")"
   href="https://llvm.org/bugs/show_bug.cgi?id=25429">25429</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optimizing loop with sizeof("literal")
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hugo.guiroux@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15233" name="attach_15233" title="minimal working example">attachment 15233</a> <a href="attachment.cgi?id=15233&action=edit" title="minimal working example">[details]</a></span>
minimal working example

Compiling with clang++ the minimal working example, I get the following result:

clang++ -O3 -Wall -o sizeof_vs_strlen sizeof_vs_strlen.cpp
./sizeof_vs_strlen
Strlen 36 ret=4
Sizeof 62092396 ret=5

With g++:

g++ -O3 -Wall -o sizeof_vs_strlen sizeof_vs_strlen.cpp 
./sizeof_vs_strlen
Strlen 30 ret=4
Sizeof 30 ret=5

The assembly generated by clang++ for the loop with sizeof:
rdtsc  
mov    %edx,%r14d
shl    $0x20,%r14
mov    $0x3b9aca01,%ecx
xchg   %ax,%ax
add    $0xffffffed,%ecx // 0x400ad0
jne    0x400ad0 <main+192>
mov    %eax,%eax
or     %rax,%r14
rdtsc  

And the one by g++:
rdtsc  
mov    %edx,%esi
mov    %eax,%ecx
rdtsc
I don't understand why clang++ do the {add, jne} loop, it seems to be a bug

For information:
g++ (GCC) 5.1.0
clang version 3.6.2 (tags/RELEASE_362/final) (also tested with 3.7.0, same
bug).

The bug was originally describe on stackoverflow
(<a href="http://stackoverflow.com/questions/33562365/clang-sizeofliteral-optimization">http://stackoverflow.com/questions/33562365/clang-sizeofliteral-optimization</a>).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>