[cfe-dev] Crash on alignments >= 2**16 (PR26444)

don hinton via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 16 09:48:35 PST 2016


Hi Philip:

Clang does check to make sure max alignment is <= 29, so that is
consistent, however, AggValueSlot stores it in an unsigned short. On my
system, OSX, that means values >= 2**16 are stored as 0, which causes and
assert/crash.

I submitted a patch over the weekend to change it to an unsigned,
http://reviews.llvm.org/D17248, but it hasn't been reviewed yet.

thanks for taking a look...
don

On Tue, Feb 16, 2016 at 12:36 PM, Philip Reames <listmail at philipreames.com>
wrote:

> From the LLVM perspective, the maximum alignment is specified as:
>
> In Value.h:
> 00520   /// \brief The maximum alignment for instructions.00521   ///00522   /// This is the greatest alignment value supported by load, store, and alloca00523   /// instructions, and global values.00524 <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a50e02a54cc6f87a00a671265e1447e61>   static const unsigned MaxAlignmentExponent <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a50e02a54cc6f87a00a671265e1447e61> = 29;00525 <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a2885f6c5817ff68bc24bd1e22e221740>   static const unsigned MaximumAlignment <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a2885f6c5817ff68bc24bd1e22e221740> = 1u << MaxAlignmentExponent <http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a50e02a54cc6f87a00a671265e1447e61>;
>
>
> This is checked in the Verifier via:
>  Assert(GV.getAlignment() <= Value::MaximumAlignment,
>           "huge alignment values are unsupported", &GV);
> (and similiar checks for Load, Store, Alloca, but not the various atomic
> instructions)
>
>
>
>
>
>
> On 02/14/2016 01:30 PM, don hinton via cfe-dev wrote:
>
> Sema::AddAlignment() defines MaxValidAlignment like this:
>
>   // Alignment calculations can wrap around if it's greater than 2**28.
>   unsigned MaxValidAlignment =
>       Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
>                                                               : 268435456;
>
> But AggValueSlot stores Alignment as an unsigned short:
>
> class AggValueSlot {
> ...
>   unsigned short Alignment;
>
> The max value for an unsigned short is 2**16 -1, but you are passing 2**16, which AddeAlignment says is okay.  However, it ends up getting stored as 0 in an unsigned short.
>
> The fix is to make these sizes consistent, but I'm not sure which should be changed  (though I'm guessing Alignment should be unsigned instead of unsigned short).
>
>
>
> _______________________________________________
> cfe-dev mailing listcfe-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160216/0852112a/attachment.html>


More information about the cfe-dev mailing list