mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #10575 from andrew-d:andrew/checklocks-field-comment
PiperOrigin-RevId: 648748528
This commit is contained in:
@@ -670,7 +670,11 @@ func (pc *passContext) structLockGuardFacts(structType *types.Struct, ss *ast.St
|
||||
for i, field := range ss.Fields.List {
|
||||
var lgf lockGuardFacts
|
||||
fieldObj = structType.Field(i) // N.B. Captured above.
|
||||
pc.fillLockGuardFacts(fieldObj, field.Doc, findLocal, &lgf)
|
||||
if field.Doc != nil {
|
||||
pc.fillLockGuardFacts(fieldObj, field.Doc, findLocal, &lgf)
|
||||
} else if field.Comment != nil {
|
||||
pc.fillLockGuardFacts(fieldObj, field.Comment, findLocal, &lgf)
|
||||
}
|
||||
|
||||
// See above, for anonymous structure fields.
|
||||
if ss, ok := field.Type.(*ast.StructType); ok {
|
||||
|
||||
@@ -143,3 +143,13 @@ func testTwoLocksDoubleGuardStructOnlyOne(tc *twoLocksDoubleGuardStruct) {
|
||||
func testTwoLocksDoubleGuardStructInvalid(tc *twoLocksDoubleGuardStruct) {
|
||||
tc.doubleGuardedField = 3 // +checklocksfail:2
|
||||
}
|
||||
|
||||
func testFieldCommentValid(tc *fieldCommentStruct) {
|
||||
tc.mu.Lock()
|
||||
tc.guardedField = 1
|
||||
tc.mu.Unlock()
|
||||
}
|
||||
|
||||
func testFieldCommentInvalid(tc *fieldCommentStruct) {
|
||||
tc.guardedField = 2 // +checklocksfail
|
||||
}
|
||||
|
||||
@@ -64,3 +64,10 @@ type nestedGuardStruct struct {
|
||||
val oneGuardStruct
|
||||
ptr *oneGuardStruct
|
||||
}
|
||||
|
||||
// fieldCommentStruct has one lock and a single field, but uses the
|
||||
// field.Comment instead of field.Doc for the guard.
|
||||
type fieldCommentStruct struct {
|
||||
mu sync.Mutex
|
||||
guardedField int // +checklocks:mu
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user