File tree Expand file tree Collapse file tree 5 files changed +40
-1
lines changed
csharp/ql/src/experimental/ir Expand file tree Collapse file tree 5 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ private newtype TOpcode =
30
30
TNegate ( ) or
31
31
TShiftLeft ( ) or
32
32
TShiftRight ( ) or
33
+ TUnsignedShiftRight ( ) or
33
34
TBitAnd ( ) or
34
35
TBitOr ( ) or
35
36
TBitXor ( ) or
@@ -652,6 +653,15 @@ module Opcode {
652
653
final override string toString ( ) { result = "ShiftRight" }
653
654
}
654
655
656
+ /**
657
+ * The `Opcode` for a `UnsignedShiftRightInstruction`.
658
+ *
659
+ * See the `UnsignedShiftRightInstruction` documentation for more details.
660
+ */
661
+ class UnsignedShiftRight extends BinaryBitwiseOpcode , TUnsignedShiftRight {
662
+ final override string toString ( ) { result = "UnsignedShiftRight" }
663
+ }
664
+
655
665
/**
656
666
* The `Opcode` for a `BitAndInstruction`.
657
667
*
Original file line number Diff line number Diff line change @@ -1204,6 +1204,17 @@ class ShiftRightInstruction extends BinaryBitwiseInstruction {
1204
1204
ShiftRightInstruction ( ) { this .getOpcode ( ) instanceof Opcode:: ShiftRight }
1205
1205
}
1206
1206
1207
+ /**
1208
+ * An instruction that shifts its left operand to the right by the number of bits specified by its
1209
+ * right operand.
1210
+ *
1211
+ * Both operands must have an integer type. The result has the same type as the left operand.
1212
+ * The leftmost bits are zero-filled.
1213
+ */
1214
+ class UnsignedShiftRightInstruction extends BinaryBitwiseInstruction {
1215
+ UnsignedShiftRightInstruction ( ) { this .getOpcode ( ) instanceof Opcode:: UnsignedShiftRight }
1216
+ }
1217
+
1207
1218
/**
1208
1219
* An instruction that performs a binary arithmetic operation involving at least one pointer
1209
1220
* operand.
Original file line number Diff line number Diff line change @@ -1095,6 +1095,8 @@ private Opcode binaryBitwiseOpcode(BinaryBitwiseOperation expr) {
1095
1095
or
1096
1096
expr instanceof RightShiftExpr and result instanceof Opcode:: ShiftRight
1097
1097
or
1098
+ expr instanceof UnsignedRightShiftExpr and result instanceof Opcode:: UnsignedShiftRight
1099
+ or
1098
1100
expr instanceof BitwiseAndExpr and result instanceof Opcode:: BitAnd
1099
1101
or
1100
1102
expr instanceof BitwiseOrExpr and result instanceof Opcode:: BitOr
@@ -1378,7 +1380,8 @@ class TranslatedAssignOperation extends TranslatedAssignment {
1378
1380
private Type getConvertedLeftOperandType ( ) {
1379
1381
if
1380
1382
expr instanceof AssignLeftShiftExpr or
1381
- expr instanceof AssignRightShiftExpr
1383
+ expr instanceof AssignRightShiftExpr or
1384
+ expr instanceof AssignUnsighedRightShiftExpr
1382
1385
then result = this .getLeftOperand ( ) .getResultType ( )
1383
1386
else
1384
1387
// The right operand has already been converted to the type of the op.
@@ -1419,6 +1422,8 @@ class TranslatedAssignOperation extends TranslatedAssignment {
1419
1422
expr instanceof AssignLeftShiftExpr and result instanceof Opcode:: ShiftLeft
1420
1423
or
1421
1424
expr instanceof AssignRightShiftExpr and result instanceof Opcode:: ShiftRight
1425
+ or
1426
+ expr instanceof AssignUnsighedRightShiftExpr and result instanceof Opcode:: UnsignedShiftRight
1422
1427
}
1423
1428
1424
1429
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CSharpType resultType ) {
Original file line number Diff line number Diff line change @@ -1204,6 +1204,17 @@ class ShiftRightInstruction extends BinaryBitwiseInstruction {
1204
1204
ShiftRightInstruction ( ) { this .getOpcode ( ) instanceof Opcode:: ShiftRight }
1205
1205
}
1206
1206
1207
+ /**
1208
+ * An instruction that shifts its left operand to the right by the number of bits specified by its
1209
+ * right operand.
1210
+ *
1211
+ * Both operands must have an integer type. The result has the same type as the left operand.
1212
+ * The leftmost bits are zero-filled.
1213
+ */
1214
+ class UnsignedShiftRightInstruction extends BinaryBitwiseInstruction {
1215
+ UnsignedShiftRightInstruction ( ) { this .getOpcode ( ) instanceof Opcode:: UnsignedShiftRight }
1216
+ }
1217
+
1207
1218
/**
1208
1219
* An instruction that performs a binary arithmetic operation involving at least one pointer
1209
1220
* operand.
Original file line number Diff line number Diff line change @@ -522,6 +522,8 @@ module SignAnalysisCached {
522
522
i instanceof ShiftRightInstruction and
523
523
not i .getResultType ( ) .( IntegralType ) instanceof SignedIntegralType and
524
524
result = s1 .urshift ( s2 )
525
+ or
526
+ i instanceof UnsignedShiftRightInstruction and result = s1 .urshift ( s2 )
525
527
)
526
528
or
527
529
// use hasGuard here?
You can’t perform that action at this time.
0 commit comments