Skip to content

Commit

Permalink
Warn & document mismatching CBMC version (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
NatKarmios authored Aug 5, 2024
1 parent 0460dce commit cff2c70
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions GillianCore/lib/gillian.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ module Logging = struct
Use this when you need a pretty printer,
but don't expect it to actually be seen anywhere *)
let dummy_pp = dummy_pp

(** Prints a message to all available reporters, and stdout if applicable. *)
let print_to_all = print_to_all
end

module IncrementalAnalysis = IncrementalAnalysis
Expand Down
1 change: 1 addition & 0 deletions kanillian/CBMC_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.14.3
28 changes: 28 additions & 0 deletions kanillian/lib/KParserAndCompiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,35 @@ let create_compilation_result path goto_prog gil_prog =
init_data = ();
}

let cbmc_version_checked = ref false

let check_cbmc_version () =
if not !cbmc_version_checked then
let () = cbmc_version_checked := true in
let expected_cbmc_version = Cbmc_version.expected in
let cbmc_version =
let inp = Unix.open_process_in "cbmc --version" in
let r = In_channel.input_all inp in
let () =
match Unix.close_process_in inp with
| Unix.WEXITED 0 -> ()
| _ ->
failwith
"Failed to check CBMC version! Make sure CBMC is installed."
in
r |> String.trim |> String.split_on_char ' ' |> List.hd
in
if cbmc_version <> expected_cbmc_version then
let msg =
Fmt.str
"WARNING: expected CBMC version %s, but found %s. There may be \
consequences!"
expected_cbmc_version cbmc_version
in
Logging.print_to_all msg

let compile_c_to_symtab c_file =
let () = check_cbmc_version () in
let symtab_file = c_file ^ ".symtab.json" in
let status =
Sys.command
Expand Down
9 changes: 9 additions & 0 deletions kanillian/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
dune-site)
(flags :standard -open Goto_lib))

(rule
(target cbmc_version.ml)
(deps
(file ../CBMC_VERSION))
(action
(with-stdout-to
%{target}
(bash "echo let expected = \\\"$(cat %{deps})\\\""))))

(generate_sites_module
(module runtime_sites)
(sites kanillian))
7 changes: 7 additions & 0 deletions sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False

cbmc_version = None
with open("../kanillian/CBMC_VERSION", "r") as f:
cbmc_version = f.read().strip()
# https://stackoverflow.com/a/39214302
rst_epilog = f"""
.. |cbmc_version| replace:: {cbmc_version}
"""

# -- Options for HTML output ----------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Welcome to Gillian

c/index
js/index
kanillian/index

.. toctree::
:titlesonly:
Expand Down
14 changes: 14 additions & 0 deletions sphinx/kanillian/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Kanillian (New Gillian-C)
=========================

.. danger::

Kanillian is currently in development and unstable.

Kanillian is a new instantiation of Gillian to the C language (or more precisely, CBMC's `GOTO-C <https://diffblue.github.io/cbmc/group__goto-programs.html>`_). It can be found in the ``kanillian`` folder of the repository.

Kanillian requires CBMC to be present on your path.

.. attention::

Kanillian is currently built to work with CBMC version |cbmc_version| - newer versions are known to cause problems.

0 comments on commit cff2c70

Please sign in to comment.