Fix assert false when calling zero_value_of_numerical_type

Reviewed By: jvillard

Differential Revision: D3463789

fbshipit-source-id: 74a2e26
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 9
parent 9d95a3a199
commit 7f3e99c3d4

@ -663,15 +663,21 @@ let has_objc_ref_counter hpred =>
| _ => false
};
let zero_value_of_numerical_type typ =>
/** Returns the zero value of a type, for int, float and ptr types, None othwewise */
let zero_value_of_numerical_type_option typ =>
switch typ {
| Typ.Tint _ => Const (Cint IntLit.zero)
| Typ.Tfloat _ => Const (Cfloat 0.0)
| Typ.Tptr _ => Const (Cint IntLit.null)
| _ => assert false
| Typ.Tint _ => Some (Const (Cint IntLit.zero))
| Typ.Tfloat _ => Some (Const (Cfloat 0.0))
| Typ.Tptr _ => Some (Const (Cint IntLit.null))
| _ => None
};
/** Returns the zero value of a type, for int, float and ptr types, fail otherwise */
let zero_value_of_numerical_type typ => Option.get (zero_value_of_numerical_type_option typ);
/** Make a static local name in objc */
let mk_static_local_name pname vname => pname ^ "_" ^ vname;

@ -460,6 +460,12 @@ let exp_is_this: exp => bool;
let path_pos_equal: path_pos => path_pos => bool;
/** Returns the zero value of a type, for int, float and ptr types, None othwewise */
let zero_value_of_numerical_type_option: Typ.t => option exp;
/** Returns the zero value of a type, for int, float and ptr types, fail otherwise */
let zero_value_of_numerical_type: Typ.t => exp;

@ -1599,8 +1599,11 @@ struct
initListExpr_initializers_trans trans_state var_exp 0 stmts typ false stmt_info in
let rh_exps = collect_exprs res_trans_subexpr_list in
if IList.length rh_exps == 0 then
let exp = Sil.zero_value_of_numerical_type var_type in
{ empty_res_trans with root_nodes = trans_state.succ_nodes; exps = [(exp, typ)]; }
let exps =
match Sil.zero_value_of_numerical_type_option var_type with
| Some zero_exp -> [(zero_exp, typ)]
| None -> [] in
{ empty_res_trans with root_nodes = trans_state.succ_nodes; exps = exps; }
else
(* For arrays, the size in the type may be an overapproximation of the number *)
(* of literals the array is initialized with *)

Loading…
Cancel
Save