MCPcopy Create free account
hub / github.com/Rust-API/Rust-API-Bypass-Checker / equals

Method equals

src/analysis/memory/symbolic_value.rs:793–846  ·  view source on GitHub ↗

Returns an element that is "self == other".

(&self, other: Rc<SymbolicValue>)

Source from the content-addressed store, hash-verified

791
792 /// Returns an element that is "self == other".
793 fn equals(&self, other: Rc<SymbolicValue>) -> Rc<SymbolicValue> {
794 match (&self.expression, &other.expression) {
795 (Expression::CompileTimeConstant(v1), Expression::CompileTimeConstant(v2)) => {
796 return Rc::new(v1.equals(v2).into());
797 }
798 // If self and other are the same location in memory, return true unless the value might be NaN.
799 (
800 Expression::Variable {
801 path: p1,
802 var_type: _t1,
803 },
804 Expression::Variable {
805 path: p2,
806 var_type: _t2,
807 },
808 ) => {
809 if p1 == p2 {
810 return Rc::new(SymbolicValue::new_true());
811 }
812 }
813 // [!x == 0] -> x when x is Boolean. Canonicalize it to the latter.
814 (
815 Expression::LogicalNot { operand },
816 Expression::CompileTimeConstant(ConstantValue::Int(val)),
817 ) => {
818 if *val == 0 && operand.expression.infer_type() == ExpressionType::Bool {
819 return operand.clone();
820 }
821 }
822 // [x == 0] -> !x when x is a Boolean. Canonicalize it to the latter.
823 // [x == 1] -> x when x is a Boolean. Canonicalize it to the latter.
824 (x, Expression::CompileTimeConstant(ConstantValue::Int(val))) => {
825 if x.infer_type() == ExpressionType::Bool {
826 if *val == 0 {
827 return self.logical_not();
828 } else if *val == 1 {
829 return self.clone();
830 }
831 }
832 }
833 (x, y) => {
834 // If self and other are the same expression and the expression could not result in NaN
835 // and the expression represents exactly one value, we can simplify this to true.
836 if x == y {
837 return Rc::new(SymbolicValue::new_true());
838 }
839 }
840 }
841 // Return an equals expression rather than a constant expression.
842 SymbolicValue::make_binary(self.clone(), other, |left, right| Expression::Equals {
843 left,
844 right,
845 })
846 }
847
848 /// Returns an element that is "self >= other".
849 fn greater_or_equal(&self, other: Rc<SymbolicValue>) -> Rc<SymbolicValue> {

Callers 4

refine_pathsMethod · 0.45
refine_parametersMethod · 0.45
logical_notMethod · 0.45
refine_withMethod · 0.45

Calls 2

infer_typeMethod · 0.80
logical_notMethod · 0.45

Tested by

no test coverage detected