Skip to content

Commit

Permalink
Merge pull request #1531 from GaloisInc/heapster/freshen-llvm-globals
Browse files Browse the repository at this point in the history
Heapster: freshen LLVM global names
  • Loading branch information
mergify[bot] authored Dec 3, 2021
2 parents d8d4776 + d69969c commit a648349
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion heapster-saw/src/Verifier/SAW/Heapster/LLVMGlobalConst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ permEnvAddGlobalConst sc mod_name dlevel endianness w env global =
case translateLLVMValueTop dlevel endianness w env global of
Nothing -> return env
Just (sh, t) ->
do let ident = mkSafeIdent mod_name $ show $ L.globalSym global
do ident <-
scFreshenGlobalIdent sc $
mkSafeIdent mod_name $ show $ L.globalSym global
complete_t <- completeOpenTerm sc t
tp <- completeOpenTermType sc t
scInsertDef sc mod_name ident tp complete_t
Expand Down
13 changes: 12 additions & 1 deletion saw-core/src/Verifier/SAW/SharedTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module Verifier.SAW.SharedTerm
, scExtCns
, scGlobalDef
, scRegisterGlobal
, scFreshenGlobalIdent
-- ** Recursors and datatypes
, scRecursorElimTypes
, scRecursorRetTypeType
Expand Down Expand Up @@ -269,7 +270,7 @@ import Control.Lens
import Control.Monad.State.Strict as State
import Control.Monad.Reader
import Data.Bits
import Data.List (inits)
import Data.List (inits, find)
import Data.Maybe
import qualified Data.Foldable as Fold
import Data.Foldable (foldl', foldlM, foldrM, maximum)
Expand Down Expand Up @@ -441,6 +442,16 @@ scRegisterGlobal sc ident t =
Just _ -> (m, True)
Nothing -> (HMap.insert ident t m, False)

-- | Find a variant of an identifier that is not already being used as a global,
-- by possibly adding a numeric suffix
scFreshenGlobalIdent :: SharedContext -> Ident -> IO Ident
scFreshenGlobalIdent sc ident =
readIORef (scGlobalEnv sc) >>= \gmap ->
return $ fromJust $ find (\i -> not $ HMap.member i gmap) $
ident : map (mkIdent (identModule ident) .
Text.append (identBaseName ident) .
Text.pack . show) [(0::Integer) ..]

-- | Create a function application term.
scApply :: SharedContext
-> Term -- ^ The function to apply
Expand Down

0 comments on commit a648349

Please sign in to comment.