File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
test/query-tests/Statements/UseOfReturnlessFunction Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,6 @@ predicate returnsVoid(Function f) {
21
21
}
22
22
23
23
predicate isStub ( Function f ) {
24
- f .getBodyStmt ( 0 ) instanceof ThrowStmt
25
- or
26
24
f .getBody ( ) .( BlockStmt ) .getNumChild ( ) = 0
27
25
or
28
26
f instanceof ExternalDecl
@@ -76,10 +74,20 @@ predicate oneshotClosure(InvokeExpr call) {
76
74
call .getCallee ( ) .getUnderlyingValue ( ) instanceof ImmediatelyInvokedFunctionExpr
77
75
}
78
76
77
+ predicate alwaysThrows ( Function f ) {
78
+ exists ( ReachableBasicBlock entry , DataFlow:: Node throwNode |
79
+ entry = f .getEntryBB ( ) and
80
+ throwNode .asExpr ( ) = any ( ThrowStmt t ) .getExpr ( ) and
81
+ entry .dominates ( throwNode .getBasicBlock ( ) )
82
+ )
83
+ }
84
+
79
85
from DataFlow:: CallNode call
80
86
where
81
87
not call .isIndefinite ( _) and
82
- forex ( Function f | f = call .getACallee ( ) | returnsVoid ( f ) and not isStub ( f ) ) and
88
+ forex ( Function f | f = call .getACallee ( ) |
89
+ returnsVoid ( f ) and not isStub ( f ) and not alwaysThrows ( f )
90
+ ) and
83
91
84
92
not benignContext ( call .asExpr ( ) ) and
85
93
Original file line number Diff line number Diff line change 56
56
var oneOfEach = Math . random ( ) > 0.5 ? onlySideEffects : returnsValue ;
57
57
var g = oneOfEach ( ) ; // OK
58
58
console . log ( g ) ;
59
+
60
+ function alwaysThrows ( ) {
61
+ if ( Math . random ( ) > 0.5 ) {
62
+ console . log ( "Whatever!" )
63
+ } else {
64
+ console . log ( "Boo!" )
65
+ }
66
+ throw new Error ( "Important error!" )
67
+ }
68
+
69
+ var h = returnsValue ( ) || alwaysThrows ( ) ; // OK!
70
+ console . log ( h ) ;
59
71
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments