Skip to content

gofmt -r crashes with specific rewrite rules #1384

Closed
@gopherbot

Description

@gopherbot

by imgx64:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
Run any of the following:
echo 'package main' | gofmt -r 'x->foo'
echo -e 'package main\nvar x int' | gofmt -r 'x->foo'
echo -e 'package main\nvar xx int' | gofmt -r 'xx->foo'
echo -e 'package main\nvar xx int = yy+zz' | gofmt -r 'a+b->a*b'

What is the expected output?
Input is correctly formatted and the rewrite rule applied.

What do you see instead?
panic: runtime error: invalid memory address or nil pointer dereference

panic PC=0x7fd6407bcba8
runtime.panic+0xa7 /opt/go/src/pkg/runtime/proc.c:1032
    runtime.panic(0x498e5c, 0x7fd6407ff2a0)
runtime.panicstring+0x69 /opt/go/src/pkg/runtime/runtime.c:83
    runtime.panicstring(0x5ab8bf, 0x4c6da8)
runtime.sigpanic+0x144 /opt/go/src/pkg/runtime/linux/thread.c:286
    runtime.sigpanic()
go/ast.*CommentGroup·Pos+0x1c /opt/go/src/pkg/go/ast/ast.go:85
    go/ast.*CommentGroup·Pos(0x0, 0x49c114, 0x0, 0x7fd6407b8b10)
main._func_003+0x1bf /opt/go/src/cmd/gofmt/rewrite.go:61
    main._func_003(0x7fd6407b7268, 0x7fd6407b7280, 0x7fd6407ff280, 0x7fd6407ff290, 0x402388, ...)
main.apply+0x24d /opt/go/src/cmd/gofmt/rewrite.go:94
    main.apply(0x7fd6407cb9b0, 0x7fd6407e8480, 0x7fd6407dc720, 0x7fd6407dc720, 0x7fd6407ff280, ...)
main.rewriteFile+0x1bc /opt/go/src/cmd/gofmt/rewrite.go:65
    main.rewriteFile(0x7fd6407d0700, 0x7fd6407dc7e0, 0x7fd6407d0700, 0x7fd6407dc7c0, 0x7fd6407d0b80, ...)
main._func_002+0x41 /opt/go/src/cmd/gofmt/rewrite.go:31
    main._func_002(0x7fd6407ff3f0, 0x7fd6407ff370, 0x40106e, 0x7fd6407d0b80, 0x4767dc, ...)
main.processFile+0x1ec /opt/go/src/cmd/gofmt/gofmt.go:109
    main.processFile(0x7fd6407b83c0, 0x500000000, 0x7fd6407e1540, 0x40852e)
main.main+0x159 /opt/go/src/cmd/gofmt/gofmt.go:202
    main.main()
runtime.mainstart+0xf /opt/go/src/pkg/runtime/amd64/asm.s:77
    runtime.mainstart()
runtime.goexit /opt/go/src/pkg/runtime/proc.c:148
    runtime.goexit()


Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Linux, Ubuntu 10.04

Which revision are you using?  (hg identify)
e86b22981073 tip

Please provide any additional information below.
I can't find a pattern to crashes. They might be more than one bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions