mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
C++: Add getLastInstruction to IR generation
This commit is contained in:
@@ -47,6 +47,8 @@ abstract class TranslatedCall extends TranslatedExpr {
|
||||
else result = this.getFirstCallTargetInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getSideEffects().getLastInstruction() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = CallTag() and
|
||||
opcode instanceof Opcode::Call and
|
||||
@@ -246,6 +248,15 @@ abstract class TranslatedSideEffects extends TranslatedElement {
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if exists(this.getAChild())
|
||||
then result = this.getChild(max(int i | exists(this.getChild(i)))).getLastInstruction()
|
||||
else
|
||||
// If there are no side effects, the "last" instruction should be the parent call's last
|
||||
// instruction, so that implicit destructors can be inserted in the right place.
|
||||
result = this.getParent().getInstruction(CallTag())
|
||||
}
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) { none() }
|
||||
|
||||
/** Gets the primary instruction to be associated with each side effect instruction. */
|
||||
@@ -423,6 +434,8 @@ abstract class TranslatedSideEffect extends TranslatedElement {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType type) {
|
||||
tag = OnlyInstructionTag() and
|
||||
this.sideEffectInstruction(opcode, type)
|
||||
|
||||
@@ -56,6 +56,10 @@ abstract class TranslatedFlexibleCondition extends TranslatedCondition, Conditio
|
||||
result = this.getOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
final override Instruction getLastInstruction() {
|
||||
result = this.getOperand().getLastInstruction()
|
||||
}
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -104,6 +108,12 @@ abstract class TranslatedBinaryLogicalOperation extends TranslatedNativeConditio
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
final override Instruction getLastInstruction() {
|
||||
result = this.getLeftOperand().getLastInstruction()
|
||||
or
|
||||
result = this.getRightOperand().getLastInstruction()
|
||||
}
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -162,6 +172,10 @@ class TranslatedValueCondition extends TranslatedCondition, TTranslatedValueCond
|
||||
result = this.getValueExpr().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(ValueConditionConditionalBranchTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = ValueConditionConditionalBranchTag() and
|
||||
opcode instanceof Opcode::ConditionalBranch and
|
||||
|
||||
@@ -156,6 +156,12 @@ class TranslatedStaticLocalVariableDeclarationEntry extends TranslatedDeclaratio
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
final override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(DynamicInitializationConditionalBranchTag())
|
||||
or
|
||||
result = this.getInstruction(DynamicInitializationFlagStoreTag())
|
||||
}
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
tag = DynamicInitializationFlagAddressTag() and
|
||||
kind instanceof GotoEdge and
|
||||
|
||||
@@ -904,6 +904,8 @@ abstract class TranslatedElement extends TTranslatedElement {
|
||||
*/
|
||||
abstract Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind);
|
||||
|
||||
abstract Instruction getLastInstruction();
|
||||
|
||||
/**
|
||||
* Gets the successor instruction to which control should flow after the
|
||||
* child element specified by `child` has finished execution. The successor
|
||||
|
||||
@@ -196,6 +196,10 @@ class TranslatedConditionValue extends TranslatedCoreExpr, ConditionContext,
|
||||
result = this.getCondition().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(ConditionValueResultLoadTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
(
|
||||
tag = ConditionValueTrueTempAddressTag() or
|
||||
@@ -370,6 +374,8 @@ class TranslatedLoad extends TranslatedValueCategoryAdjustment, TTranslatedLoad
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(LoadTag()) }
|
||||
|
||||
override Instruction getResult() { result = this.getInstruction(LoadTag()) }
|
||||
|
||||
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
@@ -416,6 +422,8 @@ class TranslatedSyntheticTemporaryObject extends TranslatedValueCategoryAdjustme
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(InitializerStoreTag()) }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getOperand() and
|
||||
result = this.getInstruction(InitializerVariableAddressTag()) and
|
||||
@@ -473,6 +481,8 @@ class TranslatedResultCopy extends TranslatedExpr, TTranslatedResultCopy {
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ResultCopyTag()) }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getOperand() and
|
||||
result = this.getInstruction(ResultCopyTag()) and
|
||||
@@ -499,6 +509,8 @@ class TranslatedCommaExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getRightOperand().getLastInstruction() }
|
||||
|
||||
override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getLeftOperand()
|
||||
or
|
||||
@@ -608,6 +620,8 @@ abstract class TranslatedCrementOperation extends TranslatedNonConstantExpr {
|
||||
result = this.getLoadedOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(CrementStoreTag()) }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
(
|
||||
@@ -711,6 +725,8 @@ class TranslatedArrayExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getBaseOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getBaseOperand()
|
||||
or
|
||||
@@ -769,6 +785,8 @@ abstract class TranslatedTransparentExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getOperand().getLastInstruction() }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getOperand()
|
||||
}
|
||||
@@ -847,6 +865,8 @@ class TranslatedThisExpr extends TranslatedNonConstantExpr {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ThisLoadTag()) }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
tag = ThisAddressTag() and
|
||||
@@ -908,6 +928,8 @@ class TranslatedNonFieldVariableAccess extends TranslatedVariableAccess {
|
||||
)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
none()
|
||||
}
|
||||
@@ -942,6 +964,8 @@ class TranslatedFieldAccess extends TranslatedVariableAccess {
|
||||
result = this.getQualifier().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
tag = OnlyInstructionTag() and
|
||||
operandTag instanceof UnaryOperandTag and
|
||||
@@ -980,6 +1004,8 @@ class TranslatedStructuredBindingVariableAccess extends TranslatedNonConstantExp
|
||||
result = this.getInstruction(StructuredBindingAccessTag())
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(LoadTag()) }
|
||||
|
||||
override TranslatedElement getChildInternal(int id) {
|
||||
// Structured bindings cannot be qualified.
|
||||
none()
|
||||
@@ -1044,6 +1070,8 @@ class TranslatedFunctionAccess extends TranslatedNonConstantExpr {
|
||||
)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -1095,6 +1123,8 @@ abstract class TranslatedConstantExpr extends TranslatedCoreExpr, TTranslatedVal
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { none() }
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
@@ -1172,6 +1202,8 @@ class TranslatedUnaryExpr extends TranslatedSingleInstructionExpr {
|
||||
result = this.getOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getOperand()
|
||||
}
|
||||
@@ -1232,6 +1264,8 @@ abstract class TranslatedSingleInstructionConversion extends TranslatedConversio
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getOperand() and
|
||||
result = this.getInstruction(OnlyInstructionTag()) and
|
||||
@@ -1329,6 +1363,10 @@ class TranslatedInheritanceConversion extends TranslatedSingleInstructionConvers
|
||||
class TranslatedBoolConversion extends TranslatedConversion {
|
||||
override BoolConversion expr;
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(BoolConversionCompareTag())
|
||||
}
|
||||
|
||||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
tag = BoolConversionConstantTag() and
|
||||
@@ -1454,6 +1492,8 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getLeftOperand()
|
||||
or
|
||||
@@ -1551,6 +1591,8 @@ class TranslatedAssignExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getRightOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AssignmentStoreTag()) }
|
||||
|
||||
final override Instruction getResult() {
|
||||
// The following distinction is needed to work around extractor limitations
|
||||
// in old versions of the extractor.
|
||||
@@ -1625,6 +1667,8 @@ class TranslatedBlockAssignExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getLeftOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AssignmentStoreTag()) }
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(AssignmentStoreTag()) }
|
||||
|
||||
final TranslatedExpr getLeftOperand() {
|
||||
@@ -1694,6 +1738,8 @@ class TranslatedAssignOperation extends TranslatedNonConstantExpr {
|
||||
result = this.getRightOperand().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AssignmentStoreTag()) }
|
||||
|
||||
final override Instruction getResult() {
|
||||
// The following distinction is needed to work around extractor limitations
|
||||
// in old versions of the extractor.
|
||||
@@ -1922,6 +1968,8 @@ class TranslatedConstantAllocationSize extends TranslatedAllocationSize {
|
||||
result = this.getInstruction(AllocationSizeTag())
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AllocationSizeTag()) }
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = AllocationSizeTag() and
|
||||
opcode instanceof Opcode::Constant and
|
||||
@@ -1959,6 +2007,8 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
|
||||
result = this.getExtent().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AllocationSizeTag()) }
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
resultType = getTypeForPRValue(expr.getAllocator().getParameter(0).getType()) and
|
||||
(
|
||||
@@ -2216,6 +2266,8 @@ class TranslatedDestructorFieldDestruction extends TranslatedNonConstantExpr, St
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
tag = OnlyInstructionTag() and
|
||||
operandTag instanceof UnaryOperandTag and
|
||||
@@ -2240,6 +2292,15 @@ class TranslatedDestructorFieldDestruction extends TranslatedNonConstantExpr, St
|
||||
abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
|
||||
override ConditionalExpr expr;
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if this.elseIsVoid()
|
||||
then result = this.getElse().getLastInstruction()
|
||||
else
|
||||
if exists(this.getInstruction(ConditionValueResultLoadTag()))
|
||||
then result = this.getInstruction(ConditionValueResultLoadTag())
|
||||
else result = this.getInstruction(ConditionValueResultTempAddressTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
// Note that the ternary flavor needs no explicit `ConditionalBranch` instruction here, because
|
||||
// the condition is a `TranslatedCondition`, which will simply connect the successor edges of
|
||||
@@ -2697,6 +2758,8 @@ class TranslatedReThrowExpr extends TranslatedThrowExpr {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ThrowTag()) }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) { none() }
|
||||
|
||||
final override Opcode getThrowOpcode() { result instanceof Opcode::ReThrow }
|
||||
@@ -2728,6 +2791,8 @@ class TranslatedBuiltInOperation extends TranslatedNonConstantExpr {
|
||||
)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
result = getTranslatedExpr(expr.getChild(id).getFullyConverted())
|
||||
}
|
||||
@@ -2842,6 +2907,10 @@ class TranslatedVarArgsStart extends TranslatedNonConstantExpr {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(VarArgsVAListStoreTag())
|
||||
}
|
||||
|
||||
final override Instruction getResult() { none() }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getVAList() }
|
||||
@@ -2915,6 +2984,10 @@ class TranslatedVarArg extends TranslatedNonConstantExpr {
|
||||
result = this.getVAList().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(VarArgsVAListStoreTag())
|
||||
}
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(VarArgsArgAddressTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getVAList() }
|
||||
@@ -2987,6 +3060,8 @@ class TranslatedVarArgsEnd extends TranslatedNonConstantExpr {
|
||||
result = this.getVAList().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override Instruction getResult() { none() }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getVAList() }
|
||||
@@ -3033,6 +3108,10 @@ class TranslatedVarArgCopy extends TranslatedNonConstantExpr {
|
||||
result = this.getSourceVAList().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(VarArgsVAListStoreTag())
|
||||
}
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(VarArgsVAListStoreTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
@@ -3107,6 +3186,12 @@ abstract class TranslatedNewOrNewArrayExpr extends TranslatedNonConstantExpr, In
|
||||
result = this.getAllocatorCall().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if exists(this.getInitialization())
|
||||
then result = this.getInitialization().getLastInstruction()
|
||||
else result = this.getInstruction(OnlyInstructionTag())
|
||||
}
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -3181,6 +3266,8 @@ class TranslatedConditionDeclExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getDecl().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ThrowTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getDecl()
|
||||
or
|
||||
@@ -3221,6 +3308,8 @@ class TranslatedLambdaExpr extends TranslatedNonConstantExpr, InitializationCont
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(LoadTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getInitialization()
|
||||
}
|
||||
@@ -3314,6 +3403,8 @@ class TranslatedStmtExpr extends TranslatedNonConstantExpr {
|
||||
result = this.getStmt().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getStmt().getLastInstruction() }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { id = 0 and result = this.getStmt() }
|
||||
|
||||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -3352,6 +3443,8 @@ class TranslatedErrorExpr extends TranslatedSingleInstructionExpr {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { none() }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
@@ -3446,6 +3539,8 @@ class TranslatedAssumeExpr extends TranslatedSingleInstructionExpr {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override TranslatedElement getChildInternal(int id) { none() }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
|
||||
@@ -114,6 +114,9 @@ class TranslatedFunction extends TranslatedRootElement, TTranslatedFunction {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ExitFunctionTag()) }
|
||||
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
(
|
||||
@@ -379,6 +382,12 @@ abstract class TranslatedParameter extends TranslatedElement {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if this.hasIndirection()
|
||||
then result = this.getInstruction(InitializerIndirectStoreTag())
|
||||
else result = this.getInstruction(InitializerStoreTag())
|
||||
}
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
tag = InitializerVariableAddressTag() and
|
||||
@@ -611,6 +620,8 @@ class TranslatedConstructorInitList extends TranslatedElement, InitializationCon
|
||||
else result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getChild(max(int id | exists(this.getChild(id)))).getLastInstruction() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -677,6 +688,7 @@ class TranslatedDestructorDestructionList extends TranslatedElement,
|
||||
then result = this.getChild(0).getFirstInstruction(kind)
|
||||
else result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
override Instruction getLastInstruction() { result = this.getChild(max(int id | exists(this.getChild(id)))).getLastInstruction() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
@@ -728,6 +740,15 @@ class TranslatedReadEffects extends TranslatedElement, TTranslatedReadEffects {
|
||||
else result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if exists(this.getAChild())
|
||||
then
|
||||
result =
|
||||
max(TranslatedElement child, int id | child = this.getChild(id) | child order by id)
|
||||
.getFirstInstruction(any(GotoEdge goto))
|
||||
else result = this.getParent().getChildSuccessor(this, any(GotoEdge goto))
|
||||
}
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
exists(int id | child = this.getChild(id) |
|
||||
if exists(TranslatedReadEffect child2, int id2 | id2 > id and child2 = this.getChild(id2))
|
||||
@@ -772,6 +793,7 @@ abstract class TranslatedReadEffect extends TranslatedElement {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
opcode instanceof Opcode::ReturnIndirection and
|
||||
tag = OnlyInstructionTag() and
|
||||
|
||||
@@ -27,6 +27,8 @@ class TranslatedStaticStorageDurationVarInit extends TranslatedRootElement,
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ExitFunctionTag()) }
|
||||
|
||||
override TranslatedElement getChild(int n) {
|
||||
n = 1 and
|
||||
result = getTranslatedInitialization(var.getInitializer().getExpr().getFullyConverted())
|
||||
|
||||
@@ -42,6 +42,8 @@ abstract class TranslatedVariableInitialization extends TranslatedElement, Initi
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = InitializerVariableAddressTag() and
|
||||
opcode instanceof Opcode::VariableAddress and
|
||||
@@ -177,6 +179,8 @@ abstract class TranslatedListInitialization extends TranslatedInitialization, In
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(ThrowTag()) }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
exists(int index |
|
||||
child = this.getChild(index) and
|
||||
@@ -260,6 +264,8 @@ class TranslatedSimpleDirectInitialization extends TranslatedDirectInitializatio
|
||||
not expr instanceof StringLiteral
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(InitializerStoreTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = InitializerStoreTag() and
|
||||
opcode instanceof Opcode::Store and
|
||||
@@ -296,6 +302,12 @@ class TranslatedSimpleDirectInitialization extends TranslatedDirectInitializatio
|
||||
class TranslatedStringLiteralInitialization extends TranslatedDirectInitialization {
|
||||
override StringLiteral expr;
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if this.zeroInitRange(_, _)
|
||||
then result = this.getInstruction(ZeroPadStringStoreTag())
|
||||
else result = this.getInstruction(InitializerStoreTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
// Load the string literal to make it a prvalue of type `char[len]`
|
||||
tag = InitializerLoadStringTag() and
|
||||
@@ -457,6 +469,8 @@ class TranslatedConstructorInitialization extends TranslatedDirectInitialization
|
||||
{
|
||||
override ConstructorCall expr;
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInitializer().getLastInstruction() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -558,6 +572,10 @@ class TranslatedExplicitFieldInitialization extends TranslatedFieldInitializatio
|
||||
this = TTranslatedExplicitFieldInitialization(ast, field, expr, position)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInitialization().getLastInstruction()
|
||||
}
|
||||
|
||||
override Instruction getTargetAddress() {
|
||||
result = this.getInstruction(this.getFieldAddressTag())
|
||||
}
|
||||
@@ -595,6 +613,10 @@ class TranslatedFieldValueInitialization extends TranslatedFieldInitialization,
|
||||
{
|
||||
TranslatedFieldValueInitialization() { this = TTranslatedFieldValueInitialization(ast, field) }
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(this.getFieldDefaultValueStoreTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
TranslatedFieldInitialization.super.hasInstruction(opcode, tag, resultType)
|
||||
or
|
||||
@@ -743,6 +765,10 @@ class TranslatedExplicitElementInitialization extends TranslatedElementInitializ
|
||||
this = TTranslatedExplicitElementInitialization(initList, elementIndex, position)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(this.getElementAddressTag())
|
||||
}
|
||||
|
||||
override Instruction getTargetAddress() {
|
||||
result = this.getInstruction(this.getElementAddressTag())
|
||||
}
|
||||
@@ -788,6 +814,10 @@ class TranslatedElementValueInitialization extends TranslatedElementInitializati
|
||||
this = TTranslatedElementValueInitialization(initList, elementIndex, elementCount)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getInstruction(this.getElementDefaultValueStoreTag())
|
||||
}
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
TranslatedElementInitialization.super.hasInstruction(opcode, tag, resultType)
|
||||
or
|
||||
@@ -894,6 +924,8 @@ abstract class TranslatedBaseStructorCall extends TranslatedStructorCallFromStru
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getStructorCall().getLastInstruction() }
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode instanceof Opcode::ConvertToNonVirtualBase and
|
||||
@@ -947,6 +979,8 @@ class TranslatedConstructorDelegationInit extends TranslatedConstructorCallFromC
|
||||
result = this.getStructorCall().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getStructorCall().getLastInstruction() }
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -1009,6 +1043,8 @@ class TranslatedConstructorBareInit extends TranslatedElement, TTranslatedConstr
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { none() } // FIXME: does this need to be filled in?
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
|
||||
@@ -211,6 +211,12 @@ class TranslatedMicrosoftTryExceptHandler extends TranslatedElement,
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getTranslatedHandler().getLastInstruction()
|
||||
or
|
||||
result = this.getInstruction(UnwindTag())
|
||||
}
|
||||
|
||||
private TranslatedExpr getTranslatedCondition() {
|
||||
result = getTranslatedExpr(tryExcept.getCondition())
|
||||
}
|
||||
@@ -271,6 +277,8 @@ class TranslatedEmptyStmt extends TranslatedStmt {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode instanceof Opcode::NoOp and
|
||||
@@ -306,6 +314,10 @@ class TranslatedDeclStmt extends TranslatedStmt {
|
||||
result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getChild(this.getChildCount() - 1).getLastInstruction()
|
||||
}
|
||||
|
||||
private int getChildCount() { result = count(this.getDeclarationEntry(_)) }
|
||||
|
||||
IRDeclarationEntry getIRDeclarationEntry(int index) {
|
||||
@@ -357,6 +369,8 @@ class TranslatedExprStmt extends TranslatedStmt {
|
||||
result = this.getExpr().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getExpr().getLastInstruction() }
|
||||
|
||||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) { none() }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
@@ -415,6 +429,8 @@ class TranslatedReturnVoidExpressionStmt extends TranslatedReturnStmt {
|
||||
result = this.getExpr().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode instanceof Opcode::NoOp and
|
||||
@@ -451,6 +467,8 @@ class TranslatedReturnVoidStmt extends TranslatedReturnStmt {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode instanceof Opcode::NoOp and
|
||||
@@ -557,6 +575,8 @@ class TranslatedTryStmt extends TranslatedStmt {
|
||||
result = this.getBody().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getFinally().getLastInstruction() }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
// All non-finally children go to the successor of the `try` if
|
||||
// there is no finally block, but if there is a finally block
|
||||
@@ -616,6 +636,12 @@ class TranslatedBlock extends TranslatedStmt {
|
||||
else result = this.getStmt(0).getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
if this.isEmpty()
|
||||
then result = this.getInstruction(OnlyInstructionTag())
|
||||
else result = this.getStmt(this.getStmtCount() - 1).getFirstInstruction(any(GotoEdge goto))
|
||||
}
|
||||
|
||||
private predicate isEmpty() { not exists(stmt.getStmt(0)) }
|
||||
|
||||
private TranslatedStmt getStmt(int index) { result = getTranslatedStmt(stmt.getStmt(index)) }
|
||||
@@ -650,6 +676,8 @@ abstract class TranslatedHandler extends TranslatedStmt {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getBlock().getLastInstruction() }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getBlock() and result = this.getParent().getChildSuccessor(this, kind)
|
||||
}
|
||||
@@ -737,6 +765,10 @@ class TranslatedIfStmt extends TranslatedStmt, ConditionContext {
|
||||
else result = this.getFirstConditionInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getElse().getLastInstruction() or result = this.getThen().getLastInstruction() // FIXME: how do we handle the CFG merge here
|
||||
}
|
||||
|
||||
override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getInitialization()
|
||||
or
|
||||
@@ -797,6 +829,10 @@ class TranslatedIfStmt extends TranslatedStmt, ConditionContext {
|
||||
abstract class TranslatedLoop extends TranslatedStmt, ConditionContext {
|
||||
override Loop stmt;
|
||||
|
||||
override Instruction getLastInstruction() {
|
||||
result = this.getCondition().getLastInstruction() // FIXME: how do we handle the branch here
|
||||
}
|
||||
|
||||
final TranslatedCondition getCondition() {
|
||||
result = getTranslatedCondition(stmt.getCondition().getFullyConverted())
|
||||
}
|
||||
@@ -932,6 +968,8 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
|
||||
result = this.getRangeVariableDeclStmt().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getCondition().getLastInstruction() }
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getRangeVariableDeclStmt() and
|
||||
result = this.getBeginEndVariableDeclStmt().getFirstInstruction(kind)
|
||||
@@ -1007,6 +1045,8 @@ class TranslatedJumpStmt extends TranslatedStmt {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override TranslatedElement getChildInternal(int id) { none() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
@@ -1051,6 +1091,8 @@ class TranslatedSwitchStmt extends TranslatedStmt {
|
||||
else result = this.getFirstExprInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getBody().getLastInstruction() }
|
||||
|
||||
override TranslatedElement getChildInternal(int id) {
|
||||
id = 0 and result = this.getInitialization()
|
||||
or
|
||||
@@ -1118,6 +1160,8 @@ class TranslatedAsmStmt extends TranslatedStmt {
|
||||
)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(AsmTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = AsmTag() and
|
||||
opcode instanceof Opcode::InlineAsm and
|
||||
@@ -1169,6 +1213,8 @@ class TranslatedVlaDimensionStmt extends TranslatedStmt {
|
||||
result = this.getChild(0).getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getChild(0).getLastInstruction() }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
none()
|
||||
}
|
||||
@@ -1191,6 +1237,8 @@ class TranslatedVlaDeclarationStmt extends TranslatedStmt {
|
||||
kind instanceof GotoEdge
|
||||
}
|
||||
|
||||
override Instruction getLastInstruction() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
// TODO: This needs a new kind of instruction that represents initialization of a VLA.
|
||||
// For now we just emit a `NoOp` instruction so that the CFG isn't incomplete.
|
||||
|
||||
Reference in New Issue
Block a user