-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/cgocall: add typeparams test
This CL adds a test for the cgocall pass that involves use of generics. Updates golang/go#48704 Change-Id: I521708d607c5f32ca24fe370b7d6436147bae6a5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/358695 Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Robert Findley <rfindley@google.com> Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
- Loading branch information
1 parent
26dbf47
commit 591e12a
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
go/analysis/passes/cgocall/testdata/src/typeparams/typeparams.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021 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. | ||
|
||
// This file contains tests for the cgo checker. | ||
|
||
package a | ||
|
||
// void f(void *ptr) {} | ||
import "C" | ||
|
||
import "unsafe" | ||
|
||
func CgoTest[T any]() { | ||
var c chan bool | ||
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&c))) // want "embedded pointer" | ||
C.f(unsafe.Pointer(&c)) // want "embedded pointer" | ||
|
||
var schan S[chan bool] | ||
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&schan))) // want "embedded pointer" | ||
C.f(unsafe.Pointer(&schan)) // want "embedded pointer" | ||
|
||
var x T | ||
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&x))) // no findings as T is not known compile-time | ||
C.f(unsafe.Pointer(&x)) | ||
|
||
// instantiating CgoTest should not yield any warnings | ||
CgoTest[chan bool]() | ||
|
||
var sint S[int] | ||
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&sint))) | ||
C.f(unsafe.Pointer(&sint)) | ||
} | ||
|
||
type S[X any] struct { | ||
val X | ||
} |