Skip to content

cmd/compile: s390x floating point <-> integer conversions clobbering the condition code #39651

@panlinux

Description

@panlinux

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

$ go version
go version go1.14.4 linux/s390x

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Ubuntu Groovy on s390x

go env
$ go env
GO111MODULE=""
GOARCH="s390x"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOENV="/home/ubuntu/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="s390x"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ubuntu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_s390x"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -march=z196 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build209301451=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run example.go on s390x (works elsewhere): https://play.golang.org/p/CGraP0pNaJi

What did you expect to see?

No errors in the output, i.e.:

--- t:
{Easy! {1 [3 4]}}

--- t dump:
a: Easy!
b:
  c: 1
  d: [3, 4]


--- m:
map[a:Easy! b:map[c:1 d:[3 4]]]

--- m dump:
a: Easy!
b:
  c: 1
  d:
  - 3
  - 4

This code comes from the gopkg.in/yaml.v2 example in their README.md except I replaced "c: 1" with "c: 1.0" in the data variable.

What did you see instead?

ubuntu@groovy-s390x:~$ ./example 
2020/06/17 13:14:58 error: yaml: unmarshal errors:
  line 4: cannot unmarshal !!float `1.0` into int

Initially I thought it was a bug in gopkg.in/yaml.v2, and filed an issue there, but I suspect something in go itself now, because either of these silly changes make the code work:

  1. Just printf in https://github.com/go-yaml/yaml/blob/v2/decode.go#L502, for debugging purposes, made it work:
--- a/decode.go
+++ b/decode.go
@@ -500,6 +500,7 @@ func (d *decoder) scalar(n *node, out reflect.Value) bool {
                                return true
                        }
                case float64:
+                       fmt.Printf("DEBUG: int64(resolved) = %d\n", int64(resolved))
                        if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) {
                                out.SetInt(int64(resolved))
                                return true

Output:

ubuntu@groovy-s390x:~$ ./example 
DEBUG: int64(resolved) = 1
--- t:
{Easy! {1 [3 4]}}

--- t dump:
a: Easy!
b:
  c: 1
  d: [3, 4]


--- m:
map[a:Easy! b:map[c:1 d:[3 4]]]

--- m dump:
a: Easy!
b:
  c: 1
  d:
  - 3
  - 4
  1. Or this change:
--- a/decode.go
+++ b/decode.go
@@ -500,7 +500,8 @@ func (d *decoder) scalar(n *node, out reflect.Value) bool {
                                return true
                        }
                case float64:
-                       if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) {
+                       is_overflow := out.OverflowInt(int64(resolved))
+                       if resolved <= math.MaxInt64 && !is_overflow {
                                out.SetInt(int64(resolved))
                                return true
                        }

Also makes it work and produces the correct output:

ubuntu@groovy-s390x:~$ rm example
ubuntu@groovy-s390x:~$ go build example.go
ubuntu@groovy-s390x:~$ ./example 
--- t:
{Easy! {1 [3 4]}}

--- t dump:
a: Easy!
b:
  c: 1
  d: [3, 4]


--- m:
map[a:Easy! b:map[c:1 d:[3 4]]]

--- m dump:
a: Easy!
b:
  c: 1
  d:
  - 3
  - 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.arch-s390xIssues solely affecting the s390x architecture.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions