Add assertion to padding size calculation, NFC
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 2 May 2018 17:20:22 +0000 (17:20 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 2 May 2018 17:20:22 +0000 (17:20 +0000)
The size of an object cannot be less than the emitted size of all the
contained elements. This would cause an overflow in padding size
calculation. Add an assert to catch this.

Patch by Suyog Sarda.

llvm-svn: 331376

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

index a1af6fd..a55f7c2 100644 (file)
@@ -2235,6 +2235,7 @@ static void emitGlobalConstantDataSequential(const DataLayout &DL,
   unsigned Size = DL.getTypeAllocSize(CDS->getType());
   unsigned EmittedSize = DL.getTypeAllocSize(CDS->getType()->getElementType()) *
                         CDS->getNumElements();
+  assert(EmittedSize <= Size && "Size cannot be less than EmittedSize!");
   if (unsigned Padding = Size - EmittedSize)
     AP.OutStreamer->EmitZeros(Padding);
 }