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: internal compiler error: untyped type mismatch, have: untyped float, want: untyped int #41680

Closed
ianlancetaylor opened this issue Sep 28, 2020 · 7 comments

Comments

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 28, 2020

On current tip (874b313, CL 247477) this valid code gets an incorrect compilation error.

I believe this is due to CL 255217. CC @cuonglm @mdempsky

package p

func F(s string) bool {
	const m = 16
	const n = 1e5
	_ = make([]int, n)
	return len(s) < n*m
}
@ianlancetaylor
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Sep 28, 2020

Sorry, I forgot to include the compilation error.

foo.go:7:19: internal compiler error: untyped type mismatch, have: untyped float, want: untyped int

goroutine 1 [running]:
runtime/debug.Stack(0xd6b500, 0xc0000ba008, 0x0)
	/home/iant/go/src/runtime/debug/stack.go:24 +0x9f
cmd/compile/internal/gc.Fatalf(0xc73811, 0x29, 0xc0000cc620, 0x2, 0x2)
	/home/iant/go/src/cmd/compile/internal/gc/subr.go:199 +0x1b0
cmd/compile/internal/gc.setconst(0xc0003b6000, 0xc3bec0, 0xc0000a1ad0)
	/home/iant/go/src/cmd/compile/internal/gc/const.go:981 +0x35c
cmd/compile/internal/gc.evconst(0xc0003b6000)
	/home/iant/go/src/cmd/compile/internal/gc/const.go:581 +0x785
cmd/compile/internal/gc.typecheck1(0xc0003b6000, 0x2, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2099 +0x2c5
cmd/compile/internal/gc.typecheck(0xc0003b6000, 0x2, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
cmd/compile/internal/gc.typecheck1(0xc0003b6080, 0x12, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:593 +0x2c1c
cmd/compile/internal/gc.typecheck(0xc0003b6080, 0x12, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
cmd/compile/internal/gc.typecheckslice(0xc0000ba448, 0x1, 0x1, 0x12)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:118 +0x51
cmd/compile/internal/gc.typecheckargs(0xc0003b6100)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2140 +0x96
cmd/compile/internal/gc.typecheck1(0xc0003b6100, 0x1, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2036 +0xa94e
cmd/compile/internal/gc.typecheck(0xc0003b6100, 0x1, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
cmd/compile/internal/gc.typecheckslice(0xc0003a1a80, 0x4, 0x4, 0x1)
	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:118 +0x51
cmd/compile/internal/gc.Main(0xc81008)
	/home/iant/go/src/cmd/compile/internal/gc/main.go:624 +0x2cb0
main.main()
	/home/iant/go/src/cmd/compile/main.go:52 +0xb1

Loading

@mdempsky mdempsky self-assigned this Sep 28, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 28, 2020

Thanks. Looks like this is related to a pre-existing type-checking bug related to make. For example, this program is valid and type checks with gccgo and go/types, but not with Go 1.15:

package main

func main() {
	const n = 1e5
	_ = make([]int, n)
	f := n
	var _ float64 = f
}

Edit: Go 1.15's error message is:

x.go:7:6: cannot use f (type int) as type float64 in assignment

(Positively, it successfully compiles at tip, likely thanks to CL 255217.)

Loading

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 28, 2020

@mdempsky Is it normal that const n = 1e5 is untyped float, but the n.Val().Ctype() is CTINT?

Loading

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 28, 2020

@cuonglm No, that's the issue. If a Node has type Idealfloat, then it should have value CTFLT.

Loading

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 28, 2020

@cuonglm No, that's the issue. If a Node has type Idealfloat, then it should have value CTFLT.

So I think that's the bug here. I can't find where we currently set that information. This bug does exists before CL 255217, it just works because we assign the value to n instead of doing assertion.

Loading

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 28, 2020

@cuonglm That's my assessment too. I have a fix. Will upload shortly.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 28, 2020

Change https://golang.org/cl/257966 mentions this issue: cmd/compile: fix type checking of "make" arguments

Loading

@gopherbot gopherbot closed this in ad0ab81 Sep 28, 2020
@golang golang locked and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants