Skip to content

Commit 3289add

Browse files
authored
Merge pull request #7645 from NlightNFotis/rust_verification_result
Translate verification results from C++ to Rust
2 parents 193b2fd + a1eb073 commit 3289add

File tree

7 files changed

+388
-69
lines changed

7 files changed

+388
-69
lines changed

src/libcprover-cpp/api.cpp

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -133,57 +133,7 @@ void api_sessiont::load_model_from_files(
133133
files, *implementation->message_handler, *implementation->options));
134134
}
135135

136-
void api_sessiont::verify_model() const
137-
{
138-
PRECONDITION(implementation->model);
139-
140-
// Remove inline assembler; this needs to happen before adding the library.
141-
remove_asm(*implementation->model);
142-
143-
// add the library
144-
messaget log{*implementation->message_handler};
145-
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
146-
<< messaget::eom;
147-
link_to_library(
148-
*implementation->model,
149-
*implementation->message_handler,
150-
cprover_c_library_factory);
151-
152-
// Common removal of types and complex constructs
153-
if(::process_goto_program(
154-
*implementation->model, *implementation->options, log))
155-
{
156-
return;
157-
}
158-
159-
// add failed symbols
160-
// needs to be done before pointer analysis
161-
add_failed_symbols(implementation->model->symbol_table);
162-
163-
// label the assertions
164-
// This must be done after adding assertions and
165-
// before using the argument of the "property" option.
166-
// Do not re-label after using the property slicer because
167-
// this would cause the property identifiers to change.
168-
label_properties(*implementation->model);
169-
170-
remove_skip(*implementation->model);
171-
172-
ui_message_handlert ui_message_handler(*implementation->message_handler);
173-
all_properties_verifier_with_trace_storaget<multi_path_symex_checkert>
174-
verifier(
175-
*implementation->options, ui_message_handler, *implementation->model);
176-
(void)verifier();
177-
verifier.report();
178-
}
179-
180-
// TODO: This is a temporary function - it's basically `verify_model`, tweaked
181-
// to return the results in a structured format. It's temporary in the sense
182-
// that this will get folded into the `verify_model` function, but I want to do
183-
// this slightly later because modifying the interface of `verify_model` from
184-
// the C++ end breaks the Rust API for now, and I want to take steps one at
185-
// a time.
186-
verification_resultt api_sessiont::produce_results()
136+
std::unique_ptr<verification_resultt> api_sessiont::verify_model() const
187137
{
188138
PRECONDITION(implementation->model);
189139

@@ -225,10 +175,13 @@ verification_resultt api_sessiont::produce_results()
225175
*implementation->options, ui_message_handler, *implementation->model);
226176
verification_resultt result;
227177
auto results = verifier();
178+
// Print messages collected to callback buffer.
179+
verifier.report();
180+
// Set results object before returning.
228181
result.set_result(results);
229182
auto properties = verifier.get_properties();
230183
result.set_properties(properties);
231-
return result;
184+
return util_make_unique<verification_resultt>(result);
232185
}
233186

234187
void api_sessiont::drop_unused_functions() const

src/libcprover-cpp/api.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ struct api_sessiont
6969
/// \param files: A vector<string> containing the filenames to be loaded
7070
void load_model_from_files(const std::vector<std::string> &files) const;
7171

72-
/// Verify previously loaded model.
73-
void verify_model() const;
72+
// Run the verification engine against previously loaded model and return
73+
// results object pointer.
74+
std::unique_ptr<verification_resultt> verify_model() const;
7475

7576
/// Drop unused functions from the loaded goto_model simplifying it
7677
void drop_unused_functions() const;
@@ -81,9 +82,6 @@ struct api_sessiont
8182
// A simple API version information function.
8283
std::unique_ptr<std::string> get_api_version() const;
8384

84-
/// Run the verification engine and return results.
85-
verification_resultt produce_results();
86-
8785
private:
8886
std::unique_ptr<api_session_implementationt> implementation;
8987
};

src/libcprover-rust/include/c_api.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <memory>
6+
#include <stdexcept>
67
#include <string>
78

89
// NOLINTNEXTLINE(build/include)
@@ -11,6 +12,9 @@
1112
#include "include/c_errors.h"
1213

1314
struct api_sessiont;
15+
struct verification_resultt;
16+
enum class verifier_resultt;
17+
enum class prop_statust;
1418

1519
// Helper function
1620
std::vector<std::string> const &
@@ -20,6 +24,18 @@ _translate_vector_of_string(rust::Vec<rust::String> elements);
2024
std::unique_ptr<api_sessiont> new_api_session();
2125
std::vector<std::string> const &get_messages();
2226

27+
// Exposure of verification result related functions.
28+
verifier_resultt
29+
get_verification_result(const std::unique_ptr<verification_resultt> &v);
30+
std::vector<std::string> const &
31+
get_property_ids(const std::unique_ptr<verification_resultt> &);
32+
std::string const &get_property_description(
33+
const std::unique_ptr<verification_resultt> &,
34+
const std::string &);
35+
prop_statust get_property_status(
36+
const std::unique_ptr<verification_resultt> &,
37+
const std::string &);
38+
2339
// NOLINTNEXTLINE(readability/namespace)
2440
namespace rust
2541
{
@@ -41,6 +57,16 @@ static void trycatch(Try &&func, Fail &&fail) noexcept
4157
{
4258
fail(i.what());
4359
}
60+
catch(const std::out_of_range &our)
61+
{
62+
fail(our.what());
63+
}
64+
catch(const std::exception &exc)
65+
{
66+
// collective catch-all for all exceptions that derive
67+
// from standard exception class.
68+
fail(exc.what());
69+
}
4470
}
4571

4672
} // namespace behavior

src/libcprover-rust/include/c_errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include <string>
6+
57
// The following type is cloning two types from the `util/exception_utils.h` and
68
// `util/invariant.h` files.
79
//

src/libcprover-rust/src/c_api.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,33 @@ std::vector<std::string> const &get_messages()
5959
{
6060
return output;
6161
}
62+
63+
verifier_resultt get_verification_result(
64+
const std::unique_ptr<verification_resultt> &verifier_result)
65+
{
66+
return verifier_result->final_result();
67+
}
68+
69+
std::vector<std::string> const &
70+
get_property_ids(const std::unique_ptr<verification_resultt> &verifier_result)
71+
{
72+
std::vector<std::string> *property_ids = new std::vector<std::string>();
73+
*property_ids = verifier_result->get_property_ids();
74+
return *property_ids;
75+
}
76+
77+
std::string const &get_property_description(
78+
const std::unique_ptr<verification_resultt> &verifier_result,
79+
const std::string &property_id)
80+
{
81+
std::string *description = new std::string();
82+
*description = verifier_result->get_property_description(property_id);
83+
return *description;
84+
}
85+
86+
prop_statust get_property_status(
87+
const std::unique_ptr<verification_resultt> &verifier_result,
88+
const std::string &property_id)
89+
{
90+
return verifier_result->get_property_status(property_id);
91+
}

0 commit comments

Comments
 (0)