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

Skip to content

Commit 173ade1

Browse files
author
Robert Marsh
committed
C++: add arithmetic/bitwise instruction classes
1 parent 7649e87 commit 173ade1

4 files changed

Lines changed: 120 additions & 48 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ abstract class PointerArithmeticOpcode extends BinaryOpcode {}
8585

8686
abstract class PointerOffsetOpcode extends PointerArithmeticOpcode {}
8787

88+
abstract class ArithmeticOpcode extends Opcode {}
89+
90+
abstract class BinaryArithmeticOpcode extends BinaryOpcode, ArithmeticOpcode {}
91+
92+
abstract class UnaryArithmeticOpcode extends UnaryOpcode, ArithmeticOpcode {}
93+
94+
abstract class BitwiseOpcode extends Opcode {}
95+
96+
abstract class BinaryBitwiseOpcode extends BinaryOpcode, BitwiseOpcode {}
97+
98+
abstract class UnaryBitwiseOpcode extends UnaryOpcode, BitwiseOpcode {}
99+
88100
abstract class CompareOpcode extends BinaryOpcode {}
89101

90102
abstract class RelationalOpcode extends CompareOpcode {}
@@ -143,18 +155,18 @@ module Opcode {
143155
class CopyValue extends UnaryOpcode, CopyOpcode, TCopyValue { override final string toString() { result = "CopyValue" } }
144156
class Load extends CopyOpcode, OpcodeWithLoad, TLoad { override final string toString() { result = "Load" } }
145157
class Store extends CopyOpcode, MemoryAccessOpcode, TStore { override final string toString() { result = "Store" } }
146-
class Add extends BinaryOpcode, TAdd { override final string toString() { result = "Add" } }
147-
class Sub extends BinaryOpcode, TSub { override final string toString() { result = "Sub" } }
148-
class Mul extends BinaryOpcode, TMul { override final string toString() { result = "Mul" } }
149-
class Div extends BinaryOpcode, TDiv { override final string toString() { result = "Div" } }
150-
class Rem extends BinaryOpcode, TRem { override final string toString() { result = "Rem" } }
151-
class Negate extends UnaryOpcode, TNegate { override final string toString() { result = "Negate" } }
152-
class ShiftLeft extends BinaryOpcode, TShiftLeft { override final string toString() { result = "ShiftLeft" } }
153-
class ShiftRight extends BinaryOpcode, TShiftRight { override final string toString() { result = "ShiftRight" } }
154-
class BitAnd extends BinaryOpcode, TBitAnd { override final string toString() { result = "BitAnd" } }
155-
class BitOr extends BinaryOpcode, TBitOr { override final string toString() { result = "BitOr" } }
156-
class BitXor extends BinaryOpcode, TBitXor { override final string toString() { result = "BitXor" } }
157-
class BitComplement extends UnaryOpcode, TBitComplement { override final string toString() { result = "BitComplement" } }
158+
class Add extends BinaryArithmeticOpcode, TAdd { override final string toString() { result = "Add" } }
159+
class Sub extends BinaryArithmeticOpcode, TSub { override final string toString() { result = "Sub" } }
160+
class Mul extends BinaryArithmeticOpcode, TMul { override final string toString() { result = "Mul" } }
161+
class Div extends BinaryArithmeticOpcode, TDiv { override final string toString() { result = "Div" } }
162+
class Rem extends BinaryArithmeticOpcode, TRem { override final string toString() { result = "Rem" } }
163+
class Negate extends UnaryArithmeticOpcode, TNegate { override final string toString() { result = "Negate" } }
164+
class ShiftLeft extends BinaryBitwiseOpcode, TShiftLeft { override final string toString() { result = "ShiftLeft" } }
165+
class ShiftRight extends BinaryBitwiseOpcode, TShiftRight { override final string toString() { result = "ShiftRight" } }
166+
class BitAnd extends BinaryBitwiseOpcode, TBitAnd { override final string toString() { result = "BitAnd" } }
167+
class BitOr extends BinaryBitwiseOpcode, TBitOr { override final string toString() { result = "BitOr" } }
168+
class BitXor extends BinaryBitwiseOpcode, TBitXor { override final string toString() { result = "BitXor" } }
169+
class BitComplement extends UnaryBitwiseOpcode, TBitComplement { override final string toString() { result = "BitComplement" } }
158170
class LogicalNot extends UnaryOpcode, TLogicalNot { override final string toString() { result = "LogicalNot" } }
159171
class CompareEQ extends CompareOpcode, TCompareEQ { override final string toString() { result = "CompareEQ" } }
160172
class CompareNE extends CompareOpcode, TCompareNE { override final string toString() { result = "CompareNE" } }

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -898,67 +898,87 @@ class BinaryInstruction extends Instruction {
898898
}
899899
}
900900

