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

Skip to content

Commit 303bab6

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2289 from jbj/ConvertToNonVirtualBaseInstruction
C++ IR: clearly distinguish between virtual and non-virtual base conversions
2 parents ec79bfa + eb55d96 commit 303bab6

15 files changed

Lines changed: 695 additions & 651 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private newtype TOpcode =
3434
TPointerSub() or
3535
TPointerDiff() or
3636
TConvert() or
37-
TConvertToBase() or
37+
TConvertToNonVirtualBase() or
3838
TConvertToVirtualBase() or
3939
TConvertToDerived() or
4040
TCheckedConvertOrNull() or
@@ -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 ConvertToBase extends UnaryOpcode, TConvertToBase {
306-
final override string toString() { result = "ConvertToBase" }
307+
class ConvertToNonVirtualBase extends ConvertToBaseOpcode, TConvertToNonVirtualBase {
308+
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
@@ -981,14 +981,22 @@ class InheritanceConversionInstruction extends UnaryInstruction {
981981
* to the address of a direct non-virtual base class.
982982
*/
983983
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984-
ConvertToBaseInstruction() { getOpcode() instanceof Opcode::ConvertToBase }
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 {
992+
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/aliased_ssa/internal/AliasAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private predicate operandIsPropagated(Operand operand, IntValue bitOffset) {
109109
instr = operand.getUse() and
110110
(
111111
// Converting to a non-virtual base class adds the offset of the base class.
112-
exists(ConvertToBaseInstruction convert |
112+
exists(ConvertToNonVirtualBaseInstruction convert |
113113
convert = instr and
114114
bitOffset = Ints::mul(convert.getDerivation().getByteOffset(), 8)
115115
)

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
@@ -981,14 +981,22 @@ class InheritanceConversionInstruction extends UnaryInstruction {
981981
* to the address of a direct non-virtual base class.
982982
*/
983983
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984-
ConvertToBaseInstruction() { getOpcode() instanceof Opcode::ConvertToBase }
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 {
992+
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/internal/TranslatedExpr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ class TranslatedInheritanceConversion extends TranslatedSingleInstructionConvers
10381038
then
10391039
if expr.(BaseClassConversion).isVirtual()
10401040
then result instanceof Opcode::ConvertToVirtualBase
1041-
else result instanceof Opcode::ConvertToBase
1041+
else result instanceof Opcode::ConvertToNonVirtualBase
10421042
else result instanceof Opcode::ConvertToDerived
10431043
}
10441044
}

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedInitialization.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ abstract class TranslatedBaseStructorCall extends TranslatedStructorCallFromStru
752752

753753
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
754754
tag = OnlyInstructionTag() and
755-
opcode instanceof Opcode::ConvertToBase and
755+
opcode instanceof Opcode::ConvertToNonVirtualBase and
756756
resultType = getTypeForGLValue(call.getTarget().getDeclaringType())
757757
}
758758

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
@@ -981,14 +981,22 @@ class InheritanceConversionInstruction extends UnaryInstruction {
981981
* to the address of a direct non-virtual base class.
982982
*/
983983
class ConvertToBaseInstruction extends InheritanceConversionInstruction {
984-
ConvertToBaseInstruction() { getOpcode() instanceof Opcode::ConvertToBase }
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 {
992+
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/internal/AliasAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private predicate operandIsPropagated(Operand operand, IntValue bitOffset) {
109109
instr = operand.getUse() and
110110
(
111111
// Converting to a non-virtual base class adds the offset of the base class.
112-
exists(ConvertToBaseInstruction convert |
112+
exists(ConvertToNonVirtualBaseInstruction convert |
113113
convert = instr and
114114
bitOffset = Ints::mul(convert.getDerivation().getByteOffset(), 8)
115115
)

cpp/ql/test/library-tests/ir/escape/points_to.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
| escape.cpp:146:5:146:18 | CopyValue | no_Point+8:0 | no_Point+8:0 |
3636
| escape.cpp:146:7:146:17 | CopyValue | no_Point+8:0 | no_Point+8:0 |
3737
| escape.cpp:146:17:146:17 | FieldAddress[z] | no_Point+8:0 | no_Point+8:0 |
38-
| escape.cpp:149:5:149:14 | ConvertToBase[Derived : Intermediate1] | no_Derived+0:0 | no_Derived+0:0 |
39-
| escape.cpp:149:5:149:14 | ConvertToBase[Intermediate1 : Base] | no_Derived+0:0 | no_Derived+0:0 |
38+
| escape.cpp:149:5:149:14 | ConvertToNonVirtualBase[Derived : Intermediate1] | no_Derived+0:0 | no_Derived+0:0 |
39+
| escape.cpp:149:5:149:14 | ConvertToNonVirtualBase[Intermediate1 : Base] | no_Derived+0:0 | no_Derived+0:0 |
4040
| escape.cpp:149:16:149:16 | FieldAddress[b] | no_Derived+0:0 | no_Derived+0:0 |
41-
| escape.cpp:150:18:150:27 | ConvertToBase[Derived : Intermediate1] | no_Derived+0:0 | no_Derived+0:0 |
42-
| escape.cpp:150:18:150:27 | ConvertToBase[Intermediate1 : Base] | no_Derived+0:0 | no_Derived+0:0 |
41+
| escape.cpp:150:18:150:27 | ConvertToNonVirtualBase[Derived : Intermediate1] | no_Derived+0:0 | no_Derived+0:0 |
42+
| escape.cpp:150:18:150:27 | ConvertToNonVirtualBase[Intermediate1 : Base] | no_Derived+0:0 | no_Derived+0:0 |
4343
| escape.cpp:150:29:150:29 | FieldAddress[b] | no_Derived+0:0 | no_Derived+0:0 |
44-
| escape.cpp:151:5:151:14 | ConvertToBase[Derived : Intermediate2] | no_Derived+12:0 | no_Derived+12:0 |
44+
| escape.cpp:151:5:151:14 | ConvertToNonVirtualBase[Derived : Intermediate2] | no_Derived+12:0 | no_Derived+12:0 |
4545
| escape.cpp:151:16:151:17 | FieldAddress[i2] | no_Derived+16:0 | no_Derived+16:0 |
46-
| escape.cpp:152:19:152:28 | ConvertToBase[Derived : Intermediate2] | no_Derived+12:0 | no_Derived+12:0 |
46+
| escape.cpp:152:19:152:28 | ConvertToNonVirtualBase[Derived : Intermediate2] | no_Derived+12:0 | no_Derived+12:0 |
4747
| escape.cpp:152:30:152:31 | FieldAddress[i2] | no_Derived+16:0 | no_Derived+16:0 |
4848
| escape.cpp:155:17:155:30 | CopyValue | no_ssa_addrOf+0:0 | no_ssa_addrOf+0:0 |
4949
| escape.cpp:155:17:155:30 | Store | no_ssa_addrOf+0:0 | no_ssa_addrOf+0:0 |

0 commit comments

Comments
 (0)