Home | History | Annotate | Download | only in fixedbugs
      1 // run
      2 
      3 // Copyright 2014 The Go Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style
      5 // license that can be found in the LICENSE file.
      6 
      7 package main
      8 
      9 import (
     10 	"fmt"
     11 	"os"
     12 	"os/exec"
     13 	"path/filepath"
     14 	"regexp"
     15 	"runtime"
     16 )
     17 
     18 func main() {
     19 	if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
     20 		return
     21 	}
     22 
     23 	err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
     24 	check(err)
     25 
     26 	out := run("go", "tool", "compile", "-S", "a.go")
     27 	os.Remove("a.o")
     28 
     29 	// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
     30 	patterns := []string{
     31 		`rel 0\+\d t=1 \"\"\.x\+8\r?\n`,       // y = &x.b
     32 		`rel 0\+\d t=1 \"\"\.x\+(28|1c)\r?\n`, // z = &x.d.q
     33 		`rel 0\+\d t=1 \"\"\.b\+5\r?\n`,       // c = &b[5]
     34 		`rel 0\+\d t=1 \"\"\.x\+(88|58)\r?\n`, // w = &x.f[3].r
     35 	}
     36 	for _, p := range patterns {
     37 		if ok, err := regexp.Match(p, out); !ok || err != nil {
     38 			println(string(out))
     39 			panic("can't find pattern " + p)
     40 		}
     41 	}
     42 }
     43 
     44 func run(cmd string, args ...string) []byte {
     45 	out, err := exec.Command(cmd, args...).CombinedOutput()
     46 	if err != nil {
     47 		fmt.Println(string(out))
     48 		fmt.Println(err)
     49 		os.Exit(1)
     50 	}
     51 	return out
     52 }
     53 
     54 func check(err error) {
     55 	if err != nil {
     56 		fmt.Println("BUG:", err)
     57 		os.Exit(1)
     58 	}
     59 }
     60