Skip to content

[MLIR][LLVM] Recursive debug type not imported properly if input is bytecode #150163

@Kuree

Description

@Kuree

How to reproduce:

bug.c:

int main() {
    int a = 0;
    return a;
}
$ clang -O1 -g bug.c -S -emit-llvm -o - | mlir-translate --import-llvm --mlir-print-debuginfo | mlir-opt --emit-bytecode | mlir-translate --mlir-to-llvmir
mismatched subprogram between #dbg record variable and DILocation
#dbg_value(i32 0, !17, !DIExpression(), !20)
label %0
ptr @main
!17 = !DILocalVariable(name: "a", scope: !18, file: !1, line: 2, type: !14)
!18 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)
!20 = !DILocation(line: 0, scope: !11)
!11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
label %0
ptr @main

Either replacing --emit-bytecode with --mlir-emit-debuginfo or skipping mlir-opt works:

// works
clang -O1 -g bug.c -S -emit-llvm -o - | mlir-translate --import-llvm --mlir-print-debuginfo | mlir-opt --mlir-print-debuginfo | mlir-translate --mlir-to-llvmir
// works
clang -O1 -g bug.c -S -emit-llvm -o - | mlir-translate --import-llvm --mlir-print-debuginfo  | mlir-translate --mlir-to-llvmir

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions