Skip to content

cmd/compile: crash on pointer conversion in call to mapaccess2 #51840

Closed

Description

@julianiewiejska

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

go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

https://go.dev/play/p/_Q4fOpnr5rn

What did you expect to see?

Code compiles and runs without errors.

What did you see instead?

Code produces error:

<autogenerated>:1: cannot use &.autotmp_19 (type *struct { netip.addr netip.uint128; netip.z *intern.Value }) as type *netip.Addr in argument to runtime.mapaccess2

Other remarks

This seems to only happen when maps.Equal is used in the method even if the method is not called. There is no error when it is called directly: https://go.dev/play/p/KlpiWS96MA-

Activity

  1. added this to the Unreleased milestone on Mar 21, 2022
  2. ianlancetaylor commented on Mar 21, 2022

    @ianlancetaylor
    Contributor

    Here is a standalone test case. CC @randall77 @mdempsky

    package main
    
    type Addr struct {
    	hi uint64
    	lo uint64
    	z *byte
    }
    
    func EqualMap[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool {
    	for k, v1 := range m1 {
    		if v2, ok := m2[k]; !ok || v1 != v2 {
    			return false
    		}
    	}
    	return true
    }
    
    type Set[T comparable] map[T]struct{}
    
    func NewSet[T comparable](items ...T) Set[T] {
    	return nil
    }
    
    func (s Set[T]) Equals(other Set[T]) bool {
    	return EqualMap(s, other)
    }
    
    func main() {
    	NewSet[Addr](Addr{0, 0, nil})
    }
    <autogenerated>:1: cannot use &.autotmp_17 (type *struct { hi uint64; lo uint64; z *byte }) as type *Addr in argument to runtime.mapaccess2
    
  3. changed the title [-]x/exp/maps and netip: error when using maps.Equal in a Method on generic map with netip.Addr as keys[/-] [+]cmd/compile: crash on pointer conversion in call to mapaccess2[/+] on Mar 21, 2022
  4. ianlancetaylor commented on Mar 21, 2022

    @ianlancetaylor
    Contributor

    @gopherbot Please open a backport to 1.18

    This is a compiler crash on valid code.

  5. gopherbot commented on Mar 21, 2022

    @gopherbot
    Contributor

    Backport issue(s) opened: #51849 (for 1.18).

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

  6. blackgreen100 commented on Apr 7, 2022

    @blackgreen100

    it seems the crash reproduces also on mapassign, and also when the key's underlying type is some composite type with more than one member:

  7. added a commit that references this issue on Apr 19, 2022
  8. wdvxdr1123 commented on May 7, 2022

    @wdvxdr1123
    Contributor

    I noticed this issue has been fixed in 115c3bf.

  9. mdempsky commented on May 7, 2022

    @mdempsky
    Contributor

    @wdvxdr1123 Thanks, for the heads up. That's unexpected, but a believable effect.

    If anyone wants to contribute a CL adding the failure cases as a regression test, that would be great. (Just add a file $GOROOT/test/fixedbugs/issue51840.go that demonstrates the previously failing code now compiles correctly. Look for other "// compile" or "// run" test cases in the directory, if you need inspiration.)

    Otherwise, I'll prepare one on Monday.

  10. gopherbot commented on May 8, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/404914 mentions this issue: test: add test case for #51840

  11. gopherbot commented on May 10, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/405436 mentions this issue: [release-branch.go1.18] cmd/compile: backport fix for #51840

  12. gopherbot commented on Jul 14, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/417616 mentions this issue: Revert "[release-branch.go1.18] cmd/compile: backport fix for #51840"

  13. locked and limited conversation to collaborators on Jul 14, 2023
  14. added a commit that references this issue on Sep 19, 2024
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

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions