diff --git a/tools/checklocks/analysis.go b/tools/checklocks/analysis.go index 8a8f18ea5..f1ab91c47 100644 --- a/tools/checklocks/analysis.go +++ b/tools/checklocks/analysis.go @@ -268,6 +268,10 @@ func (pc *passContext) checkGuards(inst almostInst, from ssa.Value, accessObj ty pc.maybeFail(inst.Pos(), "non-atomic write of field %s, writes must still be atomic with locks held (locks: %s)", accessObj.Name(), ls.String()) } case atomicDisallow: + // If atomic analysis is not enabled, skip. + if !enableAtomic { + break + } // Check that this is *not* used atomically. if refs := inst.Referrers(); refs != nil { for _, otherInst := range *refs { diff --git a/tools/checklocks/annotations.go b/tools/checklocks/annotations.go index 950168ee1..9e328edbb 100644 --- a/tools/checklocks/annotations.go +++ b/tools/checklocks/annotations.go @@ -91,6 +91,9 @@ func (pc *passContext) maybeFail(pos token.Pos, fmtStr string, args ...interface if _, ok := pc.exemptions[pc.positionKey(pos)]; ok { return // Ignored, not counted. } + if !enableWrappers && !pos.IsValid() { + return // Ignored, implicit. + } pc.pass.Reportf(pos, fmtStr, args...) } diff --git a/tools/checklocks/checklocks.go b/tools/checklocks/checklocks.go index 939af4239..70921a15c 100644 --- a/tools/checklocks/checklocks.go +++ b/tools/checklocks/checklocks.go @@ -41,6 +41,18 @@ var Analyzer = &analysis.Analyzer{ }, } +var ( + enableInferred = true + enableAtomic = true + enableWrappers = true +) + +func init() { + Analyzer.Flags.BoolVar(&enableInferred, "inferred", true, "enable inferred locks") + Analyzer.Flags.BoolVar(&enableAtomic, "atomic", true, "enable atomic checks") + Analyzer.Flags.BoolVar(&enableWrappers, "wrappers", true, "enable analysis of wrappers") +} + // objectObservations tracks lock correlations. type objectObservations struct { counts map[types.Object]int @@ -187,7 +199,9 @@ func run(pass *analysis.Pass) (interface{}, error) { } // Check for inferred checklocks annotations. - pc.checkInferred() + if enableInferred { + pc.checkInferred() + } // Check for expected failures. pc.checkFailures()