Use MCFillFragment for zero-initialized data.
authorSerge Pavlov <sepavloff@gmail.com>
Thu, 27 Jun 2013 14:35:03 +0000 (14:35 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Thu, 27 Jun 2013 14:35:03 +0000 (14:35 +0000)
It fixes PR16338 (ICE when compiling very large two-dimensional array).

Differential Revision: http://llvm-reviews.chandlerc.com/D1043

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185080 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCObjectStreamer.h
include/llvm/MC/MCStreamer.h
lib/MC/MCAssembler.cpp
lib/MC/MCObjectStreamer.cpp
lib/MC/MCStreamer.cpp

index 5941993339cd67f849ca7f1a4ad5611ab3836b19..851a0e07e411ff311f56134ef8fef579dff402ae 100644 (file)
@@ -116,6 +116,7 @@ public:
   virtual void EmitGPRel64Value(const MCExpr *Value);
   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
                         unsigned AddrSpace = 0);
+  virtual void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0);
   virtual void FinishImpl();
 
   /// @}
index 2cab481c3d8d8f515e7fe1a70f545d164226a440..34970b1200978ed5291a930d77c3077c43d1c0d0 100644 (file)
@@ -472,11 +472,9 @@ namespace llvm {
     virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
                           unsigned AddrSpace = 0);
 
-    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
-    /// function that just wraps EmitFill.
-    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) {
-      EmitFill(NumBytes, 0, AddrSpace);
-    }
+    /// \brief EmitZeros - Emit NumBytes worth of zeros.
+    /// This function properly handles data in virtual sections.
+    virtual void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0);
 
     /// EmitValueToAlignment - Emit some number of copies of @p Value until
     /// the byte alignment @p ByteAlignment is reached.
index 97f675a1ffa993f0d6334f0fb65359334722f61d..24f4b8e635ea4101482ced848a08d4b7c4f1f05d 100644 (file)
@@ -708,12 +708,13 @@ void MCAssembler::writeSectionData(const MCSectionData *SD,
       case MCFragment::FT_Align:
         // Check that we aren't trying to write a non-zero value into a virtual
         // section.
-        assert((!cast<MCAlignFragment>(it)->getValueSize() ||
-                !cast<MCAlignFragment>(it)->getValue()) &&
+        assert((cast<MCAlignFragment>(it)->getValueSize() == 0 ||
+                cast<MCAlignFragment>(it)->getValue() == 0) &&
                "Invalid align in virtual section!");
         break;
       case MCFragment::FT_Fill:
-        assert(!cast<MCFillFragment>(it)->getValueSize() &&
+        assert((cast<MCFillFragment>(it)->getValueSize() == 0 ||
+                cast<MCFillFragment>(it)->getValue() == 0) &&
                "Invalid fill in virtual section!");
         break;
       }
index a1ed01cebcd178b512713589c8a4f0cf91cc6c23..b2c9c5d0459a72c5d6225e25df06a295750ee185 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/Support/ErrorHandling.h"
 using namespace llvm;
 
@@ -374,6 +375,12 @@ void MCObjectStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
   getOrCreateDataFragment()->getContents().append(NumBytes, FillValue);
 }
 
+void MCObjectStreamer::EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
+  assert(AddrSpace == 0 && "Address space must be 0!");
+  unsigned ItemSize = getCurrentSection().first->isVirtualSection() ? 0 : 1;
+  insert(new MCFillFragment(0, ItemSize, NumBytes));
+}
+
 void MCObjectStreamer::FinishImpl() {
   // Dump out the dwarf file & directory tables and line tables.
   const MCSymbol *LineSectionSymbol = NULL;
index 96dcf5c7157d055950de24e9ffdf97735d813c99..e4c6ce35ce4f8ca39427bc4189347e5da10da687 100644 (file)
@@ -154,6 +154,12 @@ void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
     EmitValue(E, 1, AddrSpace);
 }
 
+/// EmitZeros - Emit NumBytes worth of zeros.  Implementation in this class
+/// just redirects to EmitFill.
+void MCStreamer::EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
+  EmitFill(NumBytes, 0, AddrSpace);
+}
+
 bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
                                         StringRef Directory,
                                         StringRef Filename, unsigned CUID) {