Skip to content

Commit 5036135

Browse files
committed
C++: Fix IR generation for the comma operator
1 parent 0fceece commit 5036135

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,12 @@ predicate ignoreLoad(Expr expr) {
361361
or
362362
expr instanceof FunctionAccess
363363
or
364+
// The load is duplicated from the operand.
364365
expr instanceof ParenthesisExpr
365366
or
367+
// The load is duplicated from the right operand.
368+
expr instanceof CommaExpr
369+
or
366370
expr.(PointerDereferenceExpr).getOperand().getFullyConverted().getType().getUnspecifiedType()
367371
instanceof FunctionPointerType
368372
or

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15504,7 +15504,7 @@ ir.cpp:
1550415504
# 2028| ValueCategory = lvalue
1550515505
# 2028| getRValue(): [ConditionalExpr] ... ? ... : ...
1550615506
# 2028| Type = [IntType] unsigned int
15507-
# 2028| ValueCategory = prvalue
15507+
# 2028| ValueCategory = prvalue(load)
1550815508
# 2028| getCondition(): [LTExpr] ... < ...
1550915509
# 2028| Type = [BoolType] bool
1551015510
# 2028| ValueCategory = prvalue
@@ -15522,7 +15522,7 @@ ir.cpp:
1552215522
# 2028| ValueCategory = prvalue
1552315523
# 2029| getThen(): [CommaExpr] ... , ...
1552415524
# 2029| Type = [IntType] unsigned int
15525-
# 2029| ValueCategory = prvalue
15525+
# 2029| ValueCategory = prvalue(load)
1552615526
# 2029| getLeftOperand(): [FunctionCall] call to CommaTestHelper
1552715527
# 2029| Type = [VoidType] void
1552815528
# 2029| ValueCategory = prvalue
@@ -15547,7 +15547,7 @@ ir.cpp:
1554715547
# 2030| ValueCategory = prvalue
1554815548
# 2029| getThen().getFullyConverted(): [ParenthesisExpr] (...)
1554915549
# 2029| Type = [IntType] unsigned int
15550-
# 2029| ValueCategory = prvalue
15550+
# 2029| ValueCategory = prvalue(load)
1555115551
# 2030| getElse().getFullyConverted(): [CStyleCast] (unsigned int)...
1555215552
# 2030| Conversion = [IntegralConversion] integral conversion
1555315553
# 2030| Type = [IntType] unsigned int

0 commit comments

Comments
 (0)