diff --git a/VERSION b/VERSION index 1544f466a6ab7f..f115bef4b59ca5 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -go1.21.1 -time 2023-08-31T22:36:09Z +go1.21.2 +time 2023-09-28T20:21:36Z diff --git a/src/cmd/cgo/internal/testerrors/errors_test.go b/src/cmd/cgo/internal/testerrors/errors_test.go index 486530e186c610..870d05b4914e16 100644 --- a/src/cmd/cgo/internal/testerrors/errors_test.go +++ b/src/cmd/cgo/internal/testerrors/errors_test.go @@ -111,6 +111,7 @@ func TestReportsTypeErrors(t *testing.T) { for _, file := range []string{ "err1.go", "err2.go", + "err5.go", "issue11097a.go", "issue11097b.go", "issue18452.go", diff --git a/src/cmd/cgo/internal/testerrors/testdata/err5.go b/src/cmd/cgo/internal/testerrors/testdata/err5.go new file mode 100644 index 00000000000000..779d745ba7037f --- /dev/null +++ b/src/cmd/cgo/internal/testerrors/testdata/err5.go @@ -0,0 +1,10 @@ +// Copyright 2023 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 main + +//line /tmp/_cgo_.go:1 +//go:cgo_dynamic_linker "/elf/interp" // ERROR HERE: only allowed in cgo-generated code + +func main() {} diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index 25a6ba7c889383..94071581fedbeb 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -333,8 +333,14 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P // contain cgo directives, and for security reasons // (primarily misuse of linker flags), other files are not. // See golang.org/issue/23672. +// Note that cmd/go ignores files whose names start with underscore, +// so the only _cgo_ files we will see from cmd/go are generated by cgo. +// It's easy to bypass this check by calling the compiler directly; +// we only protect against uses by cmd/go. func isCgoGeneratedFile(pos syntax.Pos) bool { - return strings.HasPrefix(filepath.Base(trimFilename(pos.Base())), "_cgo_") + // We need the absolute file, independent of //line directives, + // so we call pos.Base().Pos(). + return strings.HasPrefix(filepath.Base(trimFilename(pos.Base().Pos().Base())), "_cgo_") } // safeArg reports whether arg is a "safe" command-line argument, diff --git a/src/cmd/compile/internal/ssa/_gen/ARM64.rules b/src/cmd/compile/internal/ssa/_gen/ARM64.rules index 72319c7d896c3b..8cf6f6740ea84d 100644 --- a/src/cmd/compile/internal/ssa/_gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/_gen/ARM64.rules @@ -1552,20 +1552,22 @@ (GreaterEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.uge())]) // absorb InvertFlags into boolean values -(Equal (InvertFlags x)) => (Equal x) -(NotEqual (InvertFlags x)) => (NotEqual x) -(LessThan (InvertFlags x)) => (GreaterThan x) -(LessThanU (InvertFlags x)) => (GreaterThanU x) -(GreaterThan (InvertFlags x)) => (LessThan x) -(GreaterThanU (InvertFlags x)) => (LessThanU x) -(LessEqual (InvertFlags x)) => (GreaterEqual x) -(LessEqualU (InvertFlags x)) => (GreaterEqualU x) -(GreaterEqual (InvertFlags x)) => (LessEqual x) -(GreaterEqualU (InvertFlags x)) => (LessEqualU x) -(LessThanF (InvertFlags x)) => (GreaterThanF x) -(LessEqualF (InvertFlags x)) => (GreaterEqualF x) -(GreaterThanF (InvertFlags x)) => (LessThanF x) -(GreaterEqualF (InvertFlags x)) => (LessEqualF x) +(Equal (InvertFlags x)) => (Equal x) +(NotEqual (InvertFlags x)) => (NotEqual x) +(LessThan (InvertFlags x)) => (GreaterThan x) +(LessThanU (InvertFlags x)) => (GreaterThanU x) +(GreaterThan (InvertFlags x)) => (LessThan x) +(GreaterThanU (InvertFlags x)) => (LessThanU x) +(LessEqual (InvertFlags x)) => (GreaterEqual x) +(LessEqualU (InvertFlags x)) => (GreaterEqualU x) +(GreaterEqual (InvertFlags x)) => (LessEqual x) +(GreaterEqualU (InvertFlags x)) => (LessEqualU x) +(LessThanF (InvertFlags x)) => (GreaterThanF x) +(LessEqualF (InvertFlags x)) => (GreaterEqualF x) +(GreaterThanF (InvertFlags x)) => (LessThanF x) +(GreaterEqualF (InvertFlags x)) => (LessEqualF x) +(LessThanNoov (InvertFlags x)) => (BIC (GreaterEqualNoov x) (Equal x)) +(GreaterEqualNoov (InvertFlags x)) => (OR (LessThanNoov x) (Equal x)) // Boolean-generating instructions (NOTE: NOT all boolean Values) always // zero upper bit of the register; no need to zero-extend diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 196d8931d6e3e7..3b8fe30371f07a 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -154,6 +154,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64GreaterEqual(v) case OpARM64GreaterEqualF: return rewriteValueARM64_OpARM64GreaterEqualF(v) + case OpARM64GreaterEqualNoov: + return rewriteValueARM64_OpARM64GreaterEqualNoov(v) case OpARM64GreaterEqualU: return rewriteValueARM64_OpARM64GreaterEqualU(v) case OpARM64GreaterThan: @@ -174,6 +176,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64LessThan(v) case OpARM64LessThanF: return rewriteValueARM64_OpARM64LessThanF(v) + case OpARM64LessThanNoov: + return rewriteValueARM64_OpARM64LessThanNoov(v) case OpARM64LessThanU: return rewriteValueARM64_OpARM64LessThanU(v) case OpARM64MADD: @@ -5953,6 +5957,27 @@ func rewriteValueARM64_OpARM64GreaterEqualF(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64GreaterEqualNoov(v *Value) bool { + v_0 := v.Args[0] + b := v.Block + typ := &b.Func.Config.Types + // match: (GreaterEqualNoov (InvertFlags x)) + // result: (OR (LessThanNoov x) (Equal x)) + for { + if v_0.Op != OpARM64InvertFlags { + break + } + x := v_0.Args[0] + v.reset(OpARM64OR) + v0 := b.NewValue0(v.Pos, OpARM64LessThanNoov, typ.Bool) + v0.AddArg(x) + v1 := b.NewValue0(v.Pos, OpARM64Equal, typ.Bool) + v1.AddArg(x) + v.AddArg2(v0, v1) + return true + } + return false +} func rewriteValueARM64_OpARM64GreaterEqualU(v *Value) bool { v_0 := v.Args[0] // match: (GreaterEqualU (FlagConstant [fc])) @@ -6667,6 +6692,27 @@ func rewriteValueARM64_OpARM64LessThanF(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64LessThanNoov(v *Value) bool { + v_0 := v.Args[0] + b := v.Block + typ := &b.Func.Config.Types + // match: (LessThanNoov (InvertFlags x)) + // result: (BIC (GreaterEqualNoov x) (Equal x)) + for { + if v_0.Op != OpARM64InvertFlags { + break + } + x := v_0.Args[0] + v.reset(OpARM64BIC) + v0 := b.NewValue0(v.Pos, OpARM64GreaterEqualNoov, typ.Bool) + v0.AddArg(x) + v1 := b.NewValue0(v.Pos, OpARM64Equal, typ.Bool) + v1.AddArg(x) + v.AddArg2(v0, v1) + return true + } + return false +} func rewriteValueARM64_OpARM64LessThanU(v *Value) bool { v_0 := v.Args[0] // match: (LessThanU (FlagConstant [fc])) diff --git a/test/fixedbugs/issue62469.go b/test/fixedbugs/issue62469.go new file mode 100644 index 00000000000000..d850ccb289b38d --- /dev/null +++ b/test/fixedbugs/issue62469.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2023 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 p + +func sign(p1, p2, p3 point) bool { + return (p1.x-p3.x)*(p2.y-p3.y)-(p2.x-p3.x)*(p1.y-p3.y) < 0 +} + +type point struct { + x, y int +}