Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb30275

Browse files
committed
C++: Fix false negatives for postfix crement expressions
1 parent bcb4759 commit bb30275

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,9 +2469,6 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
24692469
expr instanceof PrefixCrementOperation and
24702470
not expr.isPRValueCategory() // is C++
24712471
or
2472-
// Because the load is on the `e` in `e++`.
2473-
expr instanceof PostfixCrementOperation
2474-
or
24752472
expr instanceof PointerDereferenceExpr
24762473
or
24772474
expr instanceof AddressOfExpr
@@ -2489,6 +2486,12 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
24892486
// TODO: simplify TranslatedStmtExpr too
24902487
) and
24912488
not exprImmediatelyDiscarded(expr)
2489+
or
2490+
// For certain expressions we want to keep the CopyValue instruction even though the result might
2491+
// not be needed, as we otherwise cannot get back the original expression. For now the only such
2492+
// expressions we have encountered are `e++` and `e--`.
2493+
// Because the load is on the `e` in `e++`.
2494+
expr instanceof PostfixCrementOperation
24922495
}
24932496

24942497
/**

0 commit comments

Comments
 (0)