Skip to content

bug: Incorrect parent and firstChild set for leftmost and rightmost nonterminals of zero length #23

@mewmew

Description

@mewmew

Creating a dedicated issue to track the bug identified at #17 (comment)

Edit: For added context, the only hand-written files are parser.go and tree.go, both of which are mostly identical copies of the original parser.go and tree.go of the TextMapper project. Which is why this bug is interesting to fix as it pertains to TextMapper itself.

I'll add my latest debug session below, feel free to skim as it's quite long :)

The debug session below is debugging the none command, which uses the mini.tm grammar, and is invoked on the example.ll input file.

Specifically the following commands may be used to reproduce the debug session:

$ go get -u github.com/mewspring/foo/none/cmd/none
$ go get -u github.com/derekparker/delve/cmd/dlv
$ go get -u github.com/aarzilli/gdlv
$ cd $GOPATH/src/github.com/mewspring/foo/none/cmd/none
$ $GOPATH/bin/gdlv debug ../../example.ll

Cheers,
Robin

Debug session

Is it correct that next should be overwritten here?
Then we will skip /* empty */ nonterminals that are in between other nonterminals.

2018-10-27-010734_1920x1175_scrot

Should it really be o >= endoffset? And not o > endoffset? Now, we decrease the end, so that InstMetadata will not be part of the call instruction.

2018-10-27-011328_1920x1175_scrot

OperandBundles and InstMetadata were not assigned to have CallInst as parent. They should have been. Note, end was too small. Most likely as a cause of using if o >= offset { end-- } instead of if o > offset { end-- }

2018-10-27-011841_1920x1175_scrot

This is probably wrong, as now OperandBundles and InstMetadata won't have CallInst as parent.

2018-10-27-013545_1920x1175_scrot

This is where it goes wrong. Really wrong. As the OperandBundles and InstMetadata of the previous CallInst are added to the current CallInst.

The only reason this happens is since OperandBundles and InstMetadata are zero in length, thus offset if not enough to distinguish which parent nonterminal they belong to.

2018-10-27-013740_1920x1175_scrot

This is the incorrect firstChild. It points to InstMetadata, but should really point to

2018-10-27-013942_1920x1175_scrot

Incorrect parents have now been set for InstMetadata and OperandBundles.

2018-10-27-014217_1920x1175_scrot

No parent was set for OperandBundles and InstMetadata. They should have both been assigned the last CallInst as parent (i.e. index 18).

2018-10-27-014315_1920x1175_scrot

Since InstMetadata (at index 10) is now the firstChild of the CallInst at index 18, and since the InstMetadata does not have a next (i.e. next is 0), the CallInst will not have any other children than the incorrectly added InstMetadata child. Therefore, calling Typ on CallInst will result in NONE type.

2018-10-27-014532_1920x1175_scrot

InstMetadata (at index 17) of previous instruction being added to have RetTerm as parent. The correct InstMetadata to add to RetTerm is at index 20.

2018-10-27-014915_1920x1175_scrot

FuncMetadata incorrectly added to have FuncBody as parent.

2018-10-27-015614_1920x1175_scrot

InstMetadata incorrectly added to have FuncBody as parent (should have been part of TermRet).

2018-10-27-015730_1920x1175_scrot

Panic with unknown node type NONE, since CallInst has InstMetadata as first child.

2018-10-27-020137_1920x1175_scrot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions