diff --git a/infer/src/IR/Sil.re b/infer/src/IR/Sil.re index 195df5a18..f2da0e9b9 100644 --- a/infer/src/IR/Sil.re +++ b/infer/src/IR/Sil.re @@ -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; diff --git a/infer/src/IR/Sil.rei b/infer/src/IR/Sil.rei index 71417e6f1..a9f9f52c3 100644 --- a/infer/src/IR/Sil.rei +++ b/infer/src/IR/Sil.rei @@ -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; diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 5f2a9a111..76a65ad9e 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -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 *)