Skip to content

Commit 9453835

Browse files
committed
C++: Avoid generating IR for a few cases where we will be synthesizing assertions.
1 parent 9718e00 commit 9453835

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import TranslatedElement
1010
private import TranslatedExpr
1111
private import TranslatedFunction
1212
private import TranslatedInitialization
13+
private import TranslatedAssertion
1314

1415
TranslatedStmt getTranslatedStmt(Stmt stmt) { result.getAst() = stmt }
1516

@@ -324,8 +325,16 @@ abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
324325

325326
class TranslatedEmptyStmt extends TranslatedStmt {
326327
TranslatedEmptyStmt() {
327-
stmt instanceof EmptyStmt or
328-
stmt instanceof LabelStmt or
328+
// An assertion macro invocation can expand to
329+
// an empty statement in release builds. In that case
330+
// we synthedsize the check that would have occured.
331+
// This is handled by `TranslatedAssertion.qll` and so
332+
// we exclude these statements here.
333+
not assertion(_, stmt) and
334+
stmt instanceof EmptyStmt
335+
or
336+
stmt instanceof LabelStmt
337+
or
329338
stmt instanceof SwitchCase
330339
}
331340

@@ -420,6 +429,15 @@ class TranslatedDeclStmt extends TranslatedStmt {
420429
class TranslatedExprStmt extends TranslatedStmt {
421430
override ExprStmt stmt;
422431

432+
TranslatedExprStmt() {
433+
// An assertion macro invocation typically expand to the
434+
// expression `((void)0)` in release builds. In that case
435+
// we synthedsize the check that would have occured.
436+
// This is handled by `TranslatedAssertion.qll` and so
437+
// we exclude these statements here.
438+
not assertion(_, stmt)
439+
}
440+
423441
TranslatedExpr getExpr() { result = getTranslatedExpr(stmt.getExpr().getFullyConverted()) }
424442

425443
override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getExpr() }

0 commit comments

Comments
 (0)