X7ROOT File Manager
Current Path:
/opt/golang/1.19.4/src/cmd/compile/internal/test/testdata
opt
/
golang
/
1.19.4
/
src
/
cmd
/
compile
/
internal
/
test
/
testdata
/
📁
..
📄
addressed_test.go
(4.42 KB)
📄
append_test.go
(1.16 KB)
📄
arithBoundary_test.go
(31.31 KB)
📄
arithConst_test.go
(633.8 KB)
📄
arith_test.go
(41.51 KB)
📄
array_test.go
(3.09 KB)
📄
assert_test.go
(2.54 KB)
📄
break_test.go
(3.67 KB)
📄
chan_test.go
(1.14 KB)
📄
closure_test.go
(572 B)
📄
cmpConst_test.go
(103.06 KB)
📄
cmp_test.go
(903 B)
📄
compound_test.go
(2.7 KB)
📄
copy_test.go
(150.18 KB)
📄
ctl_test.go
(2.33 KB)
📄
deferNoReturn_test.go
(481 B)
📄
divbyzero_test.go
(1.01 KB)
📄
dupLoad_test.go
(1.51 KB)
📄
flowgraph_generator1.go
(6.72 KB)
📄
fp_test.go
(34.99 KB)
📁
gen
📄
loadstore_test.go
(4.79 KB)
📄
map_test.go
(721 B)
📁
mysort
📄
namedReturn_test.go
(1.63 KB)
📄
phi_test.go
(2.21 KB)
📄
ptrsort.go
(633 B)
📄
ptrsort.out
(77 B)
📄
regalloc_test.go
(1.2 KB)
📁
reproducible
📄
short_test.go
(1.48 KB)
📄
slice_test.go
(850 B)
📄
sqrtConst_test.go
(1.26 KB)
📄
string_test.go
(4.46 KB)
📄
unsafe_test.go
(2.96 KB)
📄
zero_test.go
(49.6 KB)
Editing: unsafe_test.go
// Copyright 2015 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 import ( "runtime" "testing" "unsafe" ) // global pointer slot var a *[8]uint // unfoldable true var always = true // Test to make sure that a pointer value which is alive // across a call is retained, even when there are matching // conversions to/from uintptr around the call. // We arrange things very carefully to have to/from // conversions on either side of the call which cannot be // combined with any other conversions. func f_ssa() *[8]uint { // Make x a uintptr pointing to where a points. var x uintptr if always { x = uintptr(unsafe.Pointer(a)) } else { x = 0 } // Clobber the global pointer. The only live ref // to the allocated object is now x. a = nil // Convert to pointer so it should hold // the object live across GC call. p := unsafe.Pointer(x) // Call gc. runtime.GC() // Convert back to uintptr. y := uintptr(p) // Mess with y so that the subsequent cast // to unsafe.Pointer can't be combined with the // uintptr cast above. var z uintptr if always { z = y } else { z = 0 } return (*[8]uint)(unsafe.Pointer(z)) } // g_ssa is the same as f_ssa, but with a bit of pointer // arithmetic for added insanity. func g_ssa() *[7]uint { // Make x a uintptr pointing to where a points. var x uintptr if always { x = uintptr(unsafe.Pointer(a)) } else { x = 0 } // Clobber the global pointer. The only live ref // to the allocated object is now x. a = nil // Offset x by one int. x += unsafe.Sizeof(int(0)) // Convert to pointer so it should hold // the object live across GC call. p := unsafe.Pointer(x) // Call gc. runtime.GC() // Convert back to uintptr. y := uintptr(p) // Mess with y so that the subsequent cast // to unsafe.Pointer can't be combined with the // uintptr cast above. var z uintptr if always { z = y } else { z = 0 } return (*[7]uint)(unsafe.Pointer(z)) } func testf(t *testing.T) { a = new([8]uint) for i := 0; i < 8; i++ { a[i] = 0xabcd } c := f_ssa() for i := 0; i < 8; i++ { if c[i] != 0xabcd { t.Fatalf("%d:%x\n", i, c[i]) } } } func testg(t *testing.T) { a = new([8]uint) for i := 0; i < 8; i++ { a[i] = 0xabcd } c := g_ssa() for i := 0; i < 7; i++ { if c[i] != 0xabcd { t.Fatalf("%d:%x\n", i, c[i]) } } } func alias_ssa(ui64 *uint64, ui32 *uint32) uint32 { *ui32 = 0xffffffff *ui64 = 0 // store ret := *ui32 // load from same address, should be zero *ui64 = 0xffffffffffffffff // store return ret } func testdse(t *testing.T) { x := int64(-1) // construct two pointers that alias one another ui64 := (*uint64)(unsafe.Pointer(&x)) ui32 := (*uint32)(unsafe.Pointer(&x)) if want, got := uint32(0), alias_ssa(ui64, ui32); got != want { t.Fatalf("alias_ssa: wanted %d, got %d\n", want, got) } } func TestUnsafe(t *testing.T) { testf(t) testg(t) testdse(t) }
Upload File
Create Folder