From 29fcbe3c8f68dc77fd5fd2b754c9c3e9569d770d Mon Sep 17 00:00:00 2001 From: Alex Eyers-Taylor Date: Fri, 4 Apr 2025 15:48:13 +0100 Subject: [PATCH] Swift extract predicates to improve TTE to avoid loop invariant code. --- .../controlflow/internal/ControlFlowGraphImpl.qll | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll b/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll index 3d2b33e8890..aa50c552e4b 100644 --- a/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll +++ b/swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll @@ -186,9 +186,17 @@ module Stmts { ) } + private Element getLastElement() { + result = ast.getLastElement() + } + + private Element getAnElement() { + result = ast.getAnElement() + } + predicate lastInner(ControlFlowElement last, Completion c) { // Normal exit and no defer statements - astLast(ast.getLastElement().getFullyUnresolved(), last, c) and + astLast(this.getLastElement().getFullyUnresolved(), last, c) and not exists(this.getFirstDeferStmtBody()) and c instanceof NormalCompletion or @@ -198,7 +206,7 @@ module Stmts { or // Abnormal exit without any defer statements not c instanceof NormalCompletion and - astLast(ast.getAnElement().getFullyUnresolved(), last, c) and + astLast(this.getAnElement().getFullyUnresolved(), last, c) and not exists(this.getFirstDeferStmtBody()) }