From f386f74b3b963b399b61c69c30298d6afc411a45 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 18 Jun 2015 22:28:25 +0200 Subject: [PATCH] [analyzer] allow inlining unsafe casts --- analyzer.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/analyzer.ml b/analyzer.ml index 32b0bc8cb31..daa66be2f1e 100644 --- a/analyzer.ml +++ b/analyzer.ml @@ -1041,7 +1041,7 @@ module ConstPropagation = struct with Not_found -> -1 - let can_be_inlined com v0 e = type_iseq v0.v_type e.etype && match e.eexpr with + let rec can_be_inlined com v0 e = type_iseq v0.v_type e.etype && match e.eexpr with | TConst ct -> begin match ct with | TThis | TSuper -> false @@ -1065,6 +1065,9 @@ module ConstPropagation = struct Ssa.get_var_usage_count v0 <= 1 | TField(_,FEnum _) -> Ssa.get_var_usage_count v0 <= 1 + | TCast(e1,None) -> + (* We can inline an unsafe cast if the variable is only used once. *) + can_be_inlined com v0 {e1 with etype = e.etype} && Ssa.get_var_usage_count v0 <= 1 | _ -> false