Skip to content

Commit c9e8b87

Browse files
committed
Use *WithWarnings functions from llvm-pretty-bc-parser
This bumps the `llvm-pretty-bc-parser` submodule to bring in the changes from GaloisInc/llvm-pretty-bc-parser#282 (as well as the knock-on changes on the `crucible` side in GaloisInc/crucible#1313). It also updates the code to use the `*WithWarnings` variants of bitcode parsing functions. For now, we simply print parse warnings using the established mechanisms in `saw-script` and `saw-remote-api`, although there is a broader question of whether we should be using something more systematized to print these warnings (#2129).
1 parent 3a591c1 commit c9e8b87

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ This release supports [version
2626
helps ensure that unsupported `mir-json` files do not cause unintended
2727
results.
2828

29+
* Emit a warning when parsing an LLVM bitcode metadata record that SAW
30+
does not support. (Previously, SAW would throw a fatal error if this
31+
occurred, so this change makes SAW more permissive with respect to
32+
unsupported LLVM versions.)
33+
2934
## Bug fixes
3035

3136
* The saw executable's usage message now fits into a terminal. (#405)

saw-remote-api/src/SAWServer/LLVMCrucibleSetup.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module SAWServer.LLVMCrucibleSetup
2121

2222
import Control.Exception (throw)
2323
import Control.Lens ( view )
24+
import Control.Monad (unless)
2425
import Control.Monad.IO.Class
2526
import Data.Aeson (FromJSON(..), withObject, (.:))
2627
import Data.ByteString (ByteString)
@@ -260,7 +261,11 @@ llvmLoadModule (LLVMLoadModuleParams serverName fileName) =
260261
loaded <- liftIO (CMS.loadLLVMModule fileName halloc)
261262
case loaded of
262263
Left err -> Argo.raise (cantLoadLLVMModule (LLVM.formatError err))
263-
Right llvmMod ->
264-
do setServerVal serverName llvmMod
264+
Right (llvmMod, warnings) ->
265+
do -- TODO: Printing warnings directly to stdout here is
266+
-- questionable (#2129)
267+
unless (null warnings) $
268+
liftIO $ print $ LLVM.ppParseWarnings warnings
269+
setServerVal serverName llvmMod
265270
trackFile fileName
266271
ok

src/SAWScript/Crucible/LLVM/Setup/Value.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import Control.Lens
8484
import Data.Map ( Map )
8585
import qualified Data.Map as Map
8686
import Data.Maybe
87+
import Data.Sequence (Seq)
8788
import qualified Data.Text as Text
8889
import Data.Type.Equality (TestEquality(..))
8990
import Data.Void (Void)
@@ -215,15 +216,15 @@ loadLLVMModule ::
215216
(?transOpts :: CL.TranslationOptions) =>
216217
FilePath ->
217218
Crucible.HandleAllocator ->
218-
IO (Either LLVM.Error (Some LLVMModule))
219+
IO (Either LLVM.Error (Some LLVMModule, Seq LLVM.ParseWarning))
219220
loadLLVMModule file halloc =
220-
do parseResult <- LLVM.parseBitCodeFromFile file
221+
do parseResult <- LLVM.parseBitCodeFromFileWithWarnings file
221222
case parseResult of
222223
Left err -> return (Left err)
223-
Right llvm_mod ->
224+
Right (llvm_mod, warnings) ->
224225
do memVar <- CL.mkMemVar (Text.pack "saw:llvm_memory") halloc
225226
Some mtrans <- CL.translateModule halloc memVar llvm_mod
226-
return (Right (Some (LLVMModule file llvm_mod mtrans)))
227+
return (Right (Some (LLVMModule file llvm_mod mtrans), warnings))
227228

228229
instance TestEquality LLVMModule where
229230
-- As 'LLVMModule' is an abstract type, we know that the values must

src/SAWScript/LLVMBuiltins.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ import Control.Applicative hiding (many)
2424
#endif
2525
import Data.String
2626
import Data.Parameterized.Some
27+
import Control.Monad (unless)
2728
import Control.Monad.State (gets)
2829

2930
import qualified Text.LLVM.AST as LLVM
3031
import qualified Data.LLVM.BitCode as LLVM
3132
import qualified Text.LLVM.Parser as LLVM (parseType)
3233

33-
import SAWScript.Value as SV
34-
3534
import qualified SAWScript.Crucible.LLVM.CrucibleLLVM as CL
3635
import qualified SAWScript.Crucible.LLVM.MethodSpecIR as CMS (LLVMModule, loadLLVMModule)
36+
import SAWScript.Options
37+
import SAWScript.Value as SV
3738

3839
llvm_load_module :: FilePath -> TopLevel (Some CMS.LLVMModule)
3940
llvm_load_module file =
@@ -46,7 +47,10 @@ llvm_load_module file =
4647
halloc <- getHandleAlloc
4748
io (CMS.loadLLVMModule file halloc) >>= \case
4849
Left err -> fail (LLVM.formatError err)
49-
Right llvm_mod -> return llvm_mod
50+
Right (llvm_mod, warnings) -> do
51+
unless (null warnings) $
52+
printOutLnTop Warn $ show $ LLVM.ppParseWarnings warnings
53+
return llvm_mod
5054

5155
llvm_type :: String -> TopLevel LLVM.Type
5256
llvm_type str =

0 commit comments

Comments
 (0)