Skip to content

cmd/compile: function argument hiding built-in function results in a compiler crash #27356

Closed
@taylorza

Description

@taylorza

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Tested with GO 1.11

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Compiling on Windows, reproduced targeting both Windows and Linux

What did you do?

NOTE: This does not reproduce on play.golang.org, but I have reproduced it on 3 different machines

If a function argument hides a built-in function and there is an attempt to call the built-in function the compiler will crash with no indication of where it was in the compilation process, which makes it hard to find in a large codebase.

Here is a simple repo of the issue
package main

var a = []byte{1,2,3}

func bug(len int) bool {
    return len < len(a)
}

func main() { 
    println(bug(5))
}

Here the argument len hides the built-in function len, and in that same function a call is made to the function len.

What did you expect to see?

Compiler Error : cannot call non-function len (type int)

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x70 pc=0xb94675]
goroutine 1 [running]:
cmd/compile/internal/gc.typecheck1(0xc000352580, 0x2, 0xc00033fa40)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:1270 +0x3ed5
cmd/compile/internal/gc.typecheck(0xc000352580, 0x2, 0xc00033fa40)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheck1(0xc000352600, 0x12, 0xc000084998)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:585 +0x2cce
cmd/compile/internal/gc.typecheck(0xc000352600, 0x12, 0xc0000849d8)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheckslice(0xc0000885d0, 0x1, 0x1, 0x12)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:68 +0x57
cmd/compile/internal/gc.typecheck1(0xc000352680, 0x1, 0xcbf373)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:2065 +0xadd4
cmd/compile/internal/gc.typecheck(0xc000352680, 0x1, 0x3)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheckslice(0xc0000885d8, 0x1, 0x1, 0x1)
        c:/go/src/cmd/compile/internal/gc/typecheck.go:68 +0x57
cmd/compile/internal/gc.Main(0xcdea30)
        c:/go/src/cmd/compile/internal/gc/main.go:518 +0x20d0
main.main()
        c:/go/src/cmd/compile/main.go:51 +0x9d

Activity

cherrymui

cherrymui commented on Aug 30, 2018

@cherrymui
Member

It reports the error correctly with Go 1.10. Looks like a regression.

added this to the Go1.11.1 milestone on Aug 30, 2018
changed the title [-]Compiler Bug: function argument hiding built-in function results in a compiler crash[/-] [+]cmd/compile: function argument hiding built-in function results in a compiler crash[/+] on Aug 30, 2018
cherrymui

cherrymui commented on Aug 30, 2018

@cherrymui
Member
self-assigned this
on Aug 30, 2018
modified the milestones: Go1.11.1, Go1.12 on Aug 30, 2018
added
NeedsFixThe path to resolution is known, but the work has not been done.
on Aug 30, 2018
FiloSottile

FiloSottile commented on Aug 30, 2018

@FiloSottile
Contributor

@gopherbot please file this to be considered for backport to 1.11. This is a regression.

gopherbot

gopherbot commented on Aug 30, 2018

@gopherbot
Contributor

Backport issue(s) opened: #27399 (for 1.11).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

gopherbot

gopherbot commented on Sep 2, 2018

@gopherbot
Contributor

Change https://golang.org/cl/132876 mentions this issue: cmd/compile/internal/gc/typecheck : Added check to ensure that Node.Name.Defn is not nil before dereferencing. If it is nil we revert to the pre-1.11 error reporting.

gopherbot

gopherbot commented on Oct 3, 2018

@gopherbot
Contributor

Change https://golang.org/cl/139103 mentions this issue: [release-branch.go1.11] cmd/compile: don't crash reporting misuse of shadowed built-in function

added a commit that references this issue on Nov 30, 2018
locked and limited conversation to collaborators on Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @FiloSottile@griesemer@gopherbot@taylorza@cherrymui

        Issue actions

          cmd/compile: function argument hiding built-in function results in a compiler crash · Issue #27356 · golang/go