Skip to content

Commit

Permalink
[dev.boringcrypto] all: merge master into dev.boringcrypto
Browse files Browse the repository at this point in the history
Merge at CL 144340, in order to cherry-pick CL 149459 next to it, which
fixes a BoringCrypto specific breakage in the toolchain.

Change-Id: I30aeac344bbff279449e27876dc8f9c406e55e43
  • Loading branch information
FiloSottile committed Nov 14, 2018
2 parents af07f77 + 2e9f081 commit 11e9167
Show file tree
Hide file tree
Showing 33 changed files with 688 additions and 176 deletions.
6 changes: 5 additions & 1 deletion src/bytes/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// io.ByteScanner, and io.RuneScanner interfaces by reading from
// a byte slice.
// Unlike a Buffer, a Reader is read-only and supports seeking.
// The zero value for Reader operates like a Reader of an empty slice.
type Reader struct {
s []byte
i int64 // current reading index
Expand Down Expand Up @@ -75,10 +76,10 @@ func (r *Reader) ReadByte() (byte, error) {

// UnreadByte complements ReadByte in implementing the io.ByteScanner interface.
func (r *Reader) UnreadByte() error {
r.prevRune = -1
if r.i <= 0 {
return errors.New("bytes.Reader.UnreadByte: at beginning of slice")
}
r.prevRune = -1
r.i--
return nil
}
Expand All @@ -101,6 +102,9 @@ func (r *Reader) ReadRune() (ch rune, size int, err error) {

// UnreadRune complements ReadRune in implementing the io.RuneScanner interface.
func (r *Reader) UnreadRune() error {
if r.i <= 0 {
return errors.New("bytes.Reader.UnreadRune: at beginning of slice")
}
if r.prevRune < 0 {
return errors.New("bytes.Reader.UnreadRune: previous operation was not ReadRune")
}
Expand Down
42 changes: 42 additions & 0 deletions src/bytes/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,45 @@ func TestReaderReset(t *testing.T) {
t.Errorf("ReadAll: got %q, want %q", got, want)
}
}

func TestReaderZero(t *testing.T) {
if l := (&Reader{}).Len(); l != 0 {
t.Errorf("Len: got %d, want 0", l)
}

if n, err := (&Reader{}).Read(nil); n != 0 || err != io.EOF {
t.Errorf("Read: got %d, %v; want 0, io.EOF", n, err)
}

if n, err := (&Reader{}).ReadAt(nil, 11); n != 0 || err != io.EOF {
t.Errorf("ReadAt: got %d, %v; want 0, io.EOF", n, err)
}

if b, err := (&Reader{}).ReadByte(); b != 0 || err != io.EOF {
t.Errorf("ReadByte: got %d, %v; want 0, io.EOF", b, err)
}

if ch, size, err := (&Reader{}).ReadRune(); ch != 0 || size != 0 || err != io.EOF {
t.Errorf("ReadRune: got %d, %d, %v; want 0, 0, io.EOF", ch, size, err)
}

if offset, err := (&Reader{}).Seek(11, io.SeekStart); offset != 11 || err != nil {
t.Errorf("Seek: got %d, %v; want 11, nil", offset, err)
}

if s := (&Reader{}).Size(); s != 0 {
t.Errorf("Size: got %d, want 0", s)
}

if (&Reader{}).UnreadByte() == nil {
t.Errorf("UnreadByte: got nil, want error")
}

if (&Reader{}).UnreadRune() == nil {
t.Errorf("UnreadRune: got nil, want error")
}

if n, err := (&Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil {
t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err)
}
}
3 changes: 3 additions & 0 deletions src/cmd/compile/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Flags:
instead of $GOROOT/pkg/$GOOS_$GOARCH.
-l
Disable inlining.
-lang version
Set language version to compile, as in -lang=go1.12.
Default is current version.
-largemodel
Generate code that assumes a large memory model.
-linkobj file
Expand Down
14 changes: 11 additions & 3 deletions src/cmd/compile/internal/amd64/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,20 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
sc := v.AuxValAndOff()
off := sc.Off()
val := sc.Val()
if val == 1 {
if val == 1 || val == -1 {
var asm obj.As
if v.Op == ssa.OpAMD64ADDQconstmodify {
asm = x86.AINCQ
if val == 1 {
asm = x86.AINCQ
} else {
asm = x86.ADECQ
}
} else {
asm = x86.AINCL
if val == 1 {
asm = x86.AINCL
} else {
asm = x86.ADECL
}
}
p := s.Prog(asm)
p.To.Type = obj.TYPE_MEM
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/compile/internal/gc/builtin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/builtin/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func selectsetpc(cas *byte)
func selectgo(cas0 *byte, order0 *byte, ncases int) (int, bool)
func block()

func makeslice(typ *byte, len int, cap int) (ary []any)
func makeslice64(typ *byte, len int64, cap int64) (ary []any)
func makeslice(typ *byte, len int, cap int) unsafe.Pointer
func makeslice64(typ *byte, len int64, cap int64) unsafe.Pointer
func growslice(typ *byte, old []any, cap int) (ary []any)
func memmove(to *any, frm *any, length uintptr)
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
Expand Down
59 changes: 59 additions & 0 deletions src/cmd/compile/internal/gc/lang_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gc

import (
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)

const aliasSrc = `
package x
type T = int
`

func TestInvalidLang(t *testing.T) {
t.Parallel()

testenv.MustHaveGoBuild(t)

dir, err := ioutil.TempDir("", "TestInvalidLang")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

src := filepath.Join(dir, "alias.go")
if err := ioutil.WriteFile(src, []byte(aliasSrc), 0644); err != nil {
t.Fatal(err)
}

outfile := filepath.Join(dir, "alias.o")

if testLang(t, "go9.99", src, outfile) == nil {
t.Error("compilation with -lang=go9.99 succeeded unexpectedly")
}

if testLang(t, "go1.8", src, outfile) == nil {
t.Error("compilation with -lang=go1.8 succeeded unexpectedly")
}

if err := testLang(t, "go1.9", src, outfile); err != nil {
t.Errorf("compilation with -lang=go1.9 failed unexpectedly: %v", err)
}
}

func testLang(t *testing.T, lang, src, outfile string) error {
run := []string{testenv.GoToolPath(t), "tool", "compile", "-lang", lang, "-o", outfile, src}
t.Log(run)
out, err := exec.Command(run[0], run[1:]...).CombinedOutput()
t.Logf("%s", out)
return err
}
68 changes: 68 additions & 0 deletions src/cmd/compile/internal/gc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import (
"cmd/internal/sys"
"flag"
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"path"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -211,6 +213,7 @@ func Main(archInit func(*Arch)) {
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
objabi.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
objabi.Flagcount("l", "disable inlining", &Debug['l'])
flag.StringVar(&flag_lang, "lang", defaultLang(), "release to compile for")
flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
objabi.Flagcount("live", "debug liveness analysis", &debuglive)
objabi.Flagcount("m", "print optimization decisions", &Debug['m'])
Expand Down Expand Up @@ -277,6 +280,8 @@ func Main(archInit func(*Arch)) {
Exit(2)
}

checkLang()

thearch.LinkArch.Init(Ctxt)

if outfile == "" {
Expand Down Expand Up @@ -1304,3 +1309,66 @@ func recordFlags(flags ...string) {
Ctxt.Data = append(Ctxt.Data, s)
s.P = cmd.Bytes()[1:]
}

// flag_lang is the language version we are compiling for, set by the -lang flag.
var flag_lang string

// defaultLang returns the default value for the -lang flag.
func defaultLang() string {
tags := build.Default.ReleaseTags
return tags[len(tags)-1]
}

// goVersionRE is a regular expression that matches the valid
// arguments to the -lang flag.
var goVersionRE = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)

// A lang is a language version broken into major and minor numbers.
type lang struct {
major, minor int
}

// langWant is the desired language version set by the -lang flag.
var langWant lang

// langSupported reports whether language version major.minor is supported.
func langSupported(major, minor int) bool {
return langWant.major > major || (langWant.major == major && langWant.minor >= minor)
}

// checkLang verifies that the -lang flag holds a valid value, and
// exits if not. It initializes data used by langSupported.
func checkLang() {
var err error
langWant, err = parseLang(flag_lang)
if err != nil {
log.Fatalf("invalid value %q for -lang: %v", flag_lang, err)
}

if def := defaultLang(); flag_lang != def {
defVers, err := parseLang(def)
if err != nil {
log.Fatalf("internal error parsing default lang %q: %v", def, err)
}
if langWant.major > defVers.major || (langWant.major == defVers.major && langWant.major > defVers.minor) {
log.Fatalf("invalid value %q for -lang: max known version is %q", flag_lang, def)
}
}
}

// parseLang parses a -lang option into a langVer.
func parseLang(s string) (lang, error) {
matches := goVersionRE.FindStringSubmatch(s)
if matches == nil {
return lang{}, fmt.Errorf(`should be something like "go1.12"`)
}
major, err := strconv.Atoi(matches[1])
if err != nil {
return lang{}, err
}
minor, err := strconv.Atoi(matches[2])
if err != nil {
return lang{}, err
}
return lang{major: major, minor: minor}, nil
}
7 changes: 5 additions & 2 deletions src/cmd/compile/internal/gc/noder.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,11 @@ func (p *noder) typeDecl(decl *syntax.TypeDecl) *Node {
param.Pragma = 0
}

return p.nod(decl, ODCLTYPE, n, nil)

nod := p.nod(decl, ODCLTYPE, n, nil)
if param.Alias && !langSupported(1, 9) {
yyerrorl(nod.Pos, "type aliases only supported as of -lang=go1.9")
}
return nod
}

func (p *noder) declNames(names []*syntax.Name) []*Node {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/op_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/cmd/compile/internal/gc/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,12 @@ func (s *state) expr(n *Node) *ssa.Value {
data := s.expr(n.Right)
return s.newValue2(ssa.OpIMake, n.Type, tab, data)

case OSLICEHEADER:
p := s.expr(n.Left)
l := s.expr(n.List.First())
c := s.expr(n.List.Second())
return s.newValue3(ssa.OpSliceMake, n.Type, p, l, c)

case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR:
v := s.expr(n.Left)
var i, j, k *ssa.Value
Expand Down
Loading

0 comments on commit 11e9167

Please sign in to comment.