From a18f3b68593b1659ce66d0d02fb82104c68fac4c Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 9 Jan 2026 19:24:23 +0000 Subject: [PATCH] C++: Avoid generating IR for a few cases where we will be synthesizing assertions. --- .../raw/internal/TranslatedStmt.qll | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll index 9dccf7752aa..82f1fd49b52 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll @@ -10,6 +10,7 @@ private import TranslatedElement private import TranslatedExpr private import TranslatedFunction private import TranslatedInitialization +private import TranslatedAssertion TranslatedStmt getTranslatedStmt(Stmt stmt) { result.getAst() = stmt } @@ -324,8 +325,16 @@ abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt { class TranslatedEmptyStmt extends TranslatedStmt { TranslatedEmptyStmt() { - stmt instanceof EmptyStmt or - stmt instanceof LabelStmt or + // An assertion macro invocation can expand to + // an empty statement in release builds. In that case + // we synthedsize the check that would have occured. + // This is handled by `TranslatedAssertion.qll` and so + // we exclude these statements here. + not assertion(_, stmt) and + stmt instanceof EmptyStmt + or + stmt instanceof LabelStmt + or stmt instanceof SwitchCase } @@ -420,6 +429,15 @@ class TranslatedDeclStmt extends TranslatedStmt { class TranslatedExprStmt extends TranslatedStmt { override ExprStmt stmt; + TranslatedExprStmt() { + // An assertion macro invocation typically expand to the + // expression `((void)0)` in release builds. In that case + // we synthedsize the check that would have occured. + // This is handled by `TranslatedAssertion.qll` and so + // we exclude these statements here. + not assertion(_, stmt) + } + TranslatedExpr getExpr() { result = getTranslatedExpr(stmt.getExpr().getFullyConverted()) } override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getExpr() }