title: Why does GCC 6 assume data is 16-byte aligned?
body: <p><em>(Sorry in advance for not having managed to reduce my problem to a simple failing test case...)</em></p>
  
  <p>I have faced issues with upgrading to GCC 6.3.0 to build our codebase (relevant flags: <code>-O3 -m32</code>).</p>
  
  <p>Specifically, my application segfaults within a struct ctor call because of GCC optimizations.</p>
  
  <p>In this ctor, GCC used <code>movaps</code> :</p>
  
  <pre><code>movaps %xmm0,0x30a0(%ebx)
  </code></pre>
  
  <p><code>movaps</code> <em>requires</em> the operand to be <strong>16-byte aligned</strong>. But at this point in time, <code>%ebx</code> points to my object, which is <strong>not necessarily 16-byte aligned</strong>. From glibc :</p>
  
  <blockquote>
    <p>“The address of a block returned by malloc or realloc in GNU systems is always a multiple of eight (or sixteen on 64-bit systems).“</p>
  </blockquote>
  
  <p>Hence the segfault (when built with <code>-O3 -m32</code>).</p>
  
  <p><strong>Why does it seem like GCC assumed the allocated object would be 16-byte aligned ? Am I misunderstanding something ?</strong></p>
  
  <p>Notes:</p>
  
  <ul>
  <li>No alignment hints or attributes on this struct</li>
  <li>Object has been initialized via default <code>new</code> operator</li>
  <li>Depends on the level of optimization:
  
  <ul>
  <li>PASS: <code>-m32 -O2</code></li>
  <li>FAIL: <code>-m32 -O2 -ftree-slp-vectorize</code></li>
  <li>PASS: <code>-m32 -O3 -fno-tree-slp-vectorize</code></li>
  <li>FAIL: <code>-m32 -O3</code></li>
  </ul></li>
  </ul>
  
  <hr>
  
  <p>This other project, seem to have hit similar issues : <a href="https://github.com/godotengine/godot/issues/4623" rel="noreferrer">https://github.com/godotengine/godot/issues/4623</a></p>
  
  <p>Their investigation points to <code>-fvect-cost-model=dynamic</code>. Investigation on my codebase rather points to <code>-ftree-slp-vectorize</code>.</p>