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: bad compilation with inlined math functions #23522

Closed
ianlancetaylor opened this issue Jan 23, 2018 · 2 comments
Closed

cmd/compile: bad compilation with inlined math functions #23522

ianlancetaylor opened this issue Jan 23, 2018 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

This test case is miscompiled with devel +9745eed4fd Fri Jan 12 05:25:55 2018. The programs panics when it should not. This passes with Go 1.9 and gccgo.

CC @randall77

package main

import (
	"math"
)

type S struct {
	u int64
	n int32
}

func F1(f float64) *S {
	s := f
	pf := math.Copysign(f, 1)
	u := math.Floor(pf)
	return &S{
		u: int64(math.Copysign(u, s)),
		n: int32(math.Copysign((pf-u)*1e9, s)),
	}
}

func F2(f float64) *S {
	s := f
	f = math.Copysign(f, 1)
	u := math.Floor(f)
	return &S{
		u: int64(math.Copysign(u, s)),
		n: int32(math.Copysign((f-u)*1e9, s)),
	}
}

func main() {
	s1 := F1(-1)
	s2 := F2(-1)
	if *s1 != *s2 {
		println("F1:", s1.u, s1.n)
		println("F2:", s2.u, s2.n)
		panic("different")
	}
}
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jan 23, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Jan 23, 2018
@randall77
Copy link
Contributor

This boils down to a missing interference edge between two views of the same argument.
There's f, the float64 argument, and f, the uint64 argument generated by inlining math.Copysign and from there, math.Float64bits.
This causes the compiler to spill to one of those fs, clobbering the other one that was still live.

@randall77 randall77 self-assigned this Jan 23, 2018
@gopherbot
Copy link

Change https://golang.org/cl/89335 mentions this issue: cmd/compile: don't let spills clobber arguments

@golang golang locked and limited conversation to collaborators Jan 23, 2019
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. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants