class AdLint::Exam::CBuiltin::W0581

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 13606
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_function_call_expr_evaled += T(:check)
  @funcalls = Hash.new { |hash, key| hash[key] = [] }
end

Private Instance Methods

check(funcall_expr, fun, arg_vars, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 13614
def check(funcall_expr, fun, arg_vars, *)
  return unless fun.named?
  return if prototype_declaration_of(fun)

  arg_types = arg_vars.map { |var| var.type.unqualify }

  @funcalls[fun.name].each do |prv_arg_types|
    if prv_arg_types.size == arg_types.size
      conformed = prv_arg_types.zip(arg_types).all? { |prv, lst|
        case
        when prv.array?   && lst.array?,
             prv.array?   && lst.pointer?,
             prv.pointer? && lst.array?
          prv.base_type == lst.base_type
        else
          prv == lst
        end
      }
    else
      conformed = false
    end

    unless conformed
      W(funcall_expr.location)
      break
    end
  end

  @funcalls[fun.name].push(arg_types)
end
prototype_declaration_of(fun) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 13645
def prototype_declaration_of(fun)
  fun.declarations_and_definitions.find do |dcl_or_def|
    dcl_or_def.kind_of?(Cc1::FunctionDeclaration)
  end
end