diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -1750,6 +1750,18 @@ return success(); } +/// Checks if `dbgIntr` is a kill location that holds metadata instead of an SSA +/// value. +static bool isMetadataKillLocation(llvm::DbgVariableIntrinsic *dbgIntr) { + if (!dbgIntr->isKillLocation()) + return false; + llvm::Value *value = dbgIntr->getArgOperand(0); + auto *nodeAsVal = dyn_cast(value); + if (!nodeAsVal) + return false; + return !isa(nodeAsVal->getMetadata()); +} + LogicalResult ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr, DominanceInfo &domInfo) { @@ -1763,9 +1775,15 @@ // TODO: Support debug intrinsics that evaluate a debug expression. if (dbgIntr->hasArgList() || dbgIntr->getExpression()->getNumElements() != 0) return emitUnsupportedWarning(); + // Kill locations can have metadata nodes as location operand. This + // cannot be converted to poison as the type cannot be reconstructed. + // TODO: find a way to support this case. + if (isMetadataKillLocation(dbgIntr)) + return emitUnsupportedWarning(); FailureOr argOperand = convertMetadataValue(dbgIntr->getArgOperand(0)); if (failed(argOperand)) - return failure(); + return emitError(loc) << "failed to convert a debug intrinsic operand: " + << diag(*dbgIntr); // Ensure that the debug instrinsic is inserted right after its operand is // defined. Otherwise, the operand might not necessarily dominate the diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll --- a/mlir/test/Target/LLVMIR/Import/import-failure.ll +++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll @@ -65,9 +65,12 @@ ; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata i64 %arg1, metadata !3, metadata !DIExpression(DW_OP_plus_uconst, 42, DW_OP_stack_value)), !dbg !5 ; CHECK: import-failure.ll ; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5 +; CHECK: import-failure.ll +; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5 define void @dropped_instruction(i64 %arg1) { call void @llvm.dbg.value(metadata i64 %arg1, metadata !3, metadata !DIExpression(DW_OP_plus_uconst, 42, DW_OP_stack_value)), !dbg !5 call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5 + call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5 ret void } @@ -79,6 +82,7 @@ !3 = !DILocalVariable(scope: !4, name: "arg1", file: !2, line: 1, arg: 1, align: 64); !4 = distinct !DISubprogram(name: "intrinsic", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1) !5 = !DILocation(line: 1, column: 2, scope: !4) +!6 = !{} ; // -----