From f2425ad6fe898fb04ffe258c8c5312521336818f Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Fri, 22 Dec 2023 11:43:53 +0100 Subject: [PATCH] Use database extensionals instead of their wrapper classes in two predicates We are planning to change the charpred of `Function` in the CodeQL C++ library, which means the code changed here will no longer compile. By switching to the extensionals, the code will keep compiling. DIL before: ``` noinline `ConstantExprs::isFunction/1#600714be`( /* Element::Element */ interned unique entity el ) { exists(interned dontcare string _, interned dontcare int _1 | functions(el, _, _1) ) or exists(interned dontcare int _ | exprparents(el, _, el)) } noopt `ConstantExprs::callHasNoTarget/1#e6e8caa4`( /* @funbindexpr */ interned unique entity fc ) { exists(/* Function::Function */ interned entity f | funbind(fc, f) and not(`ConstantExprs::isFunction/1#600714be`(f)) ) } ``` DIL after: ``` noinline `ConstantExprs::isFunction/1#600714be`(/* @element */ interned unique entity el) { exists(interned dontcare string _, interned dontcare int _1 | functions(el, _, _1) ) or exists(interned dontcare int _ | exprparents(el, _, el)) } noopt `ConstantExprs::callHasNoTarget/1#e6e8caa4`( /* @funbindexpr */ interned unique entity fc ) { exists(/* @function */ interned entity f | funbind(fc, f) and not(`ConstantExprs::isFunction/1#600714be`(f)) ) } ``` --- .../cpp/enhancements/ControlFlowGraphEnhancements.qll | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/enhancements/ControlFlowGraphEnhancements.qll b/cpp/common/src/codingstandards/cpp/enhancements/ControlFlowGraphEnhancements.qll index 74d7e8e1c1..9dac58377c 100644 --- a/cpp/common/src/codingstandards/cpp/enhancements/ControlFlowGraphEnhancements.qll +++ b/cpp/common/src/codingstandards/cpp/enhancements/ControlFlowGraphEnhancements.qll @@ -10,8 +10,8 @@ import cpp * should be in this relation. */ pragma[noinline] -private predicate isFunction(Element el) { - el instanceof Function +private predicate isFunction(@element el) { + el instanceof @function or el.(Expr).getParent() = el } @@ -22,7 +22,7 @@ private predicate isFunction(Element el) { */ pragma[noopt] private predicate callHasNoTarget(@funbindexpr fc) { - exists(Function f | + exists(@function f | funbind(fc, f) and not isFunction(f) )