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: assertion failed (on 1.18 and tip) #53390

Closed
ALTree opened this issue Jun 15, 2022 · 4 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ALTree
Copy link
Member

ALTree commented Jun 15, 2022

This program:

package main

import (
	"reflect"
	"unsafe"
)

func F[T any](v T) uintptr {
	return unsafe.Alignof(func() T {
		_ = reflect.DeepEqual(struct{ _ T }{}, nil)
		return v
	}())
}

func main() {
	F(0)
}

crashes both the 1.18.3 and the tip compiler with this error:

$ go build crash.go

# command-line-arguments
.\crash.go:16:3: internal compiler error: assertion failed

cc @mdempsky @randall77

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 15, 2022
@ALTree ALTree added this to the Go1.19 milestone Jun 15, 2022
@mdempsky
Copy link
Contributor

Thanks for the report! 'm guessing the problem is Go 1.18 frontend is being inconsistent in when/whether it visits the argument to unsafe.Alignof, since it isn't actually needed.

I think the obvious workaround is to just write unsafe.Alignof(*new(T)) instead of unsafe.Alignof(func() T { ... }()).

The code is also already working for Unified IR, and I'll add it as a test case to make sure it stays working.

I think it's probably an easy fix for non-unified mode, if anyone wants to investigate that (@cuonglm ?). But I don't think it's terribly important, and probably not worth backporting any fixes for, unless we can reproduce the issue with more realistic code.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/412534 mentions this issue: [dev.unified] test: add regress test for #53390

@cuonglm
Copy link
Member

cuonglm commented Jun 16, 2022

@mdempsky I looked into this yesterday, but haven't had time to send CL yet, since when I'm not sure whether we should fix this for 1.19 on master, or fix for 1.20 in dev.unified branch.

You're right that the Go 1.18 frontend is not consistent, in process of generate instantiation for generic function, when doing substitution for unsafe.Alignof, it's transformed unsafe.Alignof to a OLITERAL node, but then still visit old unsafe.Alignof's children nodes.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/412794 mentions this issue: cmd/compile: skip substituting closures in unsafe builtins arguments

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Done
Development

No branches or pull requests

4 participants