Skip to content

Commit e87bf57

Browse files
committed
Avoid recursion in IPA construction
1 parent bd6fe41 commit e87bf57

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

ql/src/codeql_ruby/ast/internal/AST.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ private module Cached {
119119
THashSplatArgument(Generated::HashSplatArgument g) or
120120
THashSplatParameter(Generated::HashSplatParameter g) or
121121
THereDoc(Generated::HeredocBeginning g) or
122-
TIdentifierMethodCall(Generated::Identifier g) { vcall(g) and not access(g, _) } or
122+
TIdentifierMethodCall(Generated::Identifier g) { isIdentifierMethodCall(g) } or
123123
TIf(Generated::If g) or
124124
TIfModifierExpr(Generated::IfModifier g) or
125125
TImplicitSelf(Generated::AstNode g) {
126-
exists(TIdentifierMethodCall(g))
126+
isIdentifierMethodCall(g)
127127
or
128-
exists(TRegularMethodCall(g)) and
128+
isRegularMethodCall(g) and
129129
not exists(g.(Generated::Call).getReceiver()) and
130130
not exists(g.(Generated::Call).getMethod().(Generated::ScopeResolution).getScope())
131131
} or
@@ -165,7 +165,7 @@ private module Cached {
165165
TRegexLiteral(Generated::Regex g) or
166166
TRegexMatchExpr(Generated::Binary g) { g instanceof @binary_equaltilde } or
167167
TRegularArrayLiteral(Generated::Array g) or
168-
TRegularMethodCall(Generated::Call g) { not g.getMethod() instanceof Generated::Super } or
168+
TRegularMethodCall(Generated::Call g) { isRegularMethodCall(g) } or
169169
TRegularStringLiteral(Generated::String g) or
170170
TRegularSuperCall(Generated::Call g) { g.getMethod() instanceof Generated::Super } or
171171
TRescueClause(Generated::Rescue g) or
@@ -230,6 +230,14 @@ private module Cached {
230230
TWhileModifierExpr(Generated::WhileModifier g) or
231231
TYieldCall(Generated::Yield g)
232232

233+
private predicate isIdentifierMethodCall(Generated::Identifier g) {
234+
vcall(g) and not access(g, _)
235+
}
236+
237+
private predicate isRegularMethodCall(Generated::Call g) {
238+
not g.getMethod() instanceof Generated::Super
239+
}
240+
233241
/**
234242
* Gets the underlying TreeSitter entity for a given AST node. This does not
235243
* include synthesized AST nodes, because they are not the primary AST node

ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,18 @@ break_ensure.rb:
262262
#-----| true -> [ensure: return] then ...
263263
#-----| false -> [ensure: return] if ...
264264

265-
# 35| call to x
266-
#-----| -> 0
267-
268-
# 35| [ensure: return] call to x
269-
#-----| -> [ensure: return] 0
270-
271265
# 35| self
272266
#-----| -> call to x
273267

274268
# 35| [ensure: return] self
275269
#-----| -> [ensure: return] call to x
276270

271+
# 35| call to x
272+
#-----| -> 0
273+
274+
# 35| [ensure: return] call to x
275+
#-----| -> [ensure: return] 0
276+
277277
# 35| 0
278278
#-----| -> ... > ...
279279

@@ -429,12 +429,12 @@ case.rb:
429429
# 2| case ...
430430
#-----| -> self
431431

432-
# 2| call to x1
433-
#-----| -> when ...
434-
435432
# 2| self
436433
#-----| -> call to x1
437434

435+
# 2| call to x1
436+
#-----| -> when ...
437+
438438
# 3| when ...
439439
#-----| -> 1
440440

@@ -451,13 +451,13 @@ case.rb:
451451
# 3| if ...
452452
#-----| -> ( ... )
453453

454+
# 3| self
455+
#-----| -> call to x2
456+
454457
# 3| call to x2
455458
#-----| true -> then ...
456459
#-----| false -> if ...
457460

458-
# 3| self
459-
#-----| -> call to x2
460-
461461
# 3| then ...
462462
#-----| -> self
463463

@@ -881,12 +881,12 @@ cfg.rb:
881881
#-----| true -> "hello"
882882
#-----| false -> "bye"
883883

884-
# 60| call to b
885-
#-----| -> 10
886-
887884
# 60| self
888885
#-----| -> call to b
889886

887+
# 60| call to b
888+
#-----| -> 10
889+
890890
# 60| 10
891891
#-----| -> ... < ...
892892

@@ -1330,21 +1330,21 @@ cfg.rb:
13301330
# 109| #{...}
13311331
#-----| -> self
13321332

1333-
# 109| call to table
1334-
#-----| -> #{...}
1335-
13361333
# 109| self
13371334
#-----| -> call to table
13381335

1336+
# 109| call to table
1337+
#-----| -> #{...}
1338+
13391339
# 110| #{...}
13401340
#-----| -> ( ... )
13411341

1342-
# 110| call to type
1343-
#-----| -> #{...}
1344-
13451342
# 110| self
13461343
#-----| -> call to type
13471344

1345+
# 110| call to type
1346+
#-----| -> #{...}
1347+
13481348
# 113| call to puts
13491349
#-----| -> ... if ...
13501350

@@ -1730,12 +1730,12 @@ cfg.rb:
17301730
# 160| #{...}
17311731
#-----| -> `cat "#{...}"`
17321732

1733-
# 160| call to __FILE__
1734-
#-----| -> #{...}
1735-
17361733
# 160| self
17371734
#-----| -> call to __FILE__
17381735

1736+
# 160| call to __FILE__
1737+
#-----| -> #{...}
1738+
17391739
# 162| ... = ...
17401740
#-----| -> delimited_symbol
17411741

0 commit comments

Comments
 (0)