]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Don't try to emit size information for unsized types
authorDan Gohman <dan433584@gmail.com>
Thu, 7 Dec 2017 00:14:30 +0000 (00:14 +0000)
committerDan Gohman <dan433584@gmail.com>
Thu, 7 Dec 2017 00:14:30 +0000 (00:14 +0000)
Patch by John Sully!

Fixes PR35164.

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

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

lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
test/CodeGen/WebAssembly/global.ll

index 5f7f3d694cd4cc90cefdf6f3c5ddc7bb3d016d80..3baa2574fd158b02814e0d81582baf23859ddc8c 100644 (file)
@@ -90,11 +90,13 @@ void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
   }
   for (const auto &G : M.globals()) {
     if (!G.hasInitializer() && G.hasExternalLinkage()) {
-      uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
-      if (TM.getTargetTriple().isOSBinFormatELF())
-        getTargetStreamer()->emitGlobalImport(G.getGlobalIdentifier());
-      OutStreamer->emitELFSize(getSymbol(&G),
-                               MCConstantExpr::create(Size, OutContext));
+      if (G.getValueType()->isSized()) {
+        uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
+        if (TM.getTargetTriple().isOSBinFormatELF())
+          getTargetStreamer()->emitGlobalImport(G.getGlobalIdentifier());
+        OutStreamer->emitELFSize(getSymbol(&G),
+                                 MCConstantExpr::create(Size, OutContext));
+      }
     }
   }
 }
index 599eb53b431b89f3a4e3868ea820998d735073fb..bb942bee560b29d97829a47aaa333d7409cc2123 100644 (file)
@@ -213,3 +213,10 @@ define i8* @call_memcpy(i8* %p, i8* nocapture readonly %q, i32 %n) {
 ; CHECK-NEXT: .size       pointer_to_array, 4
 @array = internal constant [8 x i8] zeroinitializer, align 1
 @pointer_to_array = constant i8* getelementptr inbounds ([8 x i8], [8 x i8]* @array, i32 0, i32 4), align 4
+
+; Handle external objects with opaque type.
+%struct.ASTRUCT = type opaque
+@g_struct = external global %struct.ASTRUCT, align 1
+define i32 @address_of_opaque()  {
+  ret i32 ptrtoint (%struct.ASTRUCT* @g_struct to i32)
+}