File tree Expand file tree Collapse file tree
lib/semmle/go/controlflow
test/library-tests/semmle/go/controlflow/Guards Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ private module GuardsInput implements
3131 CfgImpl:: Cfg:: BasicBlock getBasicBlock ( ) { result = this .getControlFlowNode ( ) .getBasicBlock ( ) }
3232 }
3333
34+ predicate booleanOutcomeBlock ( Expr guard , CfgImpl:: Cfg:: BasicBlock outcomeBlock , boolean branch ) {
35+ exists ( CfgImpl:: Cfg:: ControlFlowNode outcomeNode |
36+ branch = true and outcomeNode .isAfterTrue ( guard )
37+ or
38+ branch = false and outcomeNode .isAfterFalse ( guard )
39+ |
40+ outcomeBlock = outcomeNode .getBasicBlock ( )
41+ )
42+ }
43+
3444 private newtype TConstantValue = TStringValue ( string s ) { s = any ( G:: Expr e ) .getStringValue ( ) }
3545
3646 class ConstantValue extends TConstantValue {
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ controlsResult
55| guards.go:9:7:9:16 | ...==... | positive | false |
66| guards.go:9:7:9:16 | ...==... | zero | true |
77| guards.go:28:5:28:5 | a | compound true | true |
8+ | guards.go:28:5:28:17 | ...&&... | compound false | false |
9+ | guards.go:28:5:28:17 | ...&&... | compound true | true |
10+ | guards.go:28:11:28:16 | ...\|\|... | compound true | true |
811| guards.go:36:5:36:20 | ...==... | upcast | true |
912| guards.go:39:5:39:19 | ...==... | downcast | true |
1013| guards.go:42:5:42:22 | ...==... | upcast narrow | true |
@@ -24,6 +27,9 @@ valueControlsResult
2427| guards.go:9:7:9:16 | ...==... | positive | false |
2528| guards.go:9:7:9:16 | ...==... | zero | true |
2629| guards.go:28:5:28:5 | a | compound true | true |
30+ | guards.go:28:5:28:17 | ...&&... | compound false | false |
31+ | guards.go:28:5:28:17 | ...&&... | compound true | true |
32+ | guards.go:28:11:28:16 | ...\|\|... | compound true | true |
2733| guards.go:36:5:36:15 | type conversion | upcast | 0 |
2834| guards.go:36:5:36:20 | ...==... | upcast | true |
2935| guards.go:36:11:36:14 | wide | upcast | 0 |
You can’t perform that action at this time.
0 commit comments