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

Skip to content

Commit 7758b43

Browse files
committed
C++: Add ConvertToBase{Opcode,Instruction} classes
These should make it easy to match base-class conversions when it's not important whether the base class is virtual.
1 parent 279fc16 commit 7758b43

7 files changed

Lines changed: 58 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ abstract class RelationalOpcode extends CompareOpcode { }
110110

111111
abstract class CopyOpcode extends Opcode { }
112112

113+
abstract class ConvertToBaseOpcode extends UnaryOpcode { }
114+
113115
abstract class MemoryAccessOpcode extends Opcode { }
114116

115117
abstract class ReturnOpcode extends Opcode { }
@@ -302,11 +304,11 @@ module Opcode {
302304
final override string toString() { result = "Convert" }
303305
}
304306

305-
class ConvertToNonVirtualBase extends UnaryOpcode, TConvertToNonVirtualBase {
307+
class ConvertToNonVirtualBase extends ConvertToBaseOpcode, TConvertToNonVirtualBase {
306308
final override string toString() { result = "ConvertToNonVirtualBase" }
307309
}
308310

309-
class ConvertToVirtualBase extends UnaryOpcode, TConvertToVirtualBase {
311+
class ConvertToVirtualBase extends ConvertToBaseOpcode, TConvertToVirtualBase {
310312
final override string toString() { result = "ConvertToVirtualBase" }
311313
}
312314

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,23 @@ class InheritanceConversionInstruction extends UnaryInstruction {
980980
* Represents an instruction that converts from the address of a derived class
981981
* to the address of a direct non-virtual base class.
982982
*/
983-
class ConvertToNonVirtualBaseInstruction extends InheritanceConversionInstruction {
983+
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984+
ConvertToBaseInstruction() { getOpcode() instanceof ConvertToBaseOpcode }
985+
}
986+
987+
/**
988+
* Represents an instruction that converts from the address of a derived class
989+
* to the address of a direct non-virtual base class.
990+
*/
991+
class ConvertToNonVirtualBaseInstruction extends ConvertToBaseInstruction {
984992
ConvertToNonVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToNonVirtualBase }
985993
}
986994

987995
/**
988996
* Represents an instruction that converts from the address of a derived class
989997
* to the address of a virtual base class.
990998
*/
991-
class ConvertToVirtualBaseInstruction extends InheritanceConversionInstruction {
999+
class ConvertToVirtualBaseInstruction extends ConvertToBaseInstruction {
9921000
ConvertToVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToVirtualBase }
9931001
}
9941002

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,23 @@ class InheritanceConversionInstruction extends UnaryInstruction {
980980
* Represents an instruction that converts from the address of a derived class
981981
* to the address of a direct non-virtual base class.
982982
*/
983-
class ConvertToNonVirtualBaseInstruction extends InheritanceConversionInstruction {
983+
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984+
ConvertToBaseInstruction() { getOpcode() instanceof ConvertToBaseOpcode }
985+
}
986+
987+
/**
988+
* Represents an instruction that converts from the address of a derived class
989+
* to the address of a direct non-virtual base class.
990+
*/
991+
class ConvertToNonVirtualBaseInstruction extends ConvertToBaseInstruction {
984992
ConvertToNonVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToNonVirtualBase }
985993
}
986994

987995
/**
988996
* Represents an instruction that converts from the address of a derived class
989997
* to the address of a virtual base class.
990998
*/
991-
class ConvertToVirtualBaseInstruction extends InheritanceConversionInstruction {
999+
class ConvertToVirtualBaseInstruction extends ConvertToBaseInstruction {
9921000
ConvertToVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToVirtualBase }
9931001
}
9941002

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,23 @@ class InheritanceConversionInstruction extends UnaryInstruction {
980980
* Represents an instruction that converts from the address of a derived class
981981
* to the address of a direct non-virtual base class.
982982
*/
983-
class ConvertToNonVirtualBaseInstruction extends InheritanceConversionInstruction {
983+
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984+
ConvertToBaseInstruction() { getOpcode() instanceof ConvertToBaseOpcode }
985+
}
986+
987+
/**
988+
* Represents an instruction that converts from the address of a derived class
989+
* to the address of a direct non-virtual base class.
990+
*/
991+
class ConvertToNonVirtualBaseInstruction extends ConvertToBaseInstruction {
984992
ConvertToNonVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToNonVirtualBase }
985993
}
986994

987995
/**
988996
* Represents an instruction that converts from the address of a derived class
989997
* to the address of a virtual base class.
990998
*/
991-
class ConvertToVirtualBaseInstruction extends InheritanceConversionInstruction {
999+
class ConvertToVirtualBaseInstruction extends ConvertToBaseInstruction {
9921000
ConvertToVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToVirtualBase }
9931001
}
9941002

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ abstract class RelationalOpcode extends CompareOpcode { }
110110

111111
abstract class CopyOpcode extends Opcode { }
112112

113+
abstract class ConvertToBaseOpcode extends UnaryOpcode { }
114+
113115
abstract class MemoryAccessOpcode extends Opcode { }
114116

115117
abstract class ReturnOpcode extends Opcode { }
@@ -302,11 +304,11 @@ module Opcode {
302304
final override string toString() { result = "Convert" }
303305
}
304306

305-
class ConvertToNonVirtualBase extends UnaryOpcode, TConvertToNonVirtualBase {
307+
class ConvertToNonVirtualBase extends ConvertToBaseOpcode, TConvertToNonVirtualBase {
306308
final override string toString() { result = "ConvertToNonVirtualBase" }
307309
}
308310

309-
class ConvertToVirtualBase extends UnaryOpcode, TConvertToVirtualBase {
311+
class ConvertToVirtualBase extends ConvertToBaseOpcode, TConvertToVirtualBase {
310312
final override string toString() { result = "ConvertToVirtualBase" }
311313
}
312314

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,23 @@ class InheritanceConversionInstruction extends UnaryInstruction {
980980
* Represents an instruction that converts from the address of a derived class
981981
* to the address of a direct non-virtual base class.
982982
*/
983-
class ConvertToNonVirtualBaseInstruction extends InheritanceConversionInstruction {
983+
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984+
ConvertToBaseInstruction() { getOpcode() instanceof ConvertToBaseOpcode }
985+
}
986+
987+
/**
988+
* Represents an instruction that converts from the address of a derived class
989+
* to the address of a direct non-virtual base class.
990+
*/
991+
class ConvertToNonVirtualBaseInstruction extends ConvertToBaseInstruction {
984992
ConvertToNonVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToNonVirtualBase }
985993
}
986994

987995
/**
988996
* Represents an instruction that converts from the address of a derived class
989997
* to the address of a virtual base class.
990998
*/
991-
class ConvertToVirtualBaseInstruction extends InheritanceConversionInstruction {
999+
class ConvertToVirtualBaseInstruction extends ConvertToBaseInstruction {
9921000
ConvertToVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToVirtualBase }
9931001
}
9941002

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,23 @@ class InheritanceConversionInstruction extends UnaryInstruction {
980980
* Represents an instruction that converts from the address of a derived class
981981
* to the address of a direct non-virtual base class.
982982
*/
983-
class ConvertToNonVirtualBaseInstruction extends InheritanceConversionInstruction {
983+
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984+
ConvertToBaseInstruction() { getOpcode() instanceof ConvertToBaseOpcode }
985+
}
986+
987+
/**
988+
* Represents an instruction that converts from the address of a derived class
989+
* to the address of a direct non-virtual base class.
990+
*/
991+
class ConvertToNonVirtualBaseInstruction extends ConvertToBaseInstruction {
984992
ConvertToNonVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToNonVirtualBase }
985993
}
986994

987995
/**
988996
* Represents an instruction that converts from the address of a derived class
989997
* to the address of a virtual base class.
990998
*/
991-
class ConvertToVirtualBaseInstruction extends InheritanceConversionInstruction {
999+
class ConvertToVirtualBaseInstruction extends ConvertToBaseInstruction {
9921000
ConvertToVirtualBaseInstruction() { getOpcode() instanceof Opcode::ConvertToVirtualBase }
9931001
}
9941002

0 commit comments

Comments
 (0)