mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
Merge pull request #984 from rdmarsh2/rdmarsh/cpp/ir-stmtexpr
C++: add support for GNU StmtExpr in IR
This commit is contained in:
@@ -8,6 +8,8 @@ private import TranslatedDeclarationEntry
|
||||
private import TranslatedElement
|
||||
private import TranslatedFunction
|
||||
private import TranslatedInitialization
|
||||
private import TranslatedFunction
|
||||
private import TranslatedStmt
|
||||
import TranslatedCall
|
||||
|
||||
/**
|
||||
@@ -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 {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user