Skip to content

Commit 9413956

Browse files
committed
Function pointer restrictions: support labels in JSON input
This is a follow-up fix to 771a153, which added support for labels as function-pointer identifiers. That commit, however, failed to consider JSON input, and instead only resulted in support for command-line specified restrictions. Fixes: #6609
1 parent 83848a8 commit 9413956

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,14 @@ function_pointer_restrictionst::restrictionst function_pointer_restrictionst::
276276
function_pointer_restrictionst::restrictionst
277277
function_pointer_restrictionst::parse_function_pointer_restrictions_from_file(
278278
const std::list<std::string> &filenames,
279+
const goto_modelt &goto_model,
279280
message_handlert &message_handler)
280281
{
281282
auto merged_restrictions = function_pointer_restrictionst::restrictionst{};
282283

283284
for(auto const &filename : filenames)
284285
{
285-
auto const restrictions = read_from_file(filename, message_handler);
286+
auto const restrictions = read_from_file(filename, goto_model, message_handler);
286287

287288
merged_restrictions = merge_function_pointer_restrictions(
288289
std::move(merged_restrictions), restrictions.restrictions);
@@ -483,7 +484,7 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
483484
auto const restriction_file_opts =
484485
options.get_list_option(RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT);
485486
file_restrictions = parse_function_pointer_restrictions_from_file(
486-
restriction_file_opts, message_handler);
487+
restriction_file_opts, goto_model, message_handler);
487488
typecheck_function_pointer_restrictions(goto_model, file_restrictions);
488489
}
489490
catch(const invalid_restriction_exceptiont &e)
@@ -512,7 +513,9 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
512513
}
513514

514515
function_pointer_restrictionst
515-
function_pointer_restrictionst::from_json(const jsont &json)
516+
function_pointer_restrictionst::from_json(
517+
const jsont &json,
518+
const goto_modelt &goto_model)
516519
{
517520
function_pointer_restrictionst::restrictionst restrictions;
518521

@@ -523,7 +526,9 @@ function_pointer_restrictionst::from_json(const jsont &json)
523526

524527
for(auto const &restriction : to_json_object(json))
525528
{
526-
restrictions.emplace(irep_idt{restriction.first}, [&] {
529+
std::string pointer_name =
530+
resolve_pointer_name(restriction.first, goto_model);
531+
restrictions.emplace(irep_idt{pointer_name}, [&] {
527532
if(!restriction.second.is_array())
528533
{
529534
throw deserialization_exceptiont{"Value of " + restriction.first +
@@ -553,6 +558,7 @@ function_pointer_restrictionst::from_json(const jsont &json)
553558

554559
function_pointer_restrictionst function_pointer_restrictionst::read_from_file(
555560
const std::string &filename,
561+
const goto_modelt &goto_model,
556562
message_handlert &message_handler)
557563
{
558564
auto inFile = std::ifstream{filename};
@@ -564,7 +570,7 @@ function_pointer_restrictionst function_pointer_restrictionst::read_from_file(
564570
"failed to read function pointer restrictions from " + filename};
565571
}
566572

567-
return from_json(json);
573+
return from_json(json, goto_model);
568574
}
569575

570576
jsont function_pointer_restrictionst::to_json() const

src/goto-programs/restrict_function_pointers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ class function_pointer_restrictionst
9393
message_handlert &message_handler);
9494

9595
jsont to_json() const;
96-
static function_pointer_restrictionst from_json(const jsont &json);
96+
static function_pointer_restrictionst from_json(const jsont &json, const goto_modelt &goto_model);
9797

9898
static function_pointer_restrictionst read_from_file(
9999
const std::string &filename,
100+
const goto_modelt &goto_model,
100101
message_handlert &message_handler);
101102

102103
void write_to_file(const std::string &filename) const;
@@ -112,6 +113,7 @@ class function_pointer_restrictionst
112113

113114
static restrictionst parse_function_pointer_restrictions_from_file(
114115
const std::list<std::string> &filenames,
116+
const goto_modelt &goto_model,
115117
message_handlert &message_handler);
116118

117119
static restrictionst parse_function_pointer_restrictions_from_command_line(

unit/goto-programs/restrict_function_pointers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ TEST_CASE("Json conversion", "[core]")
250250
// representation for the same restrictions can differ, due to the array
251251
// elements appearing in different orders)
252252

253+
goto_modelt goto_model;
253254
std::istringstream ss(
254255
"{"
255256
" \"use_f.function_pointer_call.1\": [\"f\", \"g\"],"
@@ -262,7 +263,7 @@ TEST_CASE("Json conversion", "[core]")
262263

263264
// json1 -> restrictions1
264265
const auto function_pointer_restrictions1 =
265-
function_pointer_restrictionst::from_json(json1);
266+
function_pointer_restrictionst::from_json(json1, goto_model);
266267

267268
const auto &restrictions = function_pointer_restrictions1.restrictions;
268269

@@ -284,7 +285,7 @@ TEST_CASE("Json conversion", "[core]")
284285

285286
// json2 -> restrictions2
286287
const auto function_pointer_restrictions2 =
287-
function_pointer_restrictionst::from_json(json2);
288+
function_pointer_restrictionst::from_json(json2, goto_model);
288289

289290
REQUIRE(
290291
function_pointer_restrictions1.restrictions ==

0 commit comments

Comments
 (0)