diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -196,14 +196,16 @@ Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(Type), Mutable}); } + emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration()); + // If the GlobalVariable refers to a table, we handle it here instead of // in emitExternalDecls if (Sym->isTable()) { + OutStreamer->emitLabel(Sym); getTargetStreamer()->emitTableType(Sym); return; } - - emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration()); + if (GV->hasInitializer()) { assert(getSymbolPreferLocal(*GV) == Sym); emitLinkage(GV, Sym); diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll --- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll +++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll @@ -73,4 +73,5 @@ ret %externref %ref } -; CHECK: .tabletype externref_table, externref +; CHECK-LABEL: externref_table: +; CHECK-NEXT: .tabletype externref_table, externref diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll --- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll +++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll @@ -94,4 +94,5 @@ ret void } -; CHECK: .tabletype externref_table, externref +; CHECK-LABEL: externref_table: +; CHECK-NEXT: .tabletype externref_table, externref diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll --- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll +++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll @@ -5,16 +5,9 @@ @funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef -define void @call_funcref_from_table(i32 %i) { - %p = getelementptr [0 x %funcref], [0 x %funcref] addrspace (1)* @funcref_table, i32 0, i32 %i - %ref = load %funcref, %funcref addrspace(1)* %p - %fn = bitcast %funcref %ref to %funcptr - call addrspace(20) void %fn() - ret void -} - -; CHECK: .tabletype __funcref_call_table, funcref, 1 +; CHECK: .tabletype __funcref_call_table, funcref, 1 +define void @call_funcref_from_table(i32 %i) { ; CHECK-LABEL: call_funcref_from_table: ; CHECK-NEXT: .functype call_funcref_from_table (i32) -> () ; CHECK-NEXT: i32.const 0 @@ -27,6 +20,13 @@ ; CHECK-NEXT: ref.null_func ; CHECK-NEXT: table.set __funcref_call_table ; CHECK-NEXT: end_function + %p = getelementptr [0 x %funcref], [0 x %funcref] addrspace (1)* @funcref_table, i32 0, i32 %i + %ref = load %funcref, %funcref addrspace(1)* %p + %fn = bitcast %funcref %ref to %funcptr + call addrspace(20) void %fn() + ret void +} -; CHECK: .tabletype funcref_table, funcref +; CHECK-LABEL: funcref_table: +; CHECK-NEXT: .tabletype funcref_table, funcref diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll --- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll +++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll @@ -72,4 +72,5 @@ ret %funcref %ref } -; CHECK: .tabletype funcref_table, funcref +; CHECK-LABEL: funcref_table: +; CHECK-NEXT: .tabletype funcref_table, funcref diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll --- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll +++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll @@ -78,4 +78,5 @@ ret void } -; CHECK: .tabletype funcref_table, funcref +; CHECK-LABEL: funcref_table: +; CHECK-NEXT: .tabletype funcref_table, funcref