From edc7903c69280dbe2110f2f62b115dbaa1edb00a Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 7 Feb 2024 11:45:13 +0000 Subject: [PATCH] C++: Add a predicate for getting the 0'th child of a 'ConditionDeclExpr' without casting it to a 'VariableAccess' and use it in IR generation. --- cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll | 10 ++++++++-- .../ir/implementation/raw/internal/TranslatedExpr.qll | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll b/cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll index f30c9ec8d67..56ec87b23f2 100644 --- a/cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll +++ b/cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll @@ -244,9 +244,15 @@ class ConditionDeclExpr extends Expr, @condition_decl { /** * Gets the compiler-generated variable access that conceptually occurs after - * the initialization of the declared variable. + * the initialization of the declared variable, if any. */ - VariableAccess getVariableAccess() { result = this.getChild(0) } + VariableAccess getVariableAccess() { result = this.getExpr() } + + /** + * Gets the expression that is evaluated after the initialization of the declared + * variable. + */ + Expr getExpr() { result = this.getChild(0) } /** * Gets the expression that initializes the declared variable. This predicate diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll index 1e4b52283fc..4bf21a43f63 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll @@ -3173,7 +3173,7 @@ class TranslatedConditionDeclExpr extends TranslatedNonConstantExpr { private TranslatedConditionDecl getDecl() { result = getTranslatedConditionDecl(expr) } private TranslatedExpr getConditionExpr() { - result = getTranslatedExpr(expr.getVariableAccess().getFullyConverted()) + result = getTranslatedExpr(expr.getExpr().getFullyConverted()) } }