Index: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -302,7 +302,12 @@ // not be found here. MachineModuleInfoWasm &MMIW = MMI->getObjFileInfo(); for (const auto &Name : MMIW.MachineSymbolsUsed) { - getOrCreateWasmSymbol(Name.getKey()); + auto *WasmSym = cast(getOrCreateWasmSymbol(Name.getKey())); + if (WasmSym->isFunction()) { + // TODO(wvo): is there any case where this overlaps with the call to + // emitFunctionType in the loop below? + getTargetStreamer()->emitFunctionType(WasmSym); + } } for (auto &It : OutContext.getSymbols()) { Index: llvm/test/MC/WebAssembly/extern-functype-intrinsic.ll =================================================================== --- /dev/null +++ llvm/test/MC/WebAssembly/extern-functype-intrinsic.ll @@ -0,0 +1,92 @@ +; RUN: llc %s -o - | FileCheck %s + +; ModuleID = 'test.c' +source_filename = "test.c" +target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" +target triple = "wasm32-unknown-wasi" + +; Function Attrs: nounwind +define hidden i32 @d() local_unnamed_addr #0 { +entry: + %call = call i32 bitcast (i32 (...)* @g to i32 ()*)() #3 + %cmp6 = icmp sgt i32 %call, 0 + br i1 %cmp6, label %for.body.preheader, label %for.end + +for.body.preheader: ; preds = %entry + %0 = shl nuw i32 %call, 2 + call void @llvm.memset.p0i8.i32(i8* nonnull align 4 inttoptr (i32 4 to i8*), i8 0, i32 %0, i1 false), !tbaa !2 + br label %for.end + +for.end: ; preds = %for.body.preheader, %entry + ret i32 undef +} + +declare i32 @g(...) local_unnamed_addr #1 + +; Function Attrs: argmemonly nofree nounwind willreturn writeonly +declare void @llvm.memset.p0i8.i32(i8* nocapture writeonly, i8, i32, i1 immarg) #2 + +attributes #0 = { nounwind "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" } +attributes #1 = { "frame-pointer"="none" "no-prototype" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" } +attributes #2 = { argmemonly nofree nounwind willreturn writeonly } +attributes #3 = { nounwind } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git d657c6893f9b987f23ddbb1eddf62cc3add77e28)"} +!2 = !{!3, !3, i64 0} +!3 = !{!"int", !4, i64 0} +!4 = !{!"omnipotent char", !5, i64 0} +!5 = !{!"Simple C/C++ TBAA"} + + + +; CHECK: .text +; CHECK-NEXT: .file "test.c" +; CHECK-NEXT: .functype memset (i32, i32, i32) -> (i32) +; CHECK-NEXT: .functype g () -> (i32) +; CHECK-NEXT: .section .text.d,"",@ +; CHECK-NEXT: .hidden d # -- Begin function d +; CHECK-NEXT: .globl d +; CHECK-NEXT: .type d,@function +; CHECK-NEXT: d: # @d +; CHECK-NEXT: .functype d () -> (i32) +; CHECK-NEXT: .local i32 +; CHECK-NEXT: # %bb.0: # %entry +; CHECK-NEXT: block +; CHECK-NEXT: call g +; CHECK-NEXT: local.tee 0 +; CHECK-NEXT: i32.const 1 +; CHECK-NEXT: i32.lt_s +; CHECK-NEXT: br_if 0 # 0: down to label0 +; CHECK-NEXT: # %bb.1: # %for.body.preheader +; CHECK-NEXT: i32.const 4 +; CHECK-NEXT: i32.const 0 +; CHECK-NEXT: local.get 0 +; CHECK-NEXT: i32.const 2 +; CHECK-NEXT: i32.shl +; CHECK-NEXT: call memset +; CHECK-NEXT: drop +; CHECK-NEXT: .LBB0_2: # %for.end +; CHECK-NEXT: end_block # label0: +; CHECK-NEXT: local.get 0 +; CHECK-NEXT: # fallthrough-return +; CHECK-NEXT: end_function +; CHECK-NEXT: .Lfunc_end0: +; CHECK-NEXT: .size d, .Lfunc_end0-d +; CHECK-NEXT: # -- End function +; CHECK-NEXT: .ident "clang version 15.0.0 (https://github.com/llvm/llvm-project.git d657c6893f9b987f23ddbb1eddf62cc3add77e28)" +; CHECK-NEXT: .no_dead_strip __indirect_function_table +; CHECK-NEXT: .section .custom_section.producers,"",@ +; CHECK-NEXT: .int8 1 +; CHECK-NEXT: .int8 12 +; CHECK-NEXT: .ascii "processed-by" +; CHECK-NEXT: .int8 1 +; CHECK-NEXT: .int8 5 +; CHECK-NEXT: .ascii "clang" +; CHECK-NEXT: .int8 90 +; CHECK-NEXT: .ascii "15.0.0 (https://github.com/llvm/llvm-project.git d657c6893f9b987f23ddbb1eddf62cc3add77e28)" +; CHECK-NEXT: .section .text.d,"",@ +