• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Issue 42580: cmd/cgo: shifting identifier position in ast
6
7package cgotest
8
9// typedef int (*intFunc) ();
10//
11// char* strarg = "";
12//
13// int func_with_char(char* arg, void* dummy)
14// {return 5;}
15//
16// int* get_arr(char* arg, void* dummy)
17// {return NULL;}
18import "C"
19import "unsafe"
20
21// Test variables
22var (
23	checkedPointer            = []byte{1}
24	doublePointerChecked      = []byte{1}
25	singleInnerPointerChecked = []byte{1}
26)
27
28// This test checks the positions of variable identifiers.
29// Changing the positions of the test variables idents after this point will break the test.
30
31func TestSingleArgumentCast() C.int {
32	retcode := C.func_with_char((*C.char)(unsafe.Pointer(&checkedPointer[0])), unsafe.Pointer(C.strarg))
33	return retcode
34}
35
36func TestSingleArgumentCastRecFuncAsSimpleArg() C.int {
37	retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&singleInnerPointerChecked[0])), unsafe.Pointer(C.strarg)))), nil)
38	return retcode
39}
40
41func TestSingleArgumentCastRecFunc() C.int {
42	retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&doublePointerChecked[0])), unsafe.Pointer(C.strarg)))), unsafe.Pointer(C.strarg))
43	return retcode
44}
45