Skip to content

Commit fb6e45b

Browse files
committed
C++: Emit a NoOp during CFG construction for VLAs.
1 parent d4746e0 commit fb6e45b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,49 @@ class TranslatedAsmStmt extends TranslatedStmt {
11051105
)
11061106
}
11071107
}
1108+
1109+
class TranslatedVlaDimensionStmt extends TranslatedStmt {
1110+
override VlaDimensionStmt stmt;
1111+
1112+
override TranslatedExpr getChild(int id) {
1113+
id = 0 and
1114+
result = getTranslatedExpr(stmt.getDimensionExpr().getFullyConverted())
1115+
}
1116+
1117+
override Instruction getFirstInstruction() { result = getChild(0).getFirstInstruction() }
1118+
1119+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
1120+
none()
1121+
}
1122+
1123+
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) { none() }
1124+
1125+
override Instruction getChildSuccessor(TranslatedElement child) {
1126+
child = getChild(0) and
1127+
result = getParent().getChildSuccessor(this)
1128+
}
1129+
}
1130+
1131+
class TranslatedVlaDeclarationStmt extends TranslatedStmt {
1132+
override VlaDeclStmt stmt;
1133+
1134+
override TranslatedExpr getChild(int id) { none() }
1135+
1136+
override Instruction getFirstInstruction() { result = getInstruction(OnlyInstructionTag()) }
1137+
1138+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
1139+
// TODO: This needs a new kind of instruction that represents initialization of a VLA.
1140+
// For now we just emit a `NoOp` instruction so that the CFG isn't incomplete.
1141+
tag = OnlyInstructionTag() and
1142+
opcode instanceof Opcode::NoOp and
1143+
resultType = getVoidType()
1144+
}
1145+
1146+
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
1147+
tag = OnlyInstructionTag() and
1148+
result = getParent().getChildSuccessor(this) and
1149+
kind instanceof GotoEdge
1150+
}
1151+
1152+
override Instruction getChildSuccessor(TranslatedElement child) { none() }
1153+
}

0 commit comments

Comments
 (0)