[PATCH] D15742: Fix infinite recursion in MCAsmStreamer::EmitValueImpl

Alexandru Guduleasa via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 30 05:45:36 PST 2015

alexandru.guduleasa updated the summary for this revision.
alexandru.guduleasa updated this revision to Diff 43786.
alexandru.guduleasa added a comment.

I've updated the comment just above the changes.
Also, I've computed the EmissionSize based on the min of (Size - 1) and Remaining.
This is closer to the original implementation.
If Size is a number that is not a power of 2 (e.g. 7), this should result in a 4+2+1 split in normal cases.
If the target does not support 4, instead of looping we will split as 2+2+2+1; the 2 values may be split as 1+1 if required.

Unfortunately, this can't be tested since I don't think there is a target in the official repository that can't emit 4 bytes.



Index: lib/MC/MCAsmStreamer.cpp
--- lib/MC/MCAsmStreamer.cpp
+++ lib/MC/MCAsmStreamer.cpp
@@ -708,17 +708,15 @@
       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 =

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15742.43786.patch
Type: text/x-patch
Size: 1377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151230/a4956b2f/attachment.bin>

More information about the llvm-commits mailing list