0
1
mirror of https://github.com/golang/go synced 2025-04-07 23:54:28 +00:00
Files
.github
api
doc
lib
misc
src
test
abi
alias3.dir
asmhdr.dir
bench
chan
closure3.dir
closure5.dir
codegen
ddd2.dir
dwarf
fixedbugs
import2.dir
import4.dir
interface
intrinsic.dir
ken
linkname.dir
method4.dir
retjmp.dir
runtime
stress
syntax
typeparam
uintptrescapes.dir
235.go
64bit.go
README.md
alg.go
alias.go
alias1.go
alias2.go
alias3.go
align.go
append.go
append1.go
args.go
armimm.go
asmhdr.go
assign.go
assign1.go
atomicload.go
bigalg.go
bigmap.go
blank.go
blank1.go
bom.go
bombad.go
bounds.go
cannotassign.go
chancap.go
chanlinear.go
char_lit.go
char_lit1.go
checkbce.go
clearfat.go
closedchan.go
closure.go
closure1.go
closure2.go
closure3.go
closure4.go
closure5.go
closure6.go
closure7.go
cmp.go
cmp6.go
cmplx.go
cmplxdivide.c
cmplxdivide.go
cmplxdivide1.go
complit.go
complit1.go
compos.go
const.go
const1.go
const2.go
const3.go
const4.go
const5.go
const6.go
const7.go
const8.go
convT2X.go
convert.go
convert1.go
convert2.go
convert3.go
convert4.go
convinline.go
convlit.go
convlit1.go
copy.go
copy1.go
crlf.go
ddd.go
ddd1.go
ddd2.go
decl.go
declbad.go
defer.go
defererrcheck.go
deferfin.go
defernil.go
deferprint.go
deferprint.out
devirt.go
directive.go
directive2.go
divide.go
divmod.go
embedfunc.go
embedvers.go
empty.go
env.go
eof.go
eof1.go
escape.go
escape2.go
escape2n.go
escape3.go
escape4.go
escape5.go
escape_array.go
escape_calls.go
escape_closure.go
escape_field.go
escape_goto.go
escape_hash_maphash.go
escape_iface.go
escape_iface_nounified.go
escape_iface_unified.go
escape_indir.go
escape_level.go
escape_map.go
escape_param.go
escape_runtime_atomic.go
escape_selfassign.go
escape_slice.go
escape_struct_param1.go
escape_struct_param2.go
escape_struct_return.go
escape_sync_atomic.go
escape_unsafe.go
fibo.go
finprofiled.go
float_lit.go
float_lit2.go
float_lit3.go
floatcmp.go
for.go
func.go
func1.go
func2.go
func3.go
func4.go
func5.go
func6.go
func7.go
func8.go
funcdup.go
funcdup2.go
fuse.go
gc.go
gc1.go
gc2.go
gcgort.go
gcstring.go
goprint.go
goprint.out
goto.go
heapsampling.go
helloworld.go
helloworld.out
if.go
import.go
import1.go
import2.go
import4.go
import5.go
import6.go
index.go
index0.go
index1.go
index2.go
indirect.go
indirect1.go
init.go
init1.go
initcomma.go
initexp.go
initialize.go
initializerr.go
initloop.go
inline.go
inline_big.go
inline_caller.go
inline_callers.go
inline_endian.go
inline_literal.go
inline_math_bits_rotate.go
inline_nounified.go
inline_sync.go
inline_unified.go
inline_variadic.go
int_lit.go
intcvt.go
intrinsic.go
intrinsic_atomic.go
iota.go
label.go
label1.go
linkmain.go
linkmain_run.go
linkname.go
linkname3.go
linkobj.go
linkx.go
linkx_run.go
literal.go
literal2.go
live.go
live1.go
live2.go
live_regabi.go
live_uintptrkeepalive.go
loopbce.go
mainsig.go
makechan.go
makemap.go
makenew.go
makeslice.go
mallocfin.go
map.go
map1.go
mapclear.go
maplinear.go
maymorestack.go
mergemul.go
method.go
method1.go
method2.go
method3.go
method4.go
method5.go
method6.go
method7.go
named.go
named1.go
nil.go
nilcheck.go
nilptr.go
nilptr2.go
nilptr3.go
nilptr4.go
nilptr5.go
nilptr5_aix.go
nilptr5_wasm.go
nilptr_aix.go
noinit.go
nosplit.go
nowritebarrier.go
nul1.go
opt_branchlikely.go
parentype.go
peano.go
phiopt.go
print.go
print.out
printbig.go
printbig.out
prove.go
prove_constant_folding.go
range.go
recover.go
recover1.go
recover2.go
recover3.go
recover4.go
recover5.go
reflectmethod1.go
reflectmethod2.go
reflectmethod3.go
reflectmethod4.go
reflectmethod5.go
reflectmethod6.go
reflectmethod7.go
reflectmethod8.go
rename.go
rename1.go
reorder.go
reorder2.go
retjmp.go
return.go
rotate.go
rotate0.go
rotate1.go
rotate2.go
rotate3.go
run.go
rune.go
runtime.go
shift1.go
shift2.go
shift3.go
sieve.go
sigchld.go
sigchld.out
simassign.go
sizeof.go
slice3.go
slice3err.go
slicecap.go
sliceopt.go
solitaire.go
stack.go
stackobj.go
stackobj2.go
stackobj3.go
strcopy.go
strength.go
string_lit.go
stringrange.go
struct0.go
switch.go
switch2.go
switch3.go
switch4.go
switch5.go
switch6.go
switch7.go
tinyfin.go
torture.go
turing.go
typecheck.go
typecheckloop.go
typeswitch.go
typeswitch1.go
typeswitch2.go
typeswitch2b.go
typeswitch3.go
uintptrescapes.go
uintptrescapes2.go
uintptrescapes3.go
uintptrkeepalive.go
undef.go
unsafe_slice_data.go
unsafe_string.go
unsafe_string_data.go
unsafebuiltins.go
used.go
utf.go
varerr.go
varinit.go
winbatch.go
writebarrier.go
zerodivide.go
.gitattributes
.gitignore
CONTRIBUTING.md
LICENSE
PATENTS
README.md
SECURITY.md
VERSION
codereview.cfg
Ainar Garipov 0efbd10157 all: fix typos
Use the following (suboptimal) script to obtain a list of possible
typos:

  #!/usr/bin/env sh

  set -x

  git ls-files |\
    grep -e '\.\(c\|cc\|go\)$' |\
    xargs -n 1\
    awk\
    '/\/\// { gsub(/.*\/\//, ""); print; } /\/\*/, /\*\// { gsub(/.*\/\*/, ""); gsub(/\*\/.*/, ""); }' |\
    hunspell -d en_US -l |\
    grep '^[[:upper:]]\{0,1\}[[:lower:]]\{1,\}$' |\
    grep -v -e '^.\{1,4\}$' -e '^.\{16,\}$' |\
    sort -f |\
    uniq -c |\
    awk '$1 == 1 { print $2; }'

