Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: typechecking panic #45804

Closed
rsc opened this issue Apr 27, 2021 · 2 comments
Closed

cmd/compile: typechecking panic #45804

rsc opened this issue Apr 27, 2021 · 2 comments
Labels
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Apr 27, 2021

This program has multiple problems, including that x is undefined:

% cat /tmp/x.go
package p

func g() int
func h(int)

var b bool

func f() {
	did := g()
	if !did && b {
		h(x)
	}
}
% go tool compile /tmp/x.go
/tmp/x.go:10:5: invalid operation: !did (operator ! not defined on int)
% 

Note the lack of error about x. The problem is the compiler is panicking due to the first error (and hiding that panic as it should). We should fix the panic though:

% go tool compile -d=panic /tmp/x.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x5c pc=0x12235a7]

goroutine 1 [running]:
cmd/compile/internal/types.(*Type).IsBoolean(...)
	/Users/rsc/go/src/cmd/compile/internal/types/type.go:1308
cmd/compile/internal/typecheck.typecheck1({0x1a84dd0, 0xc0003fe000}, 0x2)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:602 +0x1be7
cmd/compile/internal/typecheck.typecheck({0x1a84dd0, 0xc0003fe000}, 0x2)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:371 +0x4b0
cmd/compile/internal/typecheck.Expr(...)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:32
cmd/compile/internal/typecheck.tcIf(0xc0003fac40)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/stmt.go:303 +0x4d
cmd/compile/internal/typecheck.typecheck1({0x1a846c8, 0xc0003fac40}, 0x1)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:860 +0x227b
cmd/compile/internal/typecheck.typecheck({0x1a846c8, 0xc0003fac40}, 0x1)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:371 +0x4b0
cmd/compile/internal/typecheck.typecheckslice({0xc000164820, 0x2, 0xc000156288}, 0x11c0da9)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:177 +0x68
cmd/compile/internal/typecheck.Stmts(...)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:36
cmd/compile/internal/typecheck.FuncBody(0xc000170580)
	/Users/rsc/go/src/cmd/compile/internal/typecheck/typecheck.go:59 +0x65
cmd/compile/internal/noder.LoadPackage({0xc00010e1a0, 0x1, 0x0})
	/Users/rsc/go/src/cmd/compile/internal/noder/noder.go:145 +0x8f6
cmd/compile/internal/gc.Main(0x194a5f8)
	/Users/rsc/go/src/cmd/compile/internal/gc/main.go:192 +0xb2e
main.main()
	/Users/rsc/go/src/cmd/compile/main.go:55 +0xdd

Using compiler built fresh just now, from 0b9ca4d.

/cc @findleyr @griesemer

@rsc rsc added the NeedsFix label Apr 27, 2021
@rsc rsc added this to the Go1.17 milestone Apr 27, 2021
@cuonglm
Copy link
Member

@cuonglm cuonglm commented Apr 27, 2021

git bisect point to https://go-review.googlesource.com/c/go/+/279442

I'm sending the fix.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 27, 2021

Change https://golang.org/cl/314209 mentions this issue: cmd/compile: fix typechecking logical operators panic with non-boolean operand

Loading

@gopherbot gopherbot closed this in c9f4350 Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants