Skip to content

Commit 8087cb5

Browse files
author
Robert Marsh
committed
C++: add CopyValueInstruction for StmtExpr result
1 parent 46f93ff commit 8087cb5

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,20 +2746,32 @@ class TranslatedStmtExpr extends TranslatedNonConstantExpr {
27462746
}
27472747

27482748
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
2749-
none()
2749+
tag instanceof OnlyInstructionTag and
2750+
kind instanceof GotoEdge and
2751+
result = getParent().getChildSuccessor(this)
27502752
}
27512753

27522754
override Instruction getChildSuccessor(TranslatedElement child) {
27532755
child = getStmt() and
2754-
result = getParent().getChildSuccessor(this)
2756+
result = getInstruction(OnlyInstructionTag())
27552757
}
27562758

27572759
override predicate hasInstruction(Opcode opcode, InstructionTag tag, Type resultType,
27582760
boolean isGLValue) {
2759-
none()
2761+
opcode instanceof Opcode::CopyValue and
2762+
tag instanceof OnlyInstructionTag and
2763+
resultType = expr.getType() and
2764+
isGLValue = false
27602765
}
27612766

27622767
override Instruction getResult() {
2768+
result = getInstruction(OnlyInstructionTag())
2769+
}
2770+
2771+
override Instruction getInstructionOperand(InstructionTag tag,
2772+
OperandTag operandTag) {
2773+
tag instanceof OnlyInstructionTag and
2774+
operandTag instanceof UnaryOperandTag and
27632775
result = getTranslatedExpr(expr.getResultExpr().getFullyConverted()).getResult()
27642776
}
27652777

cpp/ql/test/library-tests/dataflow/dataflow-tests/test_diff.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
| test.cpp:477:20:477:24 | test.cpp:478:8:478:12 | AST only |
1717
| test.cpp:484:18:484:23 | test.cpp:485:8:485:12 | AST only |
1818
| test.cpp:490:18:490:22 | test.cpp:491:8:491:12 | AST only |
19-
| test.cpp:497:26:497:32 | test.cpp:498:9:498:22 | AST only |
20-
| test.cpp:497:26:497:32 | test.cpp:509:8:509:12 | AST only |
2119
| true_upon_entry.cpp:9:11:9:16 | true_upon_entry.cpp:13:8:13:8 | IR only |
2220
| true_upon_entry.cpp:62:11:62:16 | true_upon_entry.cpp:66:8:66:8 | IR only |
2321
| true_upon_entry.cpp:98:11:98:16 | true_upon_entry.cpp:105:8:105:8 | IR only |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test_ir.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
| test.cpp:314:12:314:12 | Load: x | test.cpp:313:22:313:27 | Call: call to source |
2828
| test.cpp:337:14:337:14 | Load: x | test.cpp:353:17:353:22 | Call: call to source |
2929
| test.cpp:366:7:366:7 | Load: x | test.cpp:362:4:362:9 | Call: call to source |
30+
| test.cpp:498:9:498:22 | CopyValue: (statement expression) | test.cpp:497:26:497:32 | InitializeParameter: source1 |
31+
| test.cpp:509:8:509:12 | Load: local | test.cpp:497:26:497:32 | InitializeParameter: source1 |
3032
| true_upon_entry.cpp:13:8:13:8 | Load: x | true_upon_entry.cpp:9:11:9:16 | Call: call to source |
3133
| true_upon_entry.cpp:21:8:21:8 | Load: x | true_upon_entry.cpp:17:11:17:16 | Call: call to source |
3234
| true_upon_entry.cpp:29:8:29:8 | Load: x | true_upon_entry.cpp:27:9:27:14 | Call: call to source |

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,15 +4406,17 @@ ir.cpp:
44064406
# 999| Block 3
44074407
# 999| r3_0(glval<int>) = VariableAddress[w] :
44084408
# 999| r3_1(int) = Load : r3_0, mu0_2
4409-
# 992| mu3_2(int) = Store : r0_9, r3_1
4410-
# 1002| r3_3(glval<int>) = VariableAddress[#return] :
4411-
# 1002| r3_4(glval<int>) = VariableAddress[x] :
4412-
# 1002| r3_5(int) = Load : r3_4, mu0_2
4413-
# 1002| mu3_6(int) = Store : r3_3, r3_5
4414-
# 991| r3_7(glval<int>) = VariableAddress[#return] :
4415-
# 991| v3_8(void) = ReturnValue : r3_7, mu0_2
4416-
# 991| v3_9(void) = UnmodeledUse : mu*
4417-
# 991| v3_10(void) = ExitFunction :
4409+
# 992| r3_2(int) = CopyValue : r3_1
4410+
# 992| mu3_3(int) = Store : r0_9, r3_2
4411+
# 1002| r3_4(glval<int>) = VariableAddress[#return] :
4412+
# 1002| r3_5(glval<int>) = VariableAddress[x] :
4413+
# 1002| r3_6(int) = Load : r3_5, mu0_2
4414+
# 1002| r3_7(int) = CopyValue : r3_6
4415+
# 1002| mu3_8(int) = Store : r3_4, r3_7
4416+
# 991| r3_9(glval<int>) = VariableAddress[#return] :
4417+
# 991| v3_10(void) = ReturnValue : r3_9, mu0_2
4418+
# 991| v3_11(void) = UnmodeledUse : mu*
4419+
# 991| v3_12(void) = ExitFunction :
44184420

44194421
# 1025| void EmptyStructInit()
44204422
# 1025| Block 0

0 commit comments

Comments
 (0)