mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Rust: Add BitwiseOperation library.
This commit is contained in:
27
rust/ql/lib/codeql/rust/elements/BitwiseOperation.qll
Normal file
27
rust/ql/lib/codeql/rust/elements/BitwiseOperation.qll
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Provides classes for bitwise operations.
|
||||
*/
|
||||
|
||||
private import codeql.rust.elements.BinaryExpr
|
||||
private import codeql.rust.elements.Operation
|
||||
|
||||
/**
|
||||
* A bitwise operation, such as `&`, `<<`, or `|=`.
|
||||
*/
|
||||
abstract private class BitwiseOperationImpl extends Operation { }
|
||||
|
||||
final class BitwiseOperation = BitwiseOperationImpl;
|
||||
|
||||
/**
|
||||
* A binary bitwise operation, such as `&` or `<<`.
|
||||
*/
|
||||
final class BinaryBitwiseOperation extends BinaryExpr, BitwiseOperationImpl {
|
||||
BinaryBitwiseOperation() { this.getOperatorName() = ["&", "|", "^", "<<", ">>"] }
|
||||
}
|
||||
|
||||
/**
|
||||
* A bitwise assignment operation, such as `|=` or `<<=`.
|
||||
*/
|
||||
final class AssignBitwiseOperation extends BinaryExpr, BitwiseOperationImpl {
|
||||
AssignBitwiseOperation() { this.getOperatorName() = ["&=", "|=", "^=", "<<=", ">>="] }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import codeql.files.FileSystem
|
||||
import codeql.rust.elements.Operation
|
||||
import codeql.rust.elements.ArithmeticOperation
|
||||
import codeql.rust.elements.AssignmentOperation
|
||||
import codeql.rust.elements.BitwiseOperation
|
||||
import codeql.rust.elements.ComparisonOperation
|
||||
import codeql.rust.elements.LiteralExprExt
|
||||
import codeql.rust.elements.LogicalOperation
|
||||
|
||||
@@ -39,6 +39,12 @@ string describe(Expr op) {
|
||||
op instanceof AssignArithmeticOperation and result = "AssignArithmeticOperation"
|
||||
or
|
||||
op instanceof PrefixArithmeticOperation and result = "PrefixArithmeticOperation"
|
||||
or
|
||||
op instanceof BitwiseOperation and result = "BitwiseOperation"
|
||||
or
|
||||
op instanceof BinaryBitwiseOperation and result = "BinaryBitwiseOperation"
|
||||
or
|
||||
op instanceof AssignBitwiseOperation and result = "AssignBitwiseOperation"
|
||||
}
|
||||
|
||||
module OperationsTest implements TestSig {
|
||||
|
||||
@@ -37,16 +37,16 @@ fn test_operations(
|
||||
!a; // $ Operation Op=! Operands=1 PrefixExpr LogicalOperation
|
||||
|
||||
// bitwise operations
|
||||
x & y; // $ Operation Op=& Operands=2 BinaryExpr
|
||||
x | y; // $ Operation Op=| Operands=2 BinaryExpr
|
||||
x ^ y; // $ Operation Op=^ Operands=2 BinaryExpr
|
||||
x << y; // $ Operation Op=<< Operands=2 BinaryExpr
|
||||
x >> y; // $ Operation Op=>> Operands=2 BinaryExpr
|
||||
x &= y; // $ Operation Op=&= Operands=2 AssignmentOperation BinaryExpr
|
||||
x |= y; // $ Operation Op=|= Operands=2 AssignmentOperation BinaryExpr
|
||||
x ^= y; // $ Operation Op=^= Operands=2 AssignmentOperation BinaryExpr
|
||||
x <<= y; // $ Operation Op=<<= Operands=2 AssignmentOperation BinaryExpr
|
||||
x >>= y; // $ Operation Op=>>= Operands=2 AssignmentOperation BinaryExpr
|
||||
x & y; // $ Operation Op=& Operands=2 BinaryExpr BitwiseOperation BinaryBitwiseOperation
|
||||
x | y; // $ Operation Op=| Operands=2 BinaryExpr BitwiseOperation BinaryBitwiseOperation
|
||||
x ^ y; // $ Operation Op=^ Operands=2 BinaryExpr BitwiseOperation BinaryBitwiseOperation
|
||||
x << y; // $ Operation Op=<< Operands=2 BinaryExpr BitwiseOperation BinaryBitwiseOperation
|
||||
x >> y; // $ Operation Op=>> Operands=2 BinaryExpr BitwiseOperation BinaryBitwiseOperation
|
||||
x &= y; // $ Operation Op=&= Operands=2 AssignmentOperation BinaryExpr BitwiseOperation AssignBitwiseOperation
|
||||
x |= y; // $ Operation Op=|= Operands=2 AssignmentOperation BinaryExpr BitwiseOperation AssignBitwiseOperation
|
||||
x ^= y; // $ Operation Op=^= Operands=2 AssignmentOperation BinaryExpr BitwiseOperation AssignBitwiseOperation
|
||||
x <<= y; // $ Operation Op=<<= Operands=2 AssignmentOperation BinaryExpr BitwiseOperation AssignBitwiseOperation
|
||||
x >>= y; // $ Operation Op=>>= Operands=2 AssignmentOperation BinaryExpr BitwiseOperation AssignBitwiseOperation
|
||||
|
||||
// miscellaneous expressions that might be operations
|
||||
*ptr; // $ Operation Op=* Operands=1 PrefixExpr
|
||||
|
||||
Reference in New Issue
Block a user