Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -664,11 +664,15 @@ } void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) { - assert(LocationKind == Implicit || LocationKind == Unknown); - LocationKind = Implicit; emitOp(dwarf::DW_OP_WASM_location); emitUnsigned(Index == 4/*TI_LOCAL_INDIRECT*/ ? 0/*TI_LOCAL*/ : Index); emitUnsigned(Offset); - if (Index == 4/*TI_LOCAL_INDIRECT*/) + if (Index == 4 /*TI_LOCAL_INDIRECT*/) { emitOp(dwarf::DW_OP_deref); + assert(LocationKind == Unknown); + LocationKind = Memory; + } else { + assert(LocationKind == Implicit || LocationKind == Unknown); + LocationKind = Implicit; + } } Index: llvm/lib/MC/MCParser/WasmAsmParser.cpp =================================================================== --- llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -221,18 +221,22 @@ Lexer->is(AsmToken::Identifier))) return error("Expected label,@type declaration, got: ", Lexer->getTok()); auto TypeName = Lexer->getTok().getString(); + auto *Current = + cast(getStreamer().getCurrentSection().first); if (TypeName == "function") { WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); - auto *Current = - cast(getStreamer().getCurrentSection().first); if (Current->getGroup()) WasmSym->setComdat(true); - } else if (TypeName == "global") + } else if (TypeName == "global") { WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); - else if (TypeName == "object") + } else if (TypeName == "object") { + if (Current->getKind().isText()) + return error("WASM doesn\'t support data symbols in text sections: ", + Lexer->getTok()); WasmSym->setType(wasm::WASM_SYMBOL_TYPE_DATA); - else + } else { return error("Unknown WASM symbol type: ", Lexer->getTok()); + } Lex(); return expect(AsmToken::EndOfStatement, "EOL"); } Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -488,10 +488,14 @@ const MCSymbol *SectionSymbol = nullptr; const MCSection &SecA = SymA->getSection(); - if (SecA.getKind().isText()) - SectionSymbol = SectionFunctions.find(&SecA)->second; - else + if (SecA.getKind().isText()) { + auto &SecSymIt = SectionFunctions.find(&SecA); + if (SecSymIt == SectionFunctions.end()) + report_fatal_error("section doesn\'t have defining symbol"); + SectionSymbol = SecSymIt->second; + } else { SectionSymbol = SecA.getBeginSymbol(); + } if (!SectionSymbol) report_fatal_error("section symbol is required for relocation"); Index: llvm/test/MC/WebAssembly/debug-byval-struct.ll =================================================================== --- llvm/test/MC/WebAssembly/debug-byval-struct.ll +++ llvm/test/MC/WebAssembly/debug-byval-struct.ll @@ -103,11 +103,11 @@ ; CHECK-NEXT: DW_AT_name ("x") ; CHECK-LABEL: DW_TAG_formal_parameter -; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1, DW_OP_deref, DW_OP_stack_value) +; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1, DW_OP_deref) ; CHECK-NEXT: DW_AT_name ("some_union") ; CHECK-LABEL: DW_TAG_formal_parameter -; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2, DW_OP_deref, DW_OP_stack_value) +; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2, DW_OP_deref) ; CHECK-NEXT: DW_AT_name ("some_struct") ; CHECK-LABEL: DW_TAG_formal_parameter