Then, go through the results manually and fix the most obvious typos in
the non-vendored code.

Change-Id: I3cb5830a176850e1a0584b8a40b47bde7b260eae
Reviewed-on: https://go-review.googlesource.com/c/go/+/193848
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-09-08 17:28:20 +00:00

300 lines
6.4 KiB
Go

// skip
// Copyright 2010 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.
// Generate test of index and slice bounds checks.
// The actual tests are index0.go, index1.go, index2.go.
package main
import (
"bufio"
"fmt"
"os"
"unsafe"
)
const prolog = `
package main
import (
"runtime"
)
type quad struct { x, y, z, w int }
const (
cj = 100011
ci int = 100012
ci8 int8 = 115
ci16 int16 = 10016
ci32 int32 = 100013
ci64 int64 = 100014
ci64big int64 = 1<<31
ci64bigger int64 = 1<<32
chuge = 1<<100
cfgood = 2.0
cfbad = 2.1
cnj = -2
cni int = -3
cni8 int8 = -6
cni16 int16 = -7
cni32 int32 = -4
cni64 int64 = -5
cni64big int64 = -1<<31
cni64bigger int64 = -1<<32
cnhuge = -1<<100
cnfgood = -2.0
cnfbad = -2.1
)
var j int = 100020
var i int = 100021
var i8 int8 = 126
var i16 int16 = 10025
var i32 int32 = 100022
var i64 int64 = 100023
var i64big int64 = 1<<31
var i64bigger int64 = 1<<32
var huge uint64 = 1<<64 - 1
var fgood float64 = 2.0
var fbad float64 = 2.1
var nj int = -10
var ni int = -11
var ni8 int8 = -14
var ni16 int16 = -15
var ni32 int32 = -12
var ni64 int64 = -13
var ni64big int64 = -1<<31
var ni64bigger int64 = -1<<32
var nhuge int64 = -1<<63
var nfgood float64 = -2.0
var nfbad float64 = -2.1
var si []int = make([]int, 10)
var ai [10]int
var pai *[10]int = &ai
var sq []quad = make([]quad, 10)
var aq [10]quad
var paq *[10]quad = &aq
var sib []int = make([]int, 100000)
var aib [100000]int
var paib *[100000]int = &aib
var sqb []quad = make([]quad, 100000)
var aqb [100000]quad
var paqb *[100000]quad = &aqb
type T struct {
si []int
ai [10]int
pai *[10]int
sq []quad
aq [10]quad
paq *[10]quad
sib []int
aib [100000]int
paib *[100000]int
sqb []quad
aqb [100000]quad
paqb *[100000]quad
}
var t = T{si, ai, pai, sq, aq, paq, sib, aib, paib, sqb, aqb, paqb}
var pt = &T{si, ai, pai, sq, aq, paq, sib, aib, paib, sqb, aqb, paqb}
// test that f panics
func test(f func(), s string) {
defer func() {
if err := recover(); err == nil {
_, file, line, _ := runtime.Caller(2)
bug()
print(file, ":", line, ": ", s, " did not panic\n")
} else if !contains(err.(error).Error(), "out of range") {
_, file, line, _ := runtime.Caller(2)
bug()
print(file, ":", line, ": ", s, " unexpected panic: ", err.(error).Error(), "\n")
}
}()
f()
}
func contains(x, y string) bool {
for i := 0; i+len(y) <= len(x); i++ {
if x[i:i+len(y)] == y {
return true
}
}
return false
}
var X interface{}
func use(y interface{}) {
X = y
}
var didBug = false
func bug() {
if !didBug {
didBug = true
println("BUG")
}
}
func main() {
`
// pass variable set in index[012].go
// 0 - dynamic checks
// 1 - static checks of invalid constants (cannot assign to types)
// 2 - static checks of array bounds
func testExpr(b *bufio.Writer, expr string) {
if pass == 0 {
fmt.Fprintf(b, "\ttest(func(){use(%s)}, %q)\n", expr, expr)
} else {
fmt.Fprintf(b, "\tuse(%s) // ERROR \"index|overflow|truncated|must be integer\"\n", expr)
}
}
func main() {
b := bufio.NewWriter(os.Stdout)
if pass == 0 {
fmt.Fprint(b, "// run\n\n")
} else {
fmt.Fprint(b, "// errorcheck\n\n")
}
fmt.Fprint(b, prolog)
var choices = [][]string{
// Direct value, fetch from struct, fetch from struct pointer.
// The last two cases get us to oindex_const_sudo in gsubr.c.
[]string{"", "t.", "pt."},
// Array, pointer to array, slice.
[]string{"a", "pa", "s"},
// Element is int, element is quad (struct).
// This controls whether we end up in gsubr.c (i) or cgen.c (q).
[]string{"i", "q"},
// Small or big len.
[]string{"", "b"},
// Variable or constant.
[]string{"", "c"},
// Positive or negative.
[]string{"", "n"},
// Size of index.
[]string{"j", "i", "i8", "i16", "i32", "i64", "i64big", "i64bigger", "huge", "fgood", "fbad"},
}
forall(choices, func(x []string) {
p, a, e, big, c, n, i := x[0], x[1], x[2], x[3], x[4], x[5], x[6]
// Pass: dynamic=0, static=1, 2.
// Which cases should be caught statically?
// Only constants, obviously.
// Beyond that, must be one of these:
// indexing into array or pointer to array
// negative constant
// large constant
thisPass := 0
if c == "c" && (a == "a" || a == "pa" || n == "n" || i == "i64big" || i == "i64bigger" || i == "huge" || i == "fbad") {
if i == "huge" {
// Due to a detail of gc's internals,
// the huge constant errors happen in an
// earlier pass than the others and inhibits
// the next pass from running.
// So run it as a separate check.
thisPass = 1
} else if a == "s" && n == "" && (i == "i64big" || i == "i64bigger") && unsafe.Sizeof(int(0)) > 4 {
// If int is 64 bits, these huge
// numbers do fit in an int, so they
// are not rejected at compile time.
thisPass = 0
} else {
thisPass = 2
}
}
pae := p + a + e + big
cni := c + n + i
// If we're using the big-len data, positive int8 and int16 cannot overflow.
if big == "b" && n == "" && (i == "i8" || i == "i16") {
if pass == 0 {
fmt.Fprintf(b, "\tuse(%s[%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[0:%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[1:%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[%s:])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[%s:%s])\n", pae, cni, cni)
}
return
}
// Float variables cannot be used as indices.
if c == "" && (i == "fgood" || i == "fbad") {
return
}
// Integral float constant is ok.
if c == "c" && n == "" && i == "fgood" {
if pass == 0 {
fmt.Fprintf(b, "\tuse(%s[%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[0:%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[1:%s])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[%s:])\n", pae, cni)
fmt.Fprintf(b, "\tuse(%s[%s:%s])\n", pae, cni, cni)
}
return
}
// Only print the test case if it is appropriate for this pass.
if thisPass == pass {
// Index operation
testExpr(b, pae+"["+cni+"]")
// Slice operation.
// Low index 0 is a special case in ggen.c
// so test both 0 and 1.
testExpr(b, pae+"[0:"+cni+"]")
testExpr(b, pae+"[1:"+cni+"]")
testExpr(b, pae+"["+cni+":]")
testExpr(b, pae+"["+cni+":"+cni+"]")
}
})
fmt.Fprintln(b, "}")
b.Flush()
}
func forall(choices [][]string, f func([]string)) {
x := make([]string, len(choices))
var recurse func(d int)
recurse = func(d int) {
if d >= len(choices) {
f(x)
return
}
for _, x[d] = range choices[d] {
recurse(d + 1)
}
}
recurse(0)
}