Skip to content

cmd/compile: runtime panic due to bad devirtualization #43292

Closed

Description

@mdempsky

This program should run without crashing, but currently panics at tip:

package main

type I interface { M() chan int }

type A int
func (A) M() chan int { return nil }

type B int
func (B) M() chan int { return nil }

func main() {
	c := I(A(0))

	b := make(chan I, 1)
	b <- B(0)

	for i := 0; i < 2; i++ {
		select {
		case c = <-b:
		case <-c.M():
		default:
		}
	}
}

Based on test case reported by @kivikakk in #42284.

Activity

  1. added this to the Go1.16 milestone on Dec 20, 2020
  2. self-assigned this
    on Dec 20, 2020
  3. mdempsky commented on Dec 20, 2020

    @mdempsky
    ContributorAuthor

    The issue is reassigned doesn't check for OSELRECV/OSELRECV2.

  4. mdempsky commented on Dec 20, 2020

    @mdempsky
    ContributorAuthor

    We weren't checking OAS2RECV either. :(

  5. gopherbot commented on Dec 20, 2020

    @gopherbot
    Contributor

    Change https://golang.org/cl/279352 mentions this issue: cmd/compile: recognize reassignments involving receives

  6. mdempsky commented on Dec 20, 2020

    @mdempsky
    ContributorAuthor

    @kivikakk I believe CL 279352 should fix your issue. Can you try testing that for me please?

    In case you're not familiar with Gerrit, the procedure to fetch and checkout the change locally are:

    git fetch https://go.googlesource.com/go refs/changes/52/279352/1
    git checkout FETCH_HEAD
    

    (Other options are available if you click the "DOWNLOAD" link at golang.org/cl/279352, but they all amount to fetching that commit ref and then using some git command.)

  7. kivikakk commented on Dec 20, 2020

    @kivikakk

    Fetching and compiling now, will report back shortly 👍

  8. kivikakk commented on Dec 20, 2020

    @kivikakk

    Success! The use case I reported in #42284 (comment) no longer panics:

    $ ~/Code/go/bin/go version
    go version devel +00468b24ae Sun Dec 20 01:16:30 2020 -0800 darwin/arm64
    $ ~/Code/go/bin/go run main.go
    2020/12/20 20:41:45 online
  9. mdempsky commented on Dec 20, 2020

    @mdempsky
    ContributorAuthor

    @kivikakk Great, thank you for confirming, and again for the report! I've submitted the fix. Cheers.

  10. locked and limited conversation to collaborators on Dec 20, 2021
  11. added a commit that references this issue on Apr 29, 2024
    89b44b4
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions