Repository navigation
Open
Description
RMC is a new Rust front-end for CBMC. Currently, it uses the C mode in the symbol-table. We propose adding a Rust mode to symbols. For now, this mode would have the same semantics as C, but would allow us to distinguish rust code from C code. This is particularly important as Rust support linking C code using a FFI, which we need to support in RMC.
Benefits
- Allows tools which consume CBMC output to know which language the initial source code was in. For example, when giving a failure trace that includes both Rust and C code, it would be valuable to the trace visualizer to know which language the statements originally came from
- Allows the backend to implement different semantics for the different languages. For example (maybe not the best one), one could imagine a case where one language wants unsigned addition to wrap around, while another wants it to saturate.
- Allows the addition of language specific checks. For example, Rust has areas of UB which are not defined as such in C - it may be useful to have checks which are only automatically inserted into the Rust side of a linked Rust/C binary.
Design considerations
Rust is not the only language that would benefit from this. Any new language front-end will likely see the same issues we are, and could benefit from a principled mechanism to alleviate them.
Links and documentation
Line 49 in 1ab5de1
| irep_idt mode; |
Currently, CBMC appears to have the following langauges:
cbmc/src/cbmc/cbmc_languages.cpp
Lines 25 to 35 in 4889328
| void cbmc_parse_optionst::register_languages() | |
| { | |
| register_language(new_ansi_c_language); | |
| register_language(new_statement_list_language); | |
| register_language(new_cpp_language); | |
| register_language(new_json_symtab_language); | |
| #ifdef HAVE_JSIL | |
| register_language(new_jsil_language); | |
| #endif | |
| } |
Activity
martin-cs commentedon Jul 9, 2021
If we are adding this then it would also be good to have these for Ada for the https://github.com/diffblue/gnat2goto/ front-end which is currently also using the
Cmode.kroening commentedon Jul 9, 2021
The expected pattern for this (Rust or Ada) is to set up a separate executable, with specialised command-line options. The executable then registers the relevant languages using the
register_languageAPI.Look at
jbmcas an exemplar.martin-cs commentedon Jul 9, 2021
Both of them use the
json_symtablanguage which is already supported.martin-cs commentedon Jul 9, 2021
I guess more generally; for languages that are using the
json_symtabinterface, what shouldmodebe set to?gnat2goto(and I thinkRMC) both lie and set the mode to "C".peterschrammel commentedon Jul 13, 2021
a. I'm with @martin-cs on this one:
json_symtabshouldn't be a 'language', but it should have 'mode' property.b. The issue is that
register_languageregisters a front-end implementation for handling certain input files, which is a slightly different concept than 'language'.c. Having a separate executable is preferable if language-specific options are required or the command line is adapted to seamlessly fit into the language-specific environment (like
jbmcsupporting the command line syntax ofjava), but this is somewhat orthogonal.But back to points 1, 2, 3:
exprt(like @kroening has recently done for the remainder operations) and then translate them to the right primitives in the frontend.goto_check, which requires 1 and c. This could be avoided by inserting them in the frontend - likely depends on the particular checks. Language-specific cases ingoto-checkare not the right mechanism IMO.TGWDB commentedon Jul 14, 2021
Taking into account the comments and discussion above, would a reasonable choice be as follows.
To support the handling of rust in displays and mixed input (i.e. a goto binary comprising of a mixture of
Candrust:json_symtab"language" to have amodeproperty.json_symtabmodes forID_CandID_Rust.Then for semantic differences between the languages and different language checks:
cbmc's capabilities to handle these new semantics (as mentioned by @peterschrammel and done by @kroening for other semantics). These can be done for the semantics desired, but not tied to a specific language or language mode (i.e. one could use them in any language).gnat2gotoandrmc) to handle the insertion of correct checks orgotoprograms that use the above new semantics.Comments/feedback very welcome!
martin-cs commentedon Jul 14, 2021
@TGWDB I agree with splitting this in two (getting the correct
modeand then how and where you do language-specific things) and with the general principle thatmodeshould be correct (i.e. we should haveID_C,ID_cpp,ID_java,ID_rust,ID_ada, etc.). However may I raise a few concerns with your plan:The mode is compared to the output of the
id()method:cbmc/src/langapi/mode.cpp
Line 45 in 10ddca0
which for
json_symtabis:cbmc/src/json-symtab-language/json_symtab_language.h
Line 41 in 10ddca0
it is not clear to me what this should be set to.
modeis used in two ways, it is either checked directly in language specific bits of code (actually pretty rare; searching forID_javaorID_cppshows this) or it is used bysrc/langapi/mode.hto get the relevantlanguagetmostly for output viasrc/langapi/language_util.h.Sounds good.
I get the principle and the whole point of a modular framework is so that we can have lots of different executables, so that is good. I have a slight concern about how we handle mixed language goto-programs, which is a desirable goal for both Ada and Rust ( @danielsn ? ).
As far as I can see there are two ways of resolving this and #6223 .
Simple fix approach : inherit from
json_symtab_languagetto createrust_languagetandada_languagetwhich haveid()s ofID_rustandID_adarespectively and implementfrom_type()andfrom_expr()etc.symtab2gbthen loads all of these language front-ends and possibly the C front-end as well for good measure.More involved but fuller solution : split
languagetinto two, one part for front-end, parsing and type checking and one part for language-specific support and output. Implement just the second part forID_rustandID_ada. Load the language-specific support and output for all languages in all tools. The front-end part stays the same in all tools, includingsymtab2gbwhich only needsjson_symtabsupport.HTH
chrisr-diffblue commentedon Jul 20, 2021
I think I agree with most of the points raised by @peterschrammel @TGWDB and @martin-cs - in particular, I do quite like the idea of splitting
languagetinto explicit "front-end/reporting" and "output/reporting/mid-end/back-end" - that I think enablesjson_symtabto remain a fairly focused, language-agnostic "intermediate representation" rather than having bits of ad-hoc language specific knowledge bolted on.martin-cs commentedon Jul 20, 2021
@TGWDB any feel for a time-frame on this one? If it is soon then I won't merge #6233
danielsn commentedon Jul 21, 2021
@martin-cs I also like the idea of splitting into front-end and back-end parts.
martin-cs commentedon Jul 27, 2021
@TGWDB sorry to hassle but you are assigned as the owner for this. I need to #6223 resolved ASAP. #6233 will do it but I really don't want to merge it because it is a work-around. If you are going to resolve this in the next 24-48 hours then I won't merge #6233 .
Also @chrisr-diffblue and @peterschrammel for general interest.
TGWDB commentedon Jul 27, 2021
@martin-cs I cannot promise resolution in 24-48 hours so I propose you go ahead with #6233.
martin-cs commentedon Jul 27, 2021
@TGWDB thanks for the fast response.