class AdLint::Exam::CBuiltin::W0780

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 19175
def initialize(phase_ctxt)
  super
  @interp = phase_ctxt[:cc1_interpreter]
  @interp.on_shift_expr_evaled += T(:check)
end

Private Instance Methods

check(expr, lhs_var, rhs_var, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 19182
def check(expr, lhs_var, rhs_var, *)
  op = expr.operator.type
  return unless op == "<<" || op == "<<="

  if lhs_var.type.unsigned? && constant_expression?(expr)
    if must_overflow?(lhs_var, rhs_var)
      W(expr.location)
    end
  end
end
interpreter() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 19199
def interpreter
  @interp
end
must_overflow?(lhs_var, rhs_var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 19193
def must_overflow?(lhs_var, rhs_var)
  unbound_val = lhs_var.value << rhs_var.value
  lhs_max_val = scalar_value_of(lhs_var.type.max)
  unbound_val.test_must_be_greater_than(lhs_max_val).true?
end