mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Ruby: Avoid computing full fastTC for AstNode::getParent
DIL before
```
/* AST::AstNode */ AST#87953007::Cached::TAstNode result) =
fastTC(AST#a6718388::AstNode::getAChild#0#dispred#ff/2)
.
Completion#445d5844::mayRaise#1#f(/* Call::Call */ unique AST#87953007::Cached::TAstNode c)
:-
exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode call_result#2 |
exists(/* ControlFlowGraphImpl::Trees::BodyStmtTree */ AST#87953007::Cached::TAstNode bst |
(
(
project#Expr#6fb2af19::BodyStmt::getRescue#1#dispred#fff(bst),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
);
(
exists(/* Expr::StmtSequence */ dontcare AST#87953007::Cached::TAstNode _ |
Expr#6fb2af19::BodyStmt::getEnsure#0#dispred#ff(bst, _)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst),
project#ControlFlowGraphImpl#288ae92e::Trees::StmtSequenceTree::getBodyChild#2#dispred#ffff(bst,
call_result#2)
),
(
(c = call_result#2, Call#841c84e8::Call#f(c));
(
#AST#a6718388::AstNode::getAChild#0#dispredPlus#ff(call_result#2, c),
Call#841c84e8::Call#f(c)
)
)
)
.
```
DIL after
```
incremental
Completion#445d5844::getARescuableBodyChild#0#f(/* AST::AstNode */ unique AST#87953007::Cached::TAstNode result)
:-
exists(/* ControlFlowGraphImpl::Trees::BodyStmtTree */ AST#87953007::Cached::TAstNode bst |
(
(
exists(dontcare int _,
/* Expr::RescueClause */ dontcare AST#87953007::Cached::TAstNode _1 |
Expr#6fb2af19::BodyStmt::getRescue#1#dispred#fff(bst, _, _1)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
);
(
exists(/* Expr::StmtSequence */ dontcare AST#87953007::Cached::TAstNode _ |
Expr#6fb2af19::BodyStmt::getEnsure#0#dispred#ff(bst, _)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst),
exists(boolean arg2, dontcare int _ |
arg2 = true,
ControlFlowGraphImpl#288ae92e::Trees::StmtSequenceTree::getBodyChild#2#dispred#ffff(bst,
_,
arg2,
result)
)
);
exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode call_result#5 |
rec Completion#445d5844::getARescuableBodyChild#0#f(call_result#5),
exists(cached dontcare string _ |
AST#a6718388::AstNode::getAChild#1#dispred(call_result#5, _, result)
)
)
| [base_case]
exists(/* ControlFlowGraphImpl::Trees::BodyStmtTree */ AST#87953007::Cached::TAstNode bst |
(
(
project#Expr#6fb2af19::BodyStmt::getRescue#1#dispred#fff(bst),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
);
(
exists(/* Expr::StmtSequence */ dontcare AST#87953007::Cached::TAstNode _ |
Expr#6fb2af19::BodyStmt::getEnsure#0#dispred#ff(bst, _)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst)
)
),
ControlFlowGraphImpl#288ae92e::Trees::BodyStmtTree#class#f(bst),
project#ControlFlowGraphImpl#288ae92e::Trees::StmtSequenceTree::getBodyChild#2#dispred#ffff(bst,
result)
)
| [delta_order]
exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode call_result#5 |
delta previous rec Completion#445d5844::getARescuableBodyChild#0#f(call_result#5),
project#AST#a6718388::AstNode::getAChild#1#dispred(call_result#5, result)
),
not(previous rec Completion#445d5844::getARescuableBodyChild#0#f(result))
.
```
This commit is contained in:
@@ -71,18 +71,22 @@ private predicate completionIsValidForStmt(AstNode n, Completion c) {
|
||||
c = TReturnCompletion()
|
||||
}
|
||||
|
||||
private AstNode getARescuableBodyChild() {
|
||||
exists(Trees::BodyStmtTree bst | result = bst.getBodyChild(_, true) |
|
||||
exists(bst.getARescue())
|
||||
or
|
||||
exists(bst.getEnsure())
|
||||
)
|
||||
or
|
||||
result = getARescuableBodyChild().getAChild()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `c` happens in an exception-aware context, that is, it may be
|
||||
* `rescue`d or `ensure`d. In such cases, we assume that the target of `c`
|
||||
* may raise an exception (in addition to evaluating normally).
|
||||
*/
|
||||
private predicate mayRaise(Call c) {
|
||||
exists(Trees::BodyStmtTree bst | c = bst.getBodyChild(_, true).getAChild*() |
|
||||
exists(bst.getARescue())
|
||||
or
|
||||
exists(bst.getEnsure())
|
||||
)
|
||||
}
|
||||
private predicate mayRaise(Call c) { c = getARescuableBodyChild() }
|
||||
|
||||
/** A completion of a statement or an expression. */
|
||||
abstract class Completion extends TCompletion {
|
||||
|
||||
Reference in New Issue
Block a user