Skip to content

Commit a648349

Browse files
authored
Merge pull request #1531 from GaloisInc/heapster/freshen-llvm-globals
Heapster: freshen LLVM global names
2 parents d8d4776 + d69969c commit a648349

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

heapster-saw/src/Verifier/SAW/Heapster/LLVMGlobalConst.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ permEnvAddGlobalConst sc mod_name dlevel endianness w env global =
231231
case translateLLVMValueTop dlevel endianness w env global of
232232
Nothing -> return env
233233
Just (sh, t) ->
234-
do let ident = mkSafeIdent mod_name $ show $ L.globalSym global
234+
do ident <-
235+
scFreshenGlobalIdent sc $
236+
mkSafeIdent mod_name $ show $ L.globalSym global
235237
complete_t <- completeOpenTerm sc t
236238
tp <- completeOpenTermType sc t
237239
scInsertDef sc mod_name ident tp complete_t

saw-core/src/Verifier/SAW/SharedTerm.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module Verifier.SAW.SharedTerm
7070
, scExtCns
7171
, scGlobalDef
7272
, scRegisterGlobal
73+
, scFreshenGlobalIdent
7374
-- ** Recursors and datatypes
7475
, scRecursorElimTypes
7576
, scRecursorRetTypeType
@@ -269,7 +270,7 @@ import Control.Lens
269270
import Control.Monad.State.Strict as State
270271
import Control.Monad.Reader
271272
import Data.Bits
272-
import Data.List (inits)
273+
import Data.List (inits, find)
273274
import Data.Maybe
274275
import qualified Data.Foldable as Fold
275276
import Data.Foldable (foldl', foldlM, foldrM, maximum)
@@ -441,6 +442,16 @@ scRegisterGlobal sc ident t =
441442
Just _ -> (m, True)
442443
Nothing -> (HMap.insert ident t m, False)
443444

445+
-- | Find a variant of an identifier that is not already being used as a global,
446+
-- by possibly adding a numeric suffix
447+
scFreshenGlobalIdent :: SharedContext -> Ident -> IO Ident
448+
scFreshenGlobalIdent sc ident =
449+
readIORef (scGlobalEnv sc) >>= \gmap ->
450+
return $ fromJust $ find (\i -> not $ HMap.member i gmap) $
451+
ident : map (mkIdent (identModule ident) .
452+
Text.append (identBaseName ident) .
453+
Text.pack . show) [(0::Integer) ..]
454+
444455
-- | Create a function application term.
445456
scApply :: SharedContext
446457
-> Term -- ^ The function to apply

0 commit comments

Comments
 (0)