elliotchance / c2go

⚖️ A tool for transpiling C to Go.
MIT License
2.09k stars 155 forks source link

IsLiteralLabel not handled by AsmLabelAttr regex #860

Closed kroppt closed 4 years ago

kroppt commented 4 years ago

error:

~/code/c2go $ go test -tags=integration ./...
panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)>(?P<inherited> Inherited)? "(?P<function>.+)"[\s]*$
0x559fea32f5f0 <line:407:94> "__isoc99_fscanf" IsLiteralLabel

goroutine 24 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc00020a840, 0x5e, 0xc00031ff84, 0x3d, 0x24)
        /home/user/code/c2go/ast/ast.go:310 +0x360
github.com/elliotchance/c2go/ast.parseAsmLabelAttr(0xc00031ff84, 0x3d, 0x709816)
        /home/user/code/c2go/ast/asm_label_attr.go:13 +0x62
github.com/elliotchance/c2go/ast.Parse(0xc00031ff77, 0x4a, 0x705475, 0x5)
        /home/user/code/c2go/ast/ast.go:82 +0x1216
github.com/elliotchance/c2go.convertLinesToNodes(0xc0000b4000, 0x6a1, 0x1a86, 0x0, 0x0, 0x0)
        /home/user/code/c2go/main.go:89 +0x1a6
github.com/elliotchance/c2go.convertLinesToNodesParallel.func1.1(0xc00020a000, 0xc0000b0040, 0xc0000b4000, 0x6a1, 0x1a86, 0x0)
        /home/user/code/c2go/main.go:113 +0x53
created by github.com/elliotchance/c2go.convertLinesToNodesParallel.func1

clang:

~ $ clang --version
clang version 10.0.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/10/bin

source file: https://github.com/elliotchance/c2go/blob/b603e1d1c3b21c97eee63fcec2360adf4a2ce001/tests/stdio.c

Some related information was added in clang 10: https://releases.llvm.org/10.0.0/tools/clang/docs/AttributeReference.html#asm The changeset provides more information:

    // IsLiteralLabel specifies whether the label is literal (i.e. suppresses
    // the global C symbol prefix) or not. If not, the mangle-suppression prefix
    // ('\01') is omitted from the decl name at the LLVM IR level.
    //
    // Non-literal labels are used by some external AST sources like LLDB.
...
bool isEquivalent(AsmLabelAttr *Other) const {
  return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
}

https://reviews.llvm.org/D67774