<div><div>I've been working on a target with an exotic configuration: 64-bit integers are 8-byte aligned in memory (in structures and globals), but 4-byte aligned on the stack.</div><div><br></div><div>As a result, a bug emerged with how VAARG alignment is chosen. In SelectionDAGBuilder.cpp:</div>
<div><br></div><div><div><font face="'courier new', monospace">void SelectionDAGBuilder::visitVAArg(const VAArgInst &I) {</font></div><div><font face="'courier new', monospace">  const TargetData &TD = *TLI.getTargetData();</font></div>


<div><font face="'courier new', monospace">  SDValue V = DAG.getVAArg(TLI.getValueType(I.getType()), getCurDebugLoc(),</font></div><div><font face="'courier new', monospace">                           getRoot(), getValue(I.getOperand(0)),</font></div>


<div><font face="'courier new', monospace">                           DAG.getSrcValue(I.getOperand(0)),</font></div><div><font face="'courier new', monospace">                           TD.getABITypeAlignment(I.getType()));</font></div>


<div><font face="'courier new', monospace">  setValue(&I, V);</font></div><div><font face="'courier new', monospace">  DAG.setRoot(V.getValue(1)); </font></div>
<div><font face="'courier new', monospace">}</font></div></div><div><br></div><div>This invokes TD.getABITypeAlignment() to get the alignment for va_arg. However, va_arg values actually reside on the stack. </div>


<div><br></div><div>Attached is a patch which changes the above code to use TD.getCallFrameTypeAlignment() instead. This change fixed the problem with my exotic configuration, however it may also have ramifications for other architectures.</div>
<div><br></div><div>Could someone with more general target knowledge comment on the correctness of this change?</div><div><br></div><div>Thank you,</div><div>  David Meyer</div>
</div>