901-
class AddInstruction extends BinaryInstruction {
901+
class ArithmeticInstruction extends Instruction {
902+
ArithmeticInstruction() {
903+
getOpcode() instanceof ArithmeticOpcode
904+
}
905+
}
906+
907+
class BinaryArithmeticInstruction extends ArithmeticInstruction, BinaryInstruction {}
908+
909+
class UnaryArithmeticInstruction extends ArithmeticInstruction, UnaryInstruction {}
910+
911+
class AddInstruction extends BinaryArithmeticInstruction {
902912
AddInstruction() {
903913
getOpcode() instanceof Opcode::Add
904914
}
905915
}
906916

907-
class SubInstruction extends BinaryInstruction {
917+
class SubInstruction extends BinaryArithmeticInstruction {
908918
SubInstruction() {
909919
getOpcode() instanceof Opcode::Sub
910920
}
911921
}
912922

913-
class MulInstruction extends BinaryInstruction {
923+
class MulInstruction extends BinaryArithmeticInstruction {
914924
MulInstruction() {
915925
getOpcode() instanceof Opcode::Mul
916926
}
917927
}
918928

919-
class DivInstruction extends BinaryInstruction {
929+
class DivInstruction extends BinaryArithmeticInstruction {
920930
DivInstruction() {
921931
getOpcode() instanceof Opcode::Div
922932
}
923933
}
924934

925-
class RemInstruction extends BinaryInstruction {
935+
class RemInstruction extends BinaryArithmeticInstruction {
926936
RemInstruction() {
927937
getOpcode() instanceof Opcode::Rem
928938
}
929939
}
930940

931-
class NegateInstruction extends UnaryInstruction {
941+
class NegateInstruction extends UnaryArithmeticInstruction {
932942
NegateInstruction() {
933943
getOpcode() instanceof Opcode::Negate
934944
}
935945
}
936946

937-
class BitAndInstruction extends BinaryInstruction {
947+
class BitwiseInstruction extends Instruction {
948+
BitwiseInstruction() {
949+
getOpcode() instanceof BitwiseOpcode
950+
}
951+
}
952+
953+
class BinaryBitwiseInstruction extends BitwiseInstruction, BinaryInstruction {}
954+
955+
class UnaryBitwiseInstruction extends BitwiseInstruction, UnaryInstruction {}
956+
957+
class BitAndInstruction extends BinaryBitwiseInstruction {
938958
BitAndInstruction() {
939959
getOpcode() instanceof Opcode::BitAnd
940960
}
941961
}
942962

943-
class BitOrInstruction extends BinaryInstruction {
963+
class BitOrInstruction extends BinaryBitwiseInstruction {
944964
BitOrInstruction() {
945965
getOpcode() instanceof Opcode::BitOr
946966
}
947967
}
948968

949-
class BitXorInstruction extends BinaryInstruction {
969+
class BitXorInstruction extends BinaryBitwiseInstruction {
950970
BitXorInstruction() {
951971
getOpcode() instanceof Opcode::BitXor
952972
}
953973
}
954974

955-
class ShiftLeftInstruction extends BinaryInstruction {
975+
class ShiftLeftInstruction extends BinaryBitwiseInstruction {
956976
ShiftLeftInstruction() {
957977
getOpcode() instanceof Opcode::ShiftLeft
958978
}
959979
}
960980

961-
class ShiftRightInstruction extends BinaryInstruction {
981+
class ShiftRightInstruction extends BinaryBitwiseInstruction {
962982
ShiftRightInstruction() {
963983
getOpcode() instanceof Opcode::ShiftRight
964984
}
@@ -1097,7 +1117,7 @@ class ConvertToDerivedInstruction extends InheritanceConversionInstruction {
10971117
}
10981118
}
10991119

1100-
class BitComplementInstruction extends UnaryInstruction {
1120+
class BitComplementInstruction extends UnaryBitwiseInstruction {
11011121
BitComplementInstruction() {
11021122
getOpcode() instanceof Opcode::BitComplement
11031123
}

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -898,67 +898,87 @@ class BinaryInstruction extends Instruction {
898898
}
899899
}
900900

901-
class AddInstruction extends BinaryInstruction {
901+
class ArithmeticInstruction extends Instruction {
902+
ArithmeticInstruction() {
903+
getOpcode() instanceof ArithmeticOpcode
904+
}
905+
}
906+
907+
class BinaryArithmeticInstruction extends ArithmeticInstruction, BinaryInstruction {}
908+
909+
class UnaryArithmeticInstruction extends ArithmeticInstruction, UnaryInstruction {}
910+
911+
class AddInstruction extends BinaryArithmeticInstruction {
902912
AddInstruction() {
903913
getOpcode() instanceof Opcode::Add
904914
}
905915
}
906916

907-
class SubInstruction extends BinaryInstruction {
917+
class SubInstruction extends BinaryArithmeticInstruction {
908918
SubInstruction() {
909919
getOpcode() instanceof Opcode::Sub
910920
}
911921
}
912922

913-
class MulInstruction extends BinaryInstruction {
923+
class MulInstruction extends BinaryArithmeticInstruction {
914924
MulInstruction() {
915925
getOpcode() instanceof Opcode::Mul
916926
}
917927
}
918928

919-
class DivInstruction extends BinaryInstruction {
929+
class DivInstruction extends BinaryArithmeticInstruction {
920930
DivInstruction() {
921931
getOpcode() instanceof Opcode::Div
922932
}
923933
}
924934

925-
class RemInstruction extends BinaryInstruction {
935+
class RemInstruction extends BinaryArithmeticInstruction {
926936
RemInstruction() {
927937
getOpcode() instanceof Opcode::Rem
928938
}
929939
}
930940

931-
class NegateInstruction extends UnaryInstruction {
941+
class NegateInstruction extends UnaryArithmeticInstruction {
932942
NegateInstruction() {
933943
getOpcode() instanceof Opcode::Negate
934944
}
935945
}
936946

937-
class BitAndInstruction extends BinaryInstruction {
947+
class BitwiseInstruction extends Instruction {
948+
BitwiseInstruction() {
949+
getOpcode() instanceof BitwiseOpcode
950+
}
951+
}
952+
953+
class BinaryBitwiseInstruction extends BitwiseInstruction, BinaryInstruction {}
954+
955+
class UnaryBitwiseInstruction extends BitwiseInstruction, UnaryInstruction {}
956+
957+
class BitAndInstruction extends BinaryBitwiseInstruction {
938958
BitAndInstruction() {
939959
getOpcode() instanceof Opcode::BitAnd
940960
}
941961
}
942962

943-
class BitOrInstruction extends BinaryInstruction {
963+
class BitOrInstruction extends BinaryBitwiseInstruction {
944964
BitOrInstruction() {
945965
getOpcode() instanceof Opcode::BitOr
946966
}
947967
}
948968

949-
class BitXorInstruction extends BinaryInstruction {
969+
class BitXorInstruction extends BinaryBitwiseInstruction {
950970
BitXorInstruction() {
951971
getOpcode() instanceof Opcode::BitXor
952972
}
953973
}
954974

955-
class ShiftLeftInstruction extends BinaryInstruction {
975+
class ShiftLeftInstruction extends BinaryBitwiseInstruction {
956976
ShiftLeftInstruction() {
957977
getOpcode() instanceof Opcode::ShiftLeft
958978
}
959979
}
960980

961-
class ShiftRightInstruction extends BinaryInstruction {
981+
class ShiftRightInstruction extends BinaryBitwiseInstruction {
962982
ShiftRightInstruction() {
963983
getOpcode() instanceof Opcode::ShiftRight
964984
}
@@ -1097,7 +1117,7 @@ class ConvertToDerivedInstruction extends InheritanceConversionInstruction {
10971117
}
10981118
}
10991119

1100-
class BitComplementInstruction extends UnaryInstruction {
1120+
class BitComplementInstruction extends UnaryBitwiseInstruction {
11011121
BitComplementInstruction() {
11021122
getOpcode() instanceof Opcode::BitComplement
11031123
}

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -898,67 +898,87 @@ class BinaryInstruction extends Instruction {
898898
}
899899
}
900900

901-
class AddInstruction extends BinaryInstruction {
901+
class ArithmeticInstruction extends Instruction {
902+
ArithmeticInstruction() {
903+
getOpcode() instanceof ArithmeticOpcode
904+
}
905+
}
906+
907+
class BinaryArithmeticInstruction extends ArithmeticInstruction, BinaryInstruction {}
908+
909+
class UnaryArithmeticInstruction extends ArithmeticInstruction, UnaryInstruction {}
910+
911+
class AddInstruction extends BinaryArithmeticInstruction {
902912
AddInstruction() {
903913
getOpcode() instanceof Opcode::Add
904914
}
905915
}
906916

907-
class SubInstruction extends BinaryInstruction {
917+
class SubInstruction extends BinaryArithmeticInstruction {
908918
SubInstruction() {
909919
getOpcode() instanceof Opcode::Sub
910920
}
911921
}
912922

913-
class MulInstruction extends BinaryInstruction {
923+
class MulInstruction extends BinaryArithmeticInstruction {
914924
MulInstruction() {
915925
getOpcode() instanceof Opcode::Mul
916926
}
917927
}
918928

919-
class DivInstruction extends BinaryInstruction {
929+
class DivInstruction extends BinaryArithmeticInstruction {
920930
DivInstruction() {
921931
getOpcode() instanceof Opcode::Div
922932
}
923933
}
924934

925-
class RemInstruction extends BinaryInstruction {
935+
class RemInstruction extends BinaryArithmeticInstruction {
926936
RemInstruction() {
927937
getOpcode() instanceof Opcode::Rem
928938
}
929939
}
930940

931-
class NegateInstruction extends UnaryInstruction {
941+
class NegateInstruction extends UnaryArithmeticInstruction {
932942
NegateInstruction() {
933943
getOpcode() instanceof Opcode::Negate
934944
}
935945
}
936946

937-
class BitAndInstruction extends BinaryInstruction {
947+
class BitwiseInstruction extends Instruction {
948+
BitwiseInstruction() {
949+
getOpcode() instanceof BitwiseOpcode
950+
}
951+
}
952+
953+
class BinaryBitwiseInstruction extends BitwiseInstruction, BinaryInstruction {}
954+
955+
class UnaryBitwiseInstruction extends BitwiseInstruction, UnaryInstruction {}
956+
957+
class BitAndInstruction extends BinaryBitwiseInstruction {
938958
BitAndInstruction() {
939959
getOpcode() instanceof Opcode::BitAnd
940960
}
941961
}
942962

943-
class BitOrInstruction extends BinaryInstruction {
963+
class BitOrInstruction extends BinaryBitwiseInstruction {
944964
BitOrInstruction() {
945965
getOpcode() instanceof Opcode::BitOr
946966
}
947967
}
948968

949-
class BitXorInstruction extends BinaryInstruction {
969+
class BitXorInstruction extends BinaryBitwiseInstruction {
950970
BitXorInstruction() {
951971
getOpcode() instanceof Opcode::BitXor
952972
}
953973
}
954974

955-
class ShiftLeftInstruction extends BinaryInstruction {
975+
class ShiftLeftInstruction extends BinaryBitwiseInstruction {
956976
ShiftLeftInstruction() {
957977
getOpcode() instanceof Opcode::ShiftLeft
958978
}
959979
}
960980

961-
class ShiftRightInstruction extends BinaryInstruction {
981+
class ShiftRightInstruction extends BinaryBitwiseInstruction {
962982
ShiftRightInstruction() {
963983
getOpcode() instanceof Opcode::ShiftRight
964984
}
@@ -1097,7 +1117,7 @@ class ConvertToDerivedInstruction extends InheritanceConversionInstruction {
10971117
}
10981118
}
10991119

1100-
class BitComplementInstruction extends UnaryInstruction {
1120+
class BitComplementInstruction extends UnaryBitwiseInstruction {
11011121
BitComplementInstruction() {
11021122
getOpcode() instanceof Opcode::BitComplement
11031123
}

0 commit comments

Comments
 (0)