Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ private import TranslatedDeclarationEntry
private import TranslatedElement
private import TranslatedFunction
private import TranslatedInitialization
private import TranslatedFunction
private import TranslatedStmt
import TranslatedCall

/**
Expand Down Expand Up @@ -2727,3 +2729,53 @@ class TranslatedLambdaExpr extends TranslatedNonConstantExpr, InitializationCont
result = getTranslatedInitialization(expr.getChild(0).getFullyConverted())
}
}

/**
* The IR translation of `StmtExpr` (the GNU statement expression extension to C/C++), such as
* ``` ({ doSomething(); a + b; })```
*/
class TranslatedStmtExpr extends TranslatedNonConstantExpr {
Comment thread
dave-bartolomeo marked this conversation as resolved.
override StmtExpr expr;

override final Instruction getFirstInstruction() {
result = getStmt().getFirstInstruction()
}

override final TranslatedElement getChild(int id) {
id = 0 and result = getStmt()
}

override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
tag instanceof OnlyInstructionTag and
kind instanceof GotoEdge and
result = getParent().getChildSuccessor(this)
}

override Instruction getChildSuccessor(TranslatedElement child) {
child = getStmt() and
result = getInstruction(OnlyInstructionTag())
}

override predicate hasInstruction(Opcode opcode, InstructionTag tag, Type resultType,
boolean isGLValue) {
opcode instanceof Opcode::CopyValue and
tag instanceof OnlyInstructionTag and
resultType = expr.getType() and
isGLValue = false
}

override Instruction getResult() {
result = getInstruction(OnlyInstructionTag())
}

override Instruction getInstructionOperand(InstructionTag tag,
OperandTag operandTag) {
tag instanceof OnlyInstructionTag and
operandTag instanceof UnaryOperandTag and
result = getTranslatedExpr(expr.getResultExpr().getFullyConverted()).getResult()
}

TranslatedStmt getStmt() {
result = getTranslatedStmt(expr.getStmt())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
| test.cpp:477:20:477:24 | test.cpp:478:8:478:12 | AST only |
| test.cpp:484:18:484:23 | test.cpp:485:8:485:12 | AST only |
| test.cpp:490:18:490:22 | test.cpp:491:8:491:12 | AST only |
| test.cpp:497:26:497:32 | test.cpp:498:9:498:22 | AST only |
| test.cpp:497:26:497:32 | test.cpp:509:8:509:12 | AST only |
| true_upon_entry.cpp:9:11:9:16 | true_upon_entry.cpp:13:8:13:8 | IR only |
| true_upon_entry.cpp:62:11:62:16 | true_upon_entry.cpp:66:8:66:8 | IR only |
| true_upon_entry.cpp:98:11:98:16 | true_upon_entry.cpp:105:8:105:8 | IR only |
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
| test.cpp:314:12:314:12 | Load: x | test.cpp:313:22:313:27 | Call: call to source |
| test.cpp:337:14:337:14 | Load: x | test.cpp:353:17:353:22 | Call: call to source |
| test.cpp:366:7:366:7 | Load: x | test.cpp:362:4:362:9 | Call: call to source |
| test.cpp:498:9:498:22 | CopyValue: (statement expression) | test.cpp:497:26:497:32 | InitializeParameter: source1 |
| test.cpp:509:8:509:12 | Load: local | test.cpp:497:26:497:32 | InitializeParameter: source1 |
| true_upon_entry.cpp:13:8:13:8 | Load: x | true_upon_entry.cpp:9:11:9:16 | Call: call to source |
| true_upon_entry.cpp:21:8:21:8 | Load: x | true_upon_entry.cpp:17:11:17:16 | Call: call to source |
| true_upon_entry.cpp:29:8:29:8 | Load: x | true_upon_entry.cpp:27:9:27:14 | Call: call to source |
Expand Down
Loading