issue42580.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // Issue 42580: cmd/cgo: shifting identifier position in ast
  5. package cgotest
  6. // typedef int (*intFunc) ();
  7. //
  8. // char* strarg = "";
  9. //
  10. // int func_with_char(char* arg, void* dummy)
  11. // {return 5;}
  12. //
  13. // int* get_arr(char* arg, void* dummy)
  14. // {return NULL;}
  15. import "C"
  16. import "unsafe"
  17. // Test variables
  18. var (
  19. checkedPointer = []byte{1}
  20. doublePointerChecked = []byte{1}
  21. singleInnerPointerChecked = []byte{1}
  22. )
  23. // This test checks the positions of variable identifiers.
  24. // Changing the positions of the test variables idents after this point will break the test.
  25. func TestSingleArgumentCast() C.int {
  26. retcode := C.func_with_char((*C.char)(unsafe.Pointer(&checkedPointer[0])), unsafe.Pointer(C.strarg))
  27. return retcode
  28. }
  29. func TestSingleArgumentCastRecFuncAsSimpleArg() C.int {
  30. retcode := C.func_with_char((*C.char)(unsafe.Pointer(C.get_arr((*C.char)(unsafe.Pointer(&singleInnerPointerChecked[0])), unsafe.Pointer(C.strarg)))), nil)
  31. return retcode
  32. }
  33. func TestSingleArgumentCastRecFunc() C.int {
  34. 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))
  35. return retcode
  36. }