Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6cea1b

Browse files
author
Robert Marsh
committed
C++: Add class and predicates to other IR stages
1 parent b5cd48d commit d6cea1b

2 files changed

Lines changed: 124 additions & 8 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,28 +967,86 @@ class CompareNEInstruction extends CompareInstruction {
967967
}
968968
}
969969

970-
class CompareLTInstruction extends CompareInstruction {
970+
class RelationalInstruction extends CompareInstruction {
971+
RelationalInstruction() {
972+
opcode instanceof RelationalOpcode
973+
}
974+
975+
abstract Instruction getGreaterOperand();
976+
abstract Instruction getLesserOperand();
977+
abstract predicate isStrict();
978+
}
979+
980+
class CompareLTInstruction extends RelationalInstruction {
971981
CompareLTInstruction() {
972982
opcode instanceof Opcode::CompareLT
973983
}
984+
985+
override Instruction getLesserOperand() {
986+
result = getLeftOperand()
987+
}
988+
989+
override Instruction getGreaterOperand() {
990+
result = getRightOperand()
991+
}
992+
993+
override predicate isStrict() {
994+
any()
995+
}
974996
}
975997

976-
class CompareGTInstruction extends CompareInstruction {
998+
class CompareGTInstruction extends RelationalInstruction {
977999
CompareGTInstruction() {
9781000
opcode instanceof Opcode::CompareGT
9791001
}
1002+
1003+
override Instruction getLesserOperand() {
1004+
result = getRightOperand()
1005+
}
1006+
1007+
override Instruction getGreaterOperand() {
1008+
result = getLeftOperand()
1009+
}
1010+
1011+
override predicate isStrict() {
1012+
any()
1013+
}
9801014
}
9811015

982-
class CompareLEInstruction extends CompareInstruction {
1016+
class CompareLEInstruction extends RelationalInstruction {
9831017
CompareLEInstruction() {
9841018
opcode instanceof Opcode::CompareLE
9851019
}
1020+
1021+
override Instruction getLesserOperand() {
1022+
result = getLeftOperand()
1023+
}
1024+
1025+
override Instruction getGreaterOperand() {
1026+
result = getRightOperand()
1027+
}
1028+
1029+
override predicate isStrict() {
1030+
none()
1031+
}
9861032
}
9871033

988-
class CompareGEInstruction extends CompareInstruction {
1034+
class CompareGEInstruction extends RelationalInstruction {
9891035
CompareGEInstruction() {
9901036
opcode instanceof Opcode::CompareGE
9911037
}
1038+
1039+
override Instruction getLesserOperand() {
1040+
result = getRightOperand()
1041+
}
1042+
1043+
override Instruction getGreaterOperand() {
1044+
result = getLeftOperand()
1045+
}
1046+
1047+
override predicate isStrict() {
1048+
none()
1049+
}
9921050
}
9931051

9941052
class SwitchInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,28 +967,86 @@ class CompareNEInstruction extends CompareInstruction {
967967
}
968968
}
969969

970-
class CompareLTInstruction extends CompareInstruction {
970+
class RelationalInstruction extends CompareInstruction {
971+
RelationalInstruction() {
972+
opcode instanceof RelationalOpcode
973+
}
974+
975+
abstract Instruction getGreaterOperand();
976+
abstract Instruction getLesserOperand();
977+
abstract predicate isStrict();
978+
}
979+
980+
class CompareLTInstruction extends RelationalInstruction {
971981
CompareLTInstruction() {
972982
opcode instanceof Opcode::CompareLT
973983
}
984+
985+
override Instruction getLesserOperand() {
986+
result = getLeftOperand()
987+
}
988+
989+
override Instruction getGreaterOperand() {
990+
result = getRightOperand()
991+
}
992+
993+
override predicate isStrict() {
994+
any()
995+
}
974996
}
975997

976-
class CompareGTInstruction extends CompareInstruction {
998+
class CompareGTInstruction extends RelationalInstruction {
977999
CompareGTInstruction() {
9781000
opcode instanceof Opcode::CompareGT
9791001
}
1002+
1003+
override Instruction getLesserOperand() {
1004+
result = getRightOperand()
1005+
}
1006+
1007+
override Instruction getGreaterOperand() {
1008+
result = getLeftOperand()
1009+
}
1010+
1011+
override predicate isStrict() {
1012+
any()
1013+
}
9801014
}
9811015

982-
class CompareLEInstruction extends CompareInstruction {
1016+
class CompareLEInstruction extends RelationalInstruction {
9831017
CompareLEInstruction() {
9841018
opcode instanceof Opcode::CompareLE
9851019
}
1020+
1021+
override Instruction getLesserOperand() {
1022+
result = getLeftOperand()
1023+
}
1024+
1025+
override Instruction getGreaterOperand() {
1026+
result = getRightOperand()
1027+
}
1028+
1029+
override predicate isStrict() {
1030+
none()
1031+
}
9861032
}
9871033

988-
class CompareGEInstruction extends CompareInstruction {
1034+
class CompareGEInstruction extends RelationalInstruction {
9891035
CompareGEInstruction() {
9901036
opcode instanceof Opcode::CompareGE
9911037
}
1038+
1039+
override Instruction getLesserOperand() {
1040+
result = getRightOperand()
1041+
}
1042+
1043+
override Instruction getGreaterOperand() {
1044+
result = getLeftOperand()
1045+
}
1046+
1047+
override predicate isStrict() {
1048+
none()
1049+
}
9921050
}
9931051

9941052
class SwitchInstruction extends Instruction {

0 commit comments

Comments
 (0)