| 40 | } |
| 41 | |
| 42 | func testInconsistentBranching(tc *oneGuardStruct) { // +checklocksfail=incompatible return states|incompatible return states |
| 43 | // We traverse the control flow graph in all consistent ways. We cannot |
| 44 | // determine however, that the first if block and second if block will |
| 45 | // evaluate to the same condition. Therefore, there are two consistent |
| 46 | // paths through this code, and two inconsistent paths. Either way, the |
| 47 | // guardedField should be also marked as an invalid access. |
| 48 | x := rand.Intn(10) |
| 49 | if x%2 == 1 { |
| 50 | tc.mu.Lock() |
| 51 | } |
| 52 | tc.guardedField = 1 // +checklocksfail |
| 53 | if x%2 == 1 { |
| 54 | tc.mu.Unlock() // +checklocksforce |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func testUnboundedLocks(tc []*oneGuardStruct) { |
| 59 | for _, l := range tc { |