From: Dan Gohman Date: Thu, 7 Dec 2017 00:14:30 +0000 (+0000) Subject: [WebAssembly] Don't try to emit size information for unsized types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=113753f1f65a96c18833e19fe61645b144f0bbdd;p=llvm [WebAssembly] Don't try to emit size information for unsized types 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 --- diff --git a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index 5f7f3d694cd..3baa2574fd1 100644 --- a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -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)); + } } } } diff --git a/test/CodeGen/WebAssembly/global.ll b/test/CodeGen/WebAssembly/global.ll index 599eb53b431..bb942bee560 100644 --- a/test/CodeGen/WebAssembly/global.ll +++ b/test/CodeGen/WebAssembly/global.ll @@ -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) +}