Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heapster-saw: Use LLVM debug information to choose permission variable names #1385

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions heapster-saw/heapster-saw.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ library
Verifier.SAW.Heapster.Parser
Verifier.SAW.Heapster.Permissions
Verifier.SAW.Heapster.PermParser
Verifier.SAW.Heapster.NamePropagation
Verifier.SAW.Heapster.RustTypes
Verifier.SAW.Heapster.SAWTranslation
Verifier.SAW.Heapster.Token
Expand Down
65 changes: 65 additions & 0 deletions heapster-saw/src/Verifier/SAW/Heapster/NamePropagation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{-# Language ScopedTypeVariables #-}
{-# Language GADTs #-}
module Verifier.SAW.Heapster.NamePropagation where

import Data.Functor.Constant
import Data.Parameterized.TraversableFC ( FoldableFC(toListFC), FunctorFC(fmapFC) )
import Lang.Crucible.Analysis.Fixpoint
import Lang.Crucible.CFG.Core ( Some(Some), CFG(cfgHandle) )
import Lang.Crucible.FunctionHandle ( FnHandle(handleArgTypes) )
import Lang.Crucible.LLVM.Extension ( LLVM, LLVMStmt(..), LLVM_Dbg(..) )
import qualified Data.Parameterized.Context as Ctx
import qualified Data.Parameterized.Map as PM
import qualified Text.LLVM.AST as L

type NameDom = Pointed (Constant String)

nameJoin :: Constant String a -> Constant String a -> NameDom a
nameJoin (Constant x) (Constant y) | x == y = Pointed (Constant x)
nameJoin _ _ = Top

nameDomain :: Domain (Pointed (Constant String))
nameDomain = pointed nameJoin (==) WTO

nameInterpretation :: Interpretation LLVM NameDom
nameInterpretation = Interpretation
{ interpExpr = \_ _ _ names -> (Just names, Bottom)
, interpCall = \_ _ _ _ _ names -> (Just names, Bottom)
, interpReadGlobal = \_ names -> (Just names, Bottom)
, interpWriteGlobal = \_ _ names -> Just names
, interpBr = \_ _ _ _ names -> (Just names, Just names)
, interpMaybe = \_ _ _ names -> (Just names, Bottom, Just names)
, interpExt = \_ stmt names ->
let names' =
case stmt of
LLVM_Debug (LLVM_Dbg_Declare ptr di _) | Just n <- L.dilvName di ->
modifyAbstractRegValue names ptr (\_ -> Pointed (Constant ("&" ++ n)))
LLVM_Debug (LLVM_Dbg_Addr ptr di _) | Just n <- L.dilvName di ->
modifyAbstractRegValue names ptr (\_ -> Pointed (Constant ("&" ++ n)))
LLVM_Debug (LLVM_Dbg_Value _ val di _) | Just n <- L.dilvName di ->
modifyAbstractRegValue names val (\_ -> Pointed (Constant n))
_ -> names
in (Just names', Bottom)
}

computeNames ::
forall blocks init ret.
CFG LLVM blocks init ret ->
Ctx.Assignment (Constant [Maybe String]) blocks
computeNames cfg =
case alg of
(_, end, _) -> fmapFC (\(Ignore (Some p)) -> Constant (toListFC flatten (_paRegisters p))) end
where
flatten :: NameDom a -> Maybe String
flatten Top = Nothing
flatten Bottom = Nothing
flatten (Pointed (Constant x)) = Just x

sz = Ctx.size (handleArgTypes (cfgHandle cfg))
alg =
forwardFixpoint'
nameDomain
nameInterpretation
cfg
PM.empty
(Ctx.replicate sz Bottom)
Loading