diff --git a/lld/test/wasm/import-module-empty.ll b/lld/test/wasm/import-module-empty.ll new file mode 100644 --- /dev/null +++ b/lld/test/wasm/import-module-empty.ll @@ -0,0 +1,21 @@ +; RUN: llc -filetype=obj %s -o %t.o +; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s + +target triple = "wasm32-unknown-unknown-wasm" + +define void @_start() { + call void @foo(); + ret void +} + +declare void @foo() #0 + +attributes #0 = { "wasm-import-module"="" } + +; CHECK: - Type: IMPORT +; CHECK-NEXT: Imports: +; CHECK-NEXT: - Module: '' +; CHECK-NEXT: Field: foo +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: SigIndex: 0 diff --git a/lld/test/wasm/import-name-empty.ll b/lld/test/wasm/import-name-empty.ll new file mode 100644 --- /dev/null +++ b/lld/test/wasm/import-name-empty.ll @@ -0,0 +1,27 @@ +; RUN: llc -filetype=obj %s -o %t.o +; RUN: wasm-ld -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s + +target triple = "wasm32-unknown-unknown" + +declare void @f0() #0 + +define void @_start() { + call void @f0() + ret void +} + +attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="" } + +; CHECK: - Type: IMPORT +; CHECK-NEXT: Imports: +; CHECK-NEXT: - Module: somewhere +; CHECK-NEXT: Field: '' +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: SigIndex: 0 + +; CHECK: - Type: CUSTOM +; CHECK-NEXT: Name: name +; CHECK-NEXT: FunctionNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name: f0 diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -640,9 +640,7 @@ Info.Name = Import.Field; } Signature = &Signatures[Import.SigIndex]; - if (!Import.Module.empty()) { - Info.ImportModule = Import.Module; - } + Info.ImportModule = Import.Module; } break; @@ -672,9 +670,7 @@ Info.Name = Import.Field; } GlobalType = &Import.Global; - if (!Import.Module.empty()) { - Info.ImportModule = Import.Module; - } + Info.ImportModule = Import.Module; } break; @@ -704,9 +700,7 @@ Info.Name = Import.Field; } TableType = &Import.Table; - if (!Import.Module.empty()) { - Info.ImportModule = Import.Module; - } + Info.ImportModule = Import.Module; } break; @@ -769,9 +763,7 @@ Info.Name = Import.Field; } Signature = &Signatures[Import.SigIndex]; - if (!Import.Module.empty()) { - Info.ImportModule = Import.Module; - } + Info.ImportModule = Import.Module; } break; }