Repository: Konstantin8105/c4go
Pull request #347 (2019-03-20 11:58:27)

 group convertion value to slice 

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=h1) Report
> Merging [#347](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/8a04c857d5ef1fc506bc28dfec43cb4d6a8803c6?src=pr&el=desc) will **increase** coverage by `0.06%`.
> The diff coverage is `97.14%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/347/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
+ Coverage   86.39%   86.46%   +0.06%     
==========================================
  Files         185      185              
  Lines       10532    10601      +69     
==========================================
+ Hits         9099     9166      +67     
- Misses       1023     1024       +1     
- Partials      410      411       +1
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [program/program.go](https://codecov.io/gh/Konstantin8105/c4go/pull/347/diff?src=pr&el=tree#diff-cHJvZ3JhbS9wcm9ncmFtLmdv) | `78.91% <ø> (ø)` | :arrow_up: |
| [types/resolve.go](https://codecov.io/gh/Konstantin8105/c4go/pull/347/diff?src=pr&el=tree#diff-dHlwZXMvcmVzb2x2ZS5nbw==) | `76.01% <100%> (+0.49%)` | :arrow_up: |
| [transpiler/transpiler.go](https://codecov.io/gh/Konstantin8105/c4go/pull/347/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci90cmFuc3BpbGVyLmdv) | `89.28% <100%> (+1.31%)` | :arrow_up: |
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/347/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `74.92% <87.5%> (+0.57%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=footer). Last update [8a04c85...a96de11](https://codecov.io/gh/Konstantin8105/c4go/pull/347?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index a1c02d4..9326823 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ func main() {
 	var c int32
 	fmt.Printf("Enter a number\n")
 	// get value
-	noarch.Scanf([]byte("%d\x00"), (*[100000000]int32)(unsafe.Pointer(&n))[:])
+	noarch.Scanf([]byte("%d\x00"), c4goUnsafeConvert_int32(&n))
 	noarch.Printf([]byte("The number is: %d\n\x00"), n)
 	if n == 2 {
 		// -------
@@ -114,6 +114,9 @@ func main() {
 	}
 	return
 }
+func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
+	return (*[1000000]int32)(unsafe.Pointer(c4go_name))[:]
+}
 ```
 
 # Example with binding function
@@ -146,7 +149,6 @@ int main()
 
 package main
 
-// #include </usr/include/math.h>
 import "C"
 
 import "github.com/Konstantin8105/c4go/noarch"
@@ -157,11 +159,14 @@ func main() {
 	var n int32
 	var param float64 = 8
 	var result float64
-	result = frexp(param, (*[100000000]int32)(unsafe.Pointer(&n))[:])
+	result = frexp(param, c4goUnsafeConvert_int32(&n))
 	noarch.Printf([]byte("result = %5.2f\n\x00"), result)
 	noarch.Printf([]byte("n      = %d\n\x00"), n)
 	return
 }
+func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
+	return (*[1000000]int32)(unsafe.Pointer(c4go_name))[:]
+}
 
 // Add c-binding for implemention function : `frexp`
 
@@ -186,7 +191,6 @@ void b(int v1[], int size)
     }
 }
 
-// main - transpiled function from  C4GO/examples/ap.c:14
 int main()
 {
     // value
@@ -229,6 +233,13 @@ int main()
 ```
 
 ```go
+//
+//	Package - transpiled by c4go
+//
+//	If you have found any issues, please raise an issue at:
+//	https://github.com/Konstantin8105/c4go/
+//
+
 package main
 
 import "unsafe"
@@ -250,17 +261,17 @@ func b(v1 []int32, size int32) {
 	}
 }
 
-// main - transpiled function from  C4GO/examples/ap.c:11
+// main - transpiled function from  C4GO/examples/ap.c:14
 func main() {
 	var i1 int32 = 42
 	// value
-	a((*[100000000]int32)(unsafe.Pointer(&i1))[:])
-	b((*[100000000]int32)(unsafe.Pointer(&i1))[:], 1)
+	a(c4goUnsafeConvert_int32(&i1))
+	b(c4goUnsafeConvert_int32(&i1), 1)
 	var i2 []int32 = []int32{11, 22}
 	// C-array
 	a(i2)
 	b(i2, 2)
-	var i3 []int32 = (*[100000000]int32)(unsafe.Pointer(&i1))[:]
+	var i3 []int32 = c4goUnsafeConvert_int32(&i1)
 	// C-pointer from value
 	a(i3)
 	b(i3, 1)
@@ -282,6 +293,9 @@ func main() {
 	b(i7, 1)
 	return
 }
+func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
+	return (*[1000000]int32)(unsafe.Pointer(c4go_name))[:]
+}
 ```
 
 # C standard library implementation
diff --git a/program/program.go b/program/program.go
index ba73779..1bd1294 100644
--- a/program/program.go
+++ b/program/program.go
@@ -101,6 +101,9 @@ type Program struct {
 
 	// preprocessor file
 	PreprocessorFile preprocessor.FilePP
+
+	// unsafeConvertValueToPointer - simplification for convert value to pointer
+	UnsafeConvertValueToPointer map[string]bool
 }
 
 type commentPos struct {
@@ -152,6 +155,7 @@ func NewProgram() (p *Program) {
 		commentLine:                              map[string]commentPos{},
 		functionDefinitions:                      map[string]DefinitionFunction{},
 		builtInFunctionDefinitionsHaveBeenLoaded: false,
+		UnsafeConvertValueToPointer:              map[string]bool{},
 	}
 }
 
diff --git a/scripts/9wm.sh b/scripts/9wm.sh
index e1b36b7..30fe0b7 100755
--- a/scripts/9wm.sh
+++ b/scripts/9wm.sh
@@ -37,7 +37,7 @@ $C4GO transpile  -s                                          \
 	WARNINGS_GO=`go build -o $TEMP_FOLDER/9wm.app -gcflags="-e" $FILE 2>&1 | wc -l`
 	echo "		Go build : $WARNINGS_GO warnings"
 # amount unsafe
-	UNSAFE=`cat $FILE | grep unsafe | wc -l`
+	UNSAFE=`cat $FILE | grep "unsafe\." | wc -l`
 	echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/cis71.sh b/scripts/cis71.sh
index ce48f27..6c30ca4 100755
--- a/scripts/cis71.sh
+++ b/scripts/cis71.sh
@@ -81,6 +81,6 @@ mkdir -p ./testdata/
 				WARNINGS_GO=`go build -o $TEMP_FOLDER/$COUNTER.app -gcflags="-e" $FILE 2>&1 | wc -l`
 				echo "		Go build : $WARNINGS_GO warnings"
 			# amount unsafe
-				UNSAFE=`cat $FILE | grep unsafe | wc -l`
+				UNSAFE=`cat $FILE | grep "unsafe\." | wc -l`
 				echo "		Unsafe   : $UNSAFE"
 	done
diff --git a/scripts/ed.sh b/scripts/ed.sh
index d378cab..df6b13e 100755
--- a/scripts/ed.sh
+++ b/scripts/ed.sh
@@ -42,7 +42,7 @@ $C4GO transpile  -cpuprofile=./testdata/cpu.out              \
 	WARNINGS_GO=`go build -o $TEMP_FOLDER/$COUNTER.app -gcflags="-e" $FILE 2>&1 | wc -l`
 	echo "		Go build : $WARNINGS_GO warnings"
 # amount unsafe
-	UNSAFE=`cat $FILE | grep unsafe | wc -l`
+	UNSAFE=`cat $FILE | grep "unsafe\." | wc -l`
 	echo "		Unsafe   : $UNSAFE"
 
 # Arguments menu
diff --git a/scripts/neateqn.sh b/scripts/neateqn.sh
index c4b1655..76d7eea 100755
--- a/scripts/neateqn.sh
+++ b/scripts/neateqn.sh
@@ -46,7 +46,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/neatmkfn.sh b/scripts/neatmkfn.sh
index 2de0cec..7dae66b 100755
--- a/scripts/neatmkfn.sh
+++ b/scripts/neatmkfn.sh
@@ -46,7 +46,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/neatpost.sh b/scripts/neatpost.sh
index aa40abf..3cb0b02 100755
--- a/scripts/neatpost.sh
+++ b/scripts/neatpost.sh
@@ -49,7 +49,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/neatrefer.sh b/scripts/neatrefer.sh
index a1c432d..e7bf28e 100755
--- a/scripts/neatrefer.sh
+++ b/scripts/neatrefer.sh
@@ -45,7 +45,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/neatroff.sh b/scripts/neatroff.sh
index 75f94e2..eb06e82 100755
--- a/scripts/neatroff.sh
+++ b/scripts/neatroff.sh
@@ -47,7 +47,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/neatvi.sh b/scripts/neatvi.sh
index fbd31af..cd0efd0 100755
--- a/scripts/neatvi.sh
+++ b/scripts/neatvi.sh
@@ -49,7 +49,7 @@ mkdir -p ./testdata/
 		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
 		echo "		Go build : $WARNINGS_GO warnings"
 	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep unsafe | wc -l`
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
 		echo "		Unsafe   : $UNSAFE"
 
 
diff --git a/scripts/sqlite.sh b/scripts/sqlite.sh
index 411ef3f..6e0c520 100755
--- a/scripts/sqlite.sh
+++ b/scripts/sqlite.sh
@@ -46,5 +46,5 @@ echo "After transpiling shell.c and sqlite3.c together, have summary: $SQLITE_WA
 SQLITE_WARNINGS_GO=`go build $SQLITE_TEMP_FOLDER/sqlite.go -gcflags="-e" 2>&1 | wc -l`
 echo "In file sqlite.go summary : $SQLITE_WARNINGS_GO warnings in go build."
 
-SQLITE_UNSAFE=`cat $SQLITE_TEMP_FOLDER/sqlite.go | grep unsafe | wc -l`
+SQLITE_UNSAFE=`cat $SQLITE_TEMP_FOLDER/sqlite.go | grep "unsafe\." | wc -l`
 echo "Amount unsafe package using: $SQLITE_UNSAFE"
diff --git a/transpiler/transpiler.go b/transpiler/transpiler.go
index da60a1a..0b0720c 100644
--- a/transpiler/transpiler.go
+++ b/transpiler/transpiler.go
@@ -120,6 +120,9 @@ func TranspileAST(fileName, packageName string, withOutsideStructs bool,
 		})
 	}
 
+	// add convertion value to slice
+	GetUnsafeConvertDecls(p)
+
 	// Add the imports after everything else so we can ensure that they are all
 	// placed at the top.
 	for _, quotedImportPath := range p.Imports() {
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 379fe0d..2fb18ea 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -193,6 +193,8 @@ func transpileUnaryOperatorNot(n *ast.UnaryOperator, p *program.Program) (
 // UnaryOperator 'char **' prefix '&'
 // `-DeclRefExpr 'char *' lvalue Var 0x39b95f0 'line' 'char *'
 //
+// UnaryOperator 'float *' prefix '&'
+// `-DeclRefExpr 'float' lvalue Var 0x409e2a0 't' 'float'
 func transpileUnaryOperatorAmpersant(n *ast.UnaryOperator, p *program.Program) (
 	expr goast.Expr, eType string, preStmts []goast.Stmt, postStmts []goast.Stmt, err error) {
 	defer func() {
@@ -265,11 +267,20 @@ func transpileUnaryOperatorAmpersant(n *ast.UnaryOperator, p *program.Program) (
 		return
 	}
 
+	// We now have a pointer to the original type.
+	eType += " *"
+
 	p.AddImport("unsafe")
+
+	// UnaryOperator 'float *' prefix '&'
+	// `-DeclRefExpr 'float' lvalue Var 0x409e2a0 't' 'float'
+	if e, ok := ConvertValueToPointer(n.Children(), p); ok {
+		expr = e
+		return
+	}
+
 	expr = util.CreateSliceFromReference(resolvedType, expr)
 
-	// We now have a pointer to the original type.
-	eType += " *"
 	return
 }
 
diff --git a/transpiler/value_to_pointer.go b/transpiler/value_to_pointer.go
new file mode 100644
index 0000000..9e94224
--- /dev/null
+++ b/transpiler/value_to_pointer.go
@@ -0,0 +1,108 @@
+package transpiler
+
+import (
+	"fmt"
+	"go/token"
+	"sort"
+
+	goast "go/ast"
+
+	"github.com/Konstantin8105/c4go/ast"
+	"github.com/Konstantin8105/c4go/program"
+	"github.com/Konstantin8105/c4go/types"
+	"github.com/Konstantin8105/c4go/util"
+)
+
+const unsafeConvertFunctionName string = "c4goUnsafeConvert_"
+
+func ConvertValueToPointer(nodes []ast.Node, p *program.Program) (expr goast.Expr, ok bool) {
+	if len(nodes) != 1 {
+		return nil, false
+	}
+
+	decl, ok := nodes[0].(*ast.DeclRefExpr)
+	if !ok {
+		return nil, false
+	}
+
+	if types.IsPointer(decl.Type, p) {
+		return nil, false
+	}
+
+	resolvedType, err := types.ResolveType(p, decl.Type)
+	if err != nil {
+		p.AddMessage(p.GenerateWarningMessage(err, decl))
+		return
+	}
+
+	if !types.IsGoBaseType(resolvedType) {
+		return nil, false
+	}
+
+	// can simplify
+	p.UnsafeConvertValueToPointer[resolvedType] = true
+
+	return util.NewCallExpr(fmt.Sprintf("%s%s", unsafeConvertFunctionName, resolvedType),
+		&goast.UnaryExpr{
+			Op: token.AND,
+			X:  goast.NewIdent(decl.Name),
+		}), true
+}
+
+func GetUnsafeConvertDecls(p *program.Program) {
+	if len(p.UnsafeConvertValueToPointer) == 0 {
+		return
+	}
+
+	p.AddImport("unsafe")
+
+	var names []string
+	for t, _ := range p.UnsafeConvertValueToPointer {
+		names = append(names, t)
+	}
+	sort.Sort(sort.StringSlice(names))
+
+	for _, t := range names {
+		functionName := fmt.Sprintf("%s%s", unsafeConvertFunctionName, t)
+		varName := "c4go_name"
+		p.File.Decls = append(p.File.Decls, &goast.FuncDecl{
+			Name: goast.NewIdent(functionName),
+			Type: &goast.FuncType{
+				Params: &goast.FieldList{
+					List: []*goast.Field{
+						&goast.Field{
+							Names: []*goast.Ident{goast.NewIdent(varName)},
+							Type:  goast.NewIdent("*" + t),
+						},
+					},
+				},
+				Results: &goast.FieldList{
+					List: []*goast.Field{
+						&goast.Field{
+							Type: &goast.ArrayType{
+								Lbrack: 1,
+								Elt:    goast.NewIdent(t),
+							},
+						},
+					},
+				},
+			},
+			Body: &goast.BlockStmt{
+				List: []goast.Stmt{
+					&goast.ReturnStmt{
+						Results: []goast.Expr{
+							&goast.SliceExpr{
+								X: util.NewCallExpr(fmt.Sprintf("(*[1000000]%s)", t),
+									util.NewCallExpr("unsafe.Pointer",
+										goast.NewIdent(varName)),
+								),
+							},
+						},
+					},
+				},
+			},
+		})
+	}
+
+	return
+}
diff --git a/types/resolve.go b/types/resolve.go
index 9919450..a6e8c05 100644
--- a/types/resolve.go
+++ b/types/resolve.go
@@ -28,6 +28,26 @@ var cIntegerType = []string{
 	"ptrdiff_t",
 }
 
+var goBaseTypes = [...]string{
+	"string",
+	"bool",
+	"int8", "uint8", "byte",
+	"int16", "uint16",
+	"int32", "rune", "uint32",
+	"int64", "uint64", "int",
+	"uint", "uintptr",
+	"float32", "float64",
+	"complex64", "complex128",
+}
+
+func IsGoBaseType(ctype string) bool {
+	for _, t := range goBaseTypes {
+		if ctype == t {
+			return true
+		}
+	}
+	return false
+}
 func IsSigned(p *program.Program, cType string) bool {
 	if !strings.Contains(cType, "unsigned") {
 		return true


Test patch:
diff --git a/tests/code_quality/ap.go.expected b/tests/code_quality/ap.go.expected
index 5ad664d..f425bda 100644
--- a/tests/code_quality/ap.go.expected
+++ b/tests/code_quality/ap.go.expected
@@ -35,13 +35,13 @@ func get() int32 {
 func main() {
 	var i1 int32 = 42
 	// value
-	a((*[100000000]int32)(unsafe.Pointer(&i1))[:])
-	b((*[100000000]int32)(unsafe.Pointer(&i1))[:], 1)
+	a(c4goUnsafeConvert_int32(&i1))
+	b(c4goUnsafeConvert_int32(&i1), 1)
 	var i2 []int32 = []int32{11, 22}
 	// C-array
 	a(i2)
 	b(i2, 2)
-	var i3 []int32 = (*[100000000]int32)(unsafe.Pointer(&i1))[:]
+	var i3 []int32 = c4goUnsafeConvert_int32(&i1)
 	// C-pointer from value
 	a(i3)
 	b(i3, 1)
@@ -80,3 +80,6 @@ func main() {
 	b(i11, 1)
 	return
 }
+func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
+	return (*[1000000]int32)(unsafe.Pointer(c4go_name))[:]
+}
diff --git a/tests/code_quality/unsafe.c b/tests/code_quality/unsafe.c
new file mode 100644
index 0000000..4b2e033
--- /dev/null
+++ b/tests/code_quality/unsafe.c
@@ -0,0 +1,36 @@
+#define unsafetype(type,name)	\
+void name(){					\
+	type    t;					\
+	type * pt = &t;				\
+	(void)(t);					\
+	(void)(pt);					\
+}
+
+struct str{
+	int i;
+};
+
+union un{
+	int i;
+	double d;
+};
+
+// integers
+unsafetype(char,test_char)
+unsafetype(short,test_short)
+unsafetype(int,test_int)
+unsafetype(long,test_long)
+unsafetype(long int, test_li)
+unsafetype(long long,test_ll)
+unsafetype(long long int, test_lli)
+
+// floats
+unsafetype(float, test_f)
+unsafetype(double, test_d)
+unsafetype(long double, test_ld)
+
+// struct
+unsafetype(struct str, test_struct)
+
+// union
+unsafetype(union un, test_un)
diff --git a/tests/code_quality/unsafe.go.expected b/tests/code_quality/unsafe.go.expected
new file mode 100644
index 0000000..24e8cca
--- /dev/null
+++ b/tests/code_quality/unsafe.go.expected
@@ -0,0 +1,160 @@
+//
+//	Package - transpiled by c4go
+//
+//	If you have found any issues, please raise an issue at:
+//	https://github.com/Konstantin8105/c4go/
+//
+
+package code_quality
+
+import "unsafe"
+
+// str - transpiled function from  C4GO/tests/code_quality/unsafe.c:9
+type str struct {
+	i int32
+}
+
+type un struct{ memory unsafe.Pointer }
+
+func (unionVar *un) copy() un {
+	var buffer [8]byte
+	for i := range // un - transpiled function from  C4GO/tests/code_quality/unsafe.c:13
+	buffer {
+		buffer[i] = (*((*[8]byte)(unionVar.memory)))[i]
+	}
+	var newUnion un
+	newUnion.memory = unsafe.Pointer(&buffer)
+	return newUnion
+}
+func (unionVar *un) i() *int32 {
+	if unionVar.memory == nil {
+		var buffer [8]byte
+		unionVar.memory = unsafe.Pointer(&buffer)
+	}
+	return (*int32)(unionVar.memory)
+}
+func (unionVar *un) d() *float64 {
+	if unionVar.memory == nil {
+		var buffer [8]byte
+		unionVar.memory = unsafe.Pointer(&buffer)
+	}
+	return (*float64)(unionVar.memory)
+}
+
+// test_char - transpiled function from  C4GO/tests/code_quality/unsafe.c:19
+func test_char() {
+	var t byte
+	var pt []byte = c4goUnsafeConvert_byte(&t)
+	// integers
+	_ = (t)
+	_ = (pt)
+}
+
+// test_short - transpiled function from  C4GO/tests/code_quality/unsafe.c:20
+func test_short() {
+	var t int16
+	var pt []int16 = c4goUnsafeConvert_int16(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_int - transpiled function from  C4GO/tests/code_quality/unsafe.c:21
+func test_int() {
+	var t int32
+	var pt []int32 = c4goUnsafeConvert_int32(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_long - transpiled function from  C4GO/tests/code_quality/unsafe.c:22
+func test_long() {
+	var t int32
+	var pt []int32 = c4goUnsafeConvert_int32(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_li - transpiled function from  C4GO/tests/code_quality/unsafe.c:23
+func test_li() {
+	var t int32
+	var pt []int32 = c4goUnsafeConvert_int32(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_ll - transpiled function from  C4GO/tests/code_quality/unsafe.c:24
+func test_ll() {
+	var t int64
+	var pt []int64 = c4goUnsafeConvert_int64(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_lli - transpiled function from  C4GO/tests/code_quality/unsafe.c:25
+func test_lli() {
+	var t int64
+	var pt []int64 = c4goUnsafeConvert_int64(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_f - transpiled function from  C4GO/tests/code_quality/unsafe.c:28
+func test_f() {
+	var t float32
+	var pt []float32 = c4goUnsafeConvert_float32(&t)
+	// floats
+	_ = (t)
+	_ = (pt)
+}
+
+// test_d - transpiled function from  C4GO/tests/code_quality/unsafe.c:29
+func test_d() {
+	var t float64
+	var pt []float64 = c4goUnsafeConvert_float64(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_ld - transpiled function from  C4GO/tests/code_quality/unsafe.c:30
+func test_ld() {
+	var t float64
+	var pt []float64 = c4goUnsafeConvert_float64(&t)
+	_ = (t)
+	_ = (pt)
+}
+
+// test_struct - transpiled function from  C4GO/tests/code_quality/unsafe.c:33
+func test_struct() {
+	var t str
+	var pt []str = (*[100000000]str)(unsafe.Pointer(&t))[:]
+	// struct
+	_ = (t)
+	_ = (pt)
+}
+
+// test_un - transpiled function from  C4GO/tests/code_quality/unsafe.c:36
+func test_un() {
+	var t un
+	var pt []un = (*[100000000]un)(unsafe.Pointer(&t))[:]
+	// union
+	_ = (t)
+	_ = (pt)
+}
+func c4goUnsafeConvert_byte(c4go_name *byte) []byte {
+	return (*[1000000]byte)(unsafe.Pointer(c4go_name))[:]
+}
+func c4goUnsafeConvert_float32(c4go_name *float32) []float32 {
+	return (*[1000000]float32)(unsafe.Pointer(c4go_name))[:]
+}
+func c4goUnsafeConvert_float64(c4go_name *float64) []float64 {
+	return (*[1000000]float64)(unsafe.Pointer(c4go_name))[:]
+}
+func c4goUnsafeConvert_int16(c4go_name *int16) []int16 {
+	return (*[1000000]int16)(unsafe.Pointer(c4go_name))[:]
+}
+func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
+	return (*[1000000]int32)(unsafe.Pointer(c4go_name))[:]
+}
+func c4goUnsafeConvert_int64(c4go_name *int64) []int64 {
+	return (*[1000000]int64)(unsafe.Pointer(c4go_name))[:]
+}