Skip to content

Commit c726285

Browse files
committed
C++: Sync identical files.
1 parent 0d9e298 commit c726285

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ newtype TValueNumber =
4343
} or
4444
TUniqueValueNumber(IRFunction irFunc, Instruction instr) { uniqueValueNumber(instr, irFunc) }
4545

46+
/**
47+
* A `ConvertInstruction` which converts data of type `T` to data of type `U`
48+
* where `T` and `U` only differ in specifiers. For example, if `T` is `int`
49+
* and `U` is `const T` this is a conversion from a non-const integer to a
50+
* const integer.
51+
*
52+
* Generally, the value number of a converted value is different from the value
53+
* number of an unconverted value, but conversions which only modify specifiers
54+
* leave the resulting value bitwise identical to the old value.
55+
*/
56+
class TypePreservingConvertInstruction extends ConvertInstruction {
57+
TypePreservingConvertInstruction() {
58+
pragma[only_bind_out](this.getResultType().getUnspecifiedType()) =
59+
pragma[only_bind_out](this.getUnary().getResultType().getUnspecifiedType())
60+
}
61+
}
62+
4663
/**
4764
* A `CopyInstruction` whose source operand's value is congruent to the definition of that source
4865
* operand.
@@ -216,6 +233,7 @@ private predicate unaryValueNumber(
216233
not instr instanceof InheritanceConversionInstruction and
217234
not instr instanceof CopyInstruction and
218235
not instr instanceof FieldAddressInstruction and
236+
not instr instanceof TypePreservingConvertInstruction and
219237
instr.getOpcode() = opcode and
220238
tvalueNumber(instr.getUnary()) = operand
221239
}
@@ -351,6 +369,10 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
351369
or
352370
// The value number of a copy is just the value number of its source value.
353371
result = tvalueNumber(instr.(CongruentCopyInstruction).getSourceValue())
372+
or
373+
// The value number of a type-preserving conversion is just the value
374+
// number of the unconverted value.
375+
result = tvalueNumber(instr.(TypePreservingConvertInstruction).getUnary())
354376
)
355377
)
356378
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingInternal.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ newtype TValueNumber =
4343
} or
4444
TUniqueValueNumber(IRFunction irFunc, Instruction instr) { uniqueValueNumber(instr, irFunc) }
4545

46+
/**
47+
* A `ConvertInstruction` which converts data of type `T` to data of type `U`
48+
* where `T` and `U` only differ in specifiers. For example, if `T` is `int`
49+
* and `U` is `const T` this is a conversion from a non-const integer to a
50+
* const integer.
51+
*
52+
* Generally, the value number of a converted value is different from the value
53+
* number of an unconverted value, but conversions which only modify specifiers
54+
* leave the resulting value bitwise identical to the old value.
55+
*/
56+
class TypePreservingConvertInstruction extends ConvertInstruction {
57+
TypePreservingConvertInstruction() {
58+
pragma[only_bind_out](this.getResultType().getUnspecifiedType()) =
59+
pragma[only_bind_out](this.getUnary().getResultType().getUnspecifiedType())
60+
}
61+
}
62+
4663
/**
4764
* A `CopyInstruction` whose source operand's value is congruent to the definition of that source
4865
* operand.
@@ -216,6 +233,7 @@ private predicate unaryValueNumber(
216233
not instr instanceof InheritanceConversionInstruction and
217234
not instr instanceof CopyInstruction and
218235
not instr instanceof FieldAddressInstruction and
236+
not instr instanceof TypePreservingConvertInstruction and
219237
instr.getOpcode() = opcode and
220238
tvalueNumber(instr.getUnary()) = operand
221239
}
@@ -351,6 +369,10 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
351369
or
352370
// The value number of a copy is just the value number of its source value.
353371
result = tvalueNumber(instr.(CongruentCopyInstruction).getSourceValue())
372+
or
373+
// The value number of a type-preserving conversion is just the value
374+
// number of the unconverted value.
375+
result = tvalueNumber(instr.(TypePreservingConvertInstruction).getUnary())
354376
)
355377
)
356378
}

0 commit comments

Comments
 (0)