Skip to content

Commit ba99d49

Browse files
authored
Merge pull request #16187 from MathiasVP/cfg-for-coroutines
C++: Placeholder CFG for coroutines
2 parents ea2cf27 + 477322d commit ba99d49

File tree

9 files changed

+979
-776
lines changed

9 files changed

+979
-776
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,9 @@ class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
12591259
expr instanceof NotExpr or
12601260
expr instanceof ComplementExpr or
12611261
expr instanceof UnaryPlusExpr or
1262-
expr instanceof UnaryMinusExpr
1262+
expr instanceof UnaryMinusExpr or
1263+
expr instanceof CoAwaitExpr or
1264+
expr instanceof CoYieldExpr
12631265
}
12641266

12651267
final override Instruction getFirstInstruction(EdgeKind kind) {
@@ -1299,6 +1301,12 @@ class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
12991301
expr instanceof UnaryPlusExpr and result instanceof Opcode::CopyValue
13001302
or
13011303
expr instanceof UnaryMinusExpr and result instanceof Opcode::Negate
1304+
or
1305+
// TODO: Use a new opcode to represent "awaiting the value"
1306+
expr instanceof CoAwaitExpr and result instanceof Opcode::CopyValue
1307+
or
1308+
// TODO: Use a new opcode to represent "awaiting the value"
1309+
expr instanceof CoYieldExpr and result instanceof Opcode::CopyValue
13021310
}
13031311

13041312
private TranslatedExpr getOperand() {

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,3 +1501,41 @@ class TranslatedVlaDeclarationStmt extends TranslatedStmt {
15011501

15021502
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) { none() }
15031503
}
1504+
1505+
class TranslatedCoReturnStmt extends TranslatedStmt {
1506+
override CoReturnStmt stmt;
1507+
1508+
private TranslatedExpr getTranslatedOperand() {
1509+
result = getTranslatedExpr(stmt.getOperand().getFullyConverted())
1510+
}
1511+
1512+
override TranslatedExpr getChildInternal(int id) {
1513+
id = 0 and
1514+
result = this.getTranslatedOperand()
1515+
}
1516+
1517+
override Instruction getFirstInstruction(EdgeKind kind) {
1518+
result = this.getTranslatedOperand().getFirstInstruction(kind)
1519+
}
1520+
1521+
override Instruction getALastInstructionInternal() {
1522+
result = this.getInstruction(OnlyInstructionTag())
1523+
}
1524+
1525+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
1526+
tag = OnlyInstructionTag() and
1527+
opcode instanceof Opcode::NoOp and
1528+
resultType = getVoidType()
1529+
}
1530+
1531+
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) {
1532+
tag = OnlyInstructionTag() and
1533+
result = this.getParent().getChildSuccessor(this, kind)
1534+
}
1535+
1536+
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
1537+
child = this.getTranslatedOperand() and
1538+
kind instanceof GotoEdge and
1539+
result = this.getInstruction(OnlyInstructionTag())
1540+
}
1541+
}

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

Lines changed: 265 additions & 12 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| coroutines.cpp:87:20:87:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:87:20:87:33 | co_returnable_void co_return_void() | co_returnable_void co_return_void() |
10-
| coroutines.cpp:91:21:91:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:91:21:91:33 | co_returnable_value co_return_int(int) | co_returnable_value co_return_int(int) |
11-
| coroutines.cpp:95:20:95:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:95:20:95:38 | co_returnable_void co_yield_value_void(int) | co_returnable_void co_yield_value_void(int) |
12-
| coroutines.cpp:99:21:99:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:99:21:99:40 | co_returnable_value co_yield_value_value(int) | co_returnable_value co_yield_value_value(int) |
13-
| coroutines.cpp:103:20:103:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:103:20:103:43 | co_returnable_void co_yield_and_return_void(int) | co_returnable_void co_yield_and_return_void(int) |
14-
| coroutines.cpp:108:21:108:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:108:21:108:45 | co_returnable_value co_yield_and_return_value(int) | co_returnable_value co_yield_and_return_value(int) |
159
ambiguousSuccessors
1610
unexplainedLoop
1711
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| coroutines.cpp:87:20:87:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:87:20:87:33 | co_returnable_void co_return_void() | co_returnable_void co_return_void() |
10-
| coroutines.cpp:91:21:91:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:91:21:91:33 | co_returnable_value co_return_int(int) | co_returnable_value co_return_int(int) |
11-
| coroutines.cpp:95:20:95:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:95:20:95:38 | co_returnable_void co_yield_value_void(int) | co_returnable_void co_yield_value_void(int) |
12-
| coroutines.cpp:99:21:99:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:99:21:99:40 | co_returnable_value co_yield_value_value(int) | co_returnable_value co_yield_value_value(int) |
13-
| coroutines.cpp:103:20:103:20 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:103:20:103:43 | co_returnable_void co_yield_and_return_void(int) | co_returnable_void co_yield_and_return_void(int) |
14-
| coroutines.cpp:108:21:108:21 | Uninitialized: declaration of (unnamed local variable) | Instruction 'Uninitialized: declaration of (unnamed local variable)' has no successors in function '$@'. | coroutines.cpp:108:21:108:45 | co_returnable_value co_yield_and_return_value(int) | co_returnable_value co_yield_and_return_value(int) |
159
ambiguousSuccessors
1610
unexplainedLoop
1711
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)