From 52570ea2a2498b8462e2a3a20576aea07647758d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 1 Feb 2016 20:36:49 +0000 Subject: [PATCH] Fix infinite recursion in MCAsmStreamer::EmitValueImpl. If a target can only emit 8-bits data, we would loop in EmitValueImpl since it will try to split a 32-bits data in 1 chunk of 32-bits. No test since all current targets can emit 32bits at a time. Patch by Alexandru Guduleasa! llvm-svn: 259399 --- llvm/lib/MC/MCAsmStreamer.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index b31fd2c..1bac42a 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -720,17 +720,15 @@ void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, report_fatal_error("Don't know how to emit this value."); // We couldn't handle the requested integer size so we fallback by breaking - // the request down into several, smaller, integers. Since sizes greater - // than eight are invalid and size equivalent to eight should have been - // handled earlier, we use four bytes as our largest piece of granularity. + // the request down into several, smaller, integers. + // Since sizes greater or equal to "Size" are invalid, we use the greatest + // power of 2 that is less than "Size" as our largest piece of granularity. bool IsLittleEndian = MAI->isLittleEndian(); for (unsigned Emitted = 0; Emitted != Size;) { unsigned Remaining = Size - Emitted; // The size of our partial emission must be a power of two less than - // eight. - unsigned EmissionSize = PowerOf2Floor(Remaining); - if (EmissionSize > 4) - EmissionSize = 4; + // Size. + unsigned EmissionSize = PowerOf2Floor(std::min(Remaining, Size - 1)); // Calculate the byte offset of our partial emission taking into account // the endianness of the target. unsigned ByteOffset = -- 2.7.4