@@ -3601,11 +3601,19 @@ tcEmitLLVMStmt _arch _ctx _loc stmt =
3601
3601
-- * Permission Checking for Jump Targets and Termination Statements
3602
3602
----------------------------------------------------------------------
3603
3603
3604
- -- | Cast the primary permission for @x@ using any equality permissions in scope
3605
- castPermForVar :: NuMatchingAny1 r => ExprVar a -> ImplM vars s r RNil RNil ()
3606
- castPermForVar x =
3604
+ -- | Cast the primary permission for @x@ using any equality permissions on
3605
+ -- variables *not* in the supplied list of determined variables. The idea here
3606
+ -- is that we are trying to simplify out and remove un-determined variables.
3607
+ castUnDetVarsForVar :: NuMatchingAny1 r => NameSet CrucibleType -> ExprVar a ->
3608
+ ImplM vars s r RNil RNil ()
3609
+ castUnDetVarsForVar det_vars x =
3610
+ (view varPermMap <$> getPerms) >>>= \ var_perm_map ->
3607
3611
getPerm x >>>= \ p ->
3608
- substEqsWithProof p >>>= \ eqp ->
3612
+ let nondet_perms =
3613
+ NameMap. fromList $
3614
+ filter (\ (NameMap. NameAndElem y _) -> not $ NameSet. member y det_vars) $
3615
+ NameMap. assocs var_perm_map in
3616
+ let eqp = someEqProofFromSubst nondet_perms p in
3609
3617
implPushM x p >>>
3610
3618
implCastPermM x eqp >>>
3611
3619
implPopM x (someEqProofRHS eqp)
@@ -3657,6 +3665,13 @@ simplify1PermForDetVars det_vars l (ValPerm_LOwned ls _ _)
3657
3665
simplify1PermForDetVars det_vars _ p
3658
3666
| nameSetIsSubsetOf (freeVars p) det_vars = pure ()
3659
3667
3668
+ -- If p is an equality permission to a word with undetermined variables,
3669
+ -- existentially quantify over the word
3670
+ simplify1PermForDetVars _ x p@ (ValPerm_Eq (PExpr_LLVMWord e)) =
3671
+ let mb_p = nu $ \ z -> ValPerm_Eq $ PExpr_LLVMWord $ PExpr_Var z in
3672
+ implPushM x p >>> introExistsM x e mb_p >>>
3673
+ implPopM x (ValPerm_Exists mb_p)
3674
+
3660
3675
-- Otherwise, drop p, because it is not determined
3661
3676
simplify1PermForDetVars _det_vars x p =
3662
3677
implPushM x p >>> implDropM x p
@@ -3670,7 +3685,7 @@ simplifyPermsForDetVars det_vars_list =
3670
3685
let det_vars = NameSet. fromList det_vars_list in
3671
3686
(permSetVars <$> getPerms) >>>= \ vars ->
3672
3687
mapM_ (\ (SomeName x) ->
3673
- castPermForVar x >>>
3688
+ castUnDetVarsForVar det_vars x >>>
3674
3689
getPerm x >>>= simplify1PermForDetVars det_vars x) vars
3675
3690
3676
3691
0 commit comments