Source file test/fixedbugs/issue28698.go

     1  // run
     2  
     3  //go:build !js && !wasip1
     4  
     5  // Copyright 2026 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  package main
    10  
    11  import (
    12  	"bytes"
    13  	"fmt"
    14  	"os"
    15  	"os/exec"
    16  	"path/filepath"
    17  	"strings"
    18  )
    19  
    20  const src = `package p
    21  
    22  //go:noinline
    23  func sink(i int, f float64) {}
    24  
    25  func div(i int, x, y float64) {
    26  	sink(i, x/y)
    27  }
    28  `
    29  
    30  func isSoftFloat(s string) bool {
    31  	for _, v := range strings.Split(s, ",") {
    32  		if v == "softfloat" {
    33  			return true
    34  		}
    35  	}
    36  	return false
    37  }
    38  
    39  func main() {
    40  	for _, env := range []string{"GO386", "GOMIPS", "GOMIPS64", "GOARM"} {
    41  		if isSoftFloat(os.Getenv(env)) {
    42  			return
    43  		}
    44  	}
    45  
    46  	dir, err := os.MkdirTemp("", "issue28698")
    47  	if err != nil {
    48  		panic(err)
    49  	}
    50  	defer os.RemoveAll(dir)
    51  
    52  	fn := filepath.Join(dir, "p.go")
    53  	if err := os.WriteFile(fn, []byte(src), 0644); err != nil {
    54  		panic(err)
    55  	}
    56  
    57  	// Float division does not require a temporary when preparing call arguments.
    58  	cmd := exec.Command("go", "tool", "compile", "-W", fn)
    59  	out, err := cmd.CombinedOutput()
    60  	if err != nil {
    61  		panic(err)
    62  	}
    63  
    64  	if bytes.Contains(out, []byte(".autotmp_")) {
    65  		fmt.Println(string(out))
    66  		panic("unexpected autotmp")
    67  	}
    68  
    69  	// Forcing softfloat should still emit temporary.
    70  	cmd = exec.Command("go", "tool", "compile", "-W", "-d=softfloat", fn)
    71  	out, err = cmd.CombinedOutput()
    72  	if err != nil {
    73  		panic(err)
    74  	}
    75  
    76  	if !bytes.Contains(out, []byte(".autotmp_")) {
    77  		fmt.Println(string(out))
    78  		panic("no autotmp")
    79  	}
    80  }
    81  

View as plain text