<html>
    <head>
      <base href="http://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 --- - crash due to incorrect ARM code generated for std::vector initialization"
   href="http://llvm.org/bugs/show_bug.cgi?id=20415">20415</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>crash due to incorrect ARM code generated for std::vector initialization
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>itsme@xs4all.nl
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>compile and link the code pasted below to an ios binary, make sure you call the
'tstv' function.

the program will crash when compiled with -O3


commandline used to generate the assembly listing:

clang++ -S -arch armv7s -O3  -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk
-o armv7s.s tstv.cpp

my compiler version:

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)

the xcode6 beta compiler ( Apple LLVM version 6.0 (clang-600.0.41.2) (based on
LLVM 3.5svn)  )
shows the same problem


======= tstv.cpp
#include <vector>

extern void logmsg(const char*);

template<typename T>
struct buf : std::vector<T>
{
    buf(int n) : std::vector<T>(n) { logmsg("+"); }
    ~buf() { logmsg("-"); }
};

void tstv()
{
    buf<int>  b(256);
    buf<char> a(256); // <<< here will be the crash
}

======== logmsg.cpp
// this needs to be in a seperate compilation unit
void logmsg(const char*)
{
}

===========================
the generated assembly code showing the problem

Ltmp1:
@ BB#3:                                 @ %_ZN3bufIiEC1Ei.exit
    ldr    r0, [sp, #8]    @ <<<<<<<<<<< problem: reading uninitialized ptr
value before 'new' is stored
    str    r0, [sp]                @ 4-byte Spill
    movs    r0, #2
    str    r0, [sp, #16]
Ltmp3:
    mov.w    r0, #256
    blx    __Znwm
Ltmp4:
@ BB#4:                                 @
%_ZN3bufIiEC1Ei.exit..preheader_crit_edge
    ldr    r2, [sp]                @ 4-byte Reload
    movs    r1, #0
    str    r0, [sp, #8]
    mvn    r0, #255
LBB0_5:                                 @ %.preheader
                                        @ =>This Inner Loop Header: Depth=1
    cmp    r2, #0
    ite    ne
    strbne    r1, [r2]        @ <<<<<<<<<<< using wrong value loaded at Ltmp1
    moveq    r2, #0
    adds    r0, #1
    add.w    r2, r2, #1
    bne    LBB0_5</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>