Navigation Menu

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

gccgo: struct comparison with blank field could be wrong #55142

Open
melonedo opened this issue Sep 19, 2022 · 1 comment
Open

gccgo: struct comparison with blank field could be wrong #55142

melonedo opened this issue Sep 19, 2022 · 1 comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@melonedo
Copy link

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

$ go version
go version go1.18.2 linux/amd64

Does this issue reproduce with the latest release?

Yes, tested on GCC 12.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/melonedo/.cache/go-build"
GOENV="/home/melonedo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/melonedo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/melonedo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/melonedo/fuzzTest/go.mod"
GOWORK=""
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 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build557955963=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go run -compiler gccgo issue.go on code:

// MWE from signature fuzzer
package main

import "fmt"

type StructF11S1 struct {
        _ int16
        F1 int16
}

//go:noinline
func compare(a *StructF11S1, b *StructF11S1) bool {
        return *a == *b
}

func main() {
        a := StructF11S1{1, 2}
        fmt.Println(compare(&a, &a))
}

What did you expect to see?

true should be printed.

What did you see instead?

false is printed.

Run gccgo -issue.go -fgo-dump-ast, we can find that *a and *b are not referenced at all:

.main.compare(.main.a (g._2main_0StructF11S1),.main.b (g._2main_0StructF11S1)) (.main.$ret0 (bool)) : (g.func_8_2main_0StructF11S1_3_2main_0StructF11S1_9_8bool_9)
{
  tmp.66002704 (main.StructF11S1) // struct-equal2.go:12
  tmp.66089344 (main.StructF11S1) // struct-equal2.go:12
  {
    {
      tmp.66109760 (bool) = true // struct-equal2.go:12
      if tmp.66109760 // struct-equal2.go:12
      {
        tmp.66109760 = (tmp.66002704.1 == tmp.66089344.1)  // struct-equal2.go:12
      }
    }
    tmp.65273920 = tmp.66109760 // struct-equal2.go:12
    $ret0 = tmp.65273920 // struct-equal2.go:12
    return  // struct-equal2.go:12
  }
}

A fix has been proposed at https://go-review.googlesource.com/c/gofrontend/+/431736.

@gopherbot gopherbot added this to the Gccgo milestone Sep 19, 2022
@cherrymui cherrymui added NeedsFix The path to resolution is known, but the work has not been done. help wanted and removed help wanted labels Sep 19, 2022
@gopherbot
Copy link

Change https://go.dev/cl/431736 mentions this issue: gofrontend: fix struct comparison with blank field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants