]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Use the correct size for MCFillFragment
authorSam Clegg <sbc@chromium.org>
Mon, 10 Jul 2017 18:36:34 +0000 (18:36 +0000)
committerSam Clegg <sbc@chromium.org>
Mon, 10 Jul 2017 18:36:34 +0000 (18:36 +0000)
Summary: When implementing MCFillFragment, use the size of the fragment,
rather than the size of the section.

Patch by Dan Gohman

Differential Revision: https://reviews.llvm.org/D35090

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

lib/MC/WasmObjectWriter.cpp
test/MC/WebAssembly/array-fill.ll [new file with mode: 0644]

index 769dbb810ed7f8e8ea50f3bac59a28724c42a755..a38d9339880c9588c8fd23fcff17cf446e995800 100644 (file)
@@ -1197,7 +1197,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
                                                  Align->getMaxBytesToEmit());
           DataBytes.resize(Size, Value);
         } else if (auto *Fill = dyn_cast<MCFillFragment>(&Frag)) {
-          DataBytes.insert(DataBytes.end(), Size, Fill->getValue());
+          DataBytes.insert(DataBytes.end(), Fill->getSize(), Fill->getValue());
         } else {
           const auto &DataFrag = cast<MCDataFragment>(Frag);
           const SmallVectorImpl<char> &Contents = DataFrag.getContents();
diff --git a/test/MC/WebAssembly/array-fill.ll b/test/MC/WebAssembly/array-fill.ll
new file mode 100644 (file)
index 0000000..4feabc0
--- /dev/null
@@ -0,0 +1,14 @@
+; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
+; PR33624
+
+source_filename = "ws.c"
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+%struct.bd = type { i8 }
+
+@gBd = hidden global [2 x %struct.bd] [%struct.bd { i8 1 }, %struct.bd { i8 2 }], align 1
+
+; CHECK:  - Type:            DATA
+; CHECK:        Content:         '0102'
+; CHECK:    DataSize:        2