Skip to content

Commit c0270a4

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 0d8e005 commit c0270a4

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--function-pointer-restrictions-file restriction.json
4+
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) == 11: SUCCESS
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This test checks that the function f is called for the first function pointer
10+
call in function use_f when using the label to refer to the call site, with the
11+
restriction described in the JSON file instead of the command-line directly.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"use_f.labelled_call":[
3+
"f"
4+
]
5+
}

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,15 @@ 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 =
287+
read_from_file(filename, goto_model, message_handler);
286288

287289
merged_restrictions = merge_function_pointer_restrictions(
288290
std::move(merged_restrictions), restrictions.restrictions);
@@ -487,7 +489,7 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
487489
auto const restriction_file_opts =
488490
options.get_list_option(RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT);
489491
file_restrictions = parse_function_pointer_restrictions_from_file(
490-
restriction_file_opts, message_handler);
492+
restriction_file_opts, goto_model, message_handler);
491493
typecheck_function_pointer_restrictions(goto_model, file_restrictions);
492494
}
493495
catch(const invalid_restriction_exceptiont &e)
@@ -515,8 +517,9 @@ function_pointer_restrictionst function_pointer_restrictionst::from_options(
515517
merge_function_pointer_restrictions(file_restrictions, name_restrictions))};
516518
}
517519

518-
function_pointer_restrictionst
519-
function_pointer_restrictionst::from_json(const jsont &json)
520+
function_pointer_restrictionst function_pointer_restrictionst::from_json(
521+
const jsont &json,
522+
const goto_modelt &goto_model)
520523
{
521524
function_pointer_restrictionst::restrictionst restrictions;
522525

@@ -527,7 +530,9 @@ function_pointer_restrictionst::from_json(const jsont &json)
527530

528531
for(auto const &restriction : to_json_object(json))
529532
{
530-
restrictions.emplace(irep_idt{restriction.first}, [&] {
533+
std::string pointer_name =
534+
resolve_pointer_name(restriction.first, goto_model);
535+
restrictions.emplace(irep_idt{pointer_name}, [&] {
531536
if(!restriction.second.is_array())
532537
{
533538
throw deserialization_exceptiont{"Value of " + restriction.first +
@@ -557,6 +562,7 @@ function_pointer_restrictionst::from_json(const jsont &json)
557562

558563
function_pointer_restrictionst function_pointer_restrictionst::read_from_file(
559564
const std::string &filename,
565+
const goto_modelt &goto_model,
560566
message_handlert &message_handler)
561567
{
562568
auto inFile = std::ifstream{filename};
@@ -568,7 +574,7 @@ function_pointer_restrictionst function_pointer_restrictionst::read_from_file(
568574
"failed to read function pointer restrictions from " + filename};
569575
}
570576

571-
return from_json(json);
577+
return from_json(json, goto_model);
572578
}
573579

574580
jsont function_pointer_restrictionst::to_json() const

src/goto-programs/restrict_function_pointers.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ 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
97+
from_json(const jsont &json, const goto_modelt &goto_model);
9798

9899
static function_pointer_restrictionst read_from_file(
99100
const std::string &filename,
101+
const goto_modelt &goto_model,
100102
message_handlert &message_handler);
101103

102104
void write_to_file(const std::string &filename) const;
@@ -112,6 +114,7 @@ class function_pointer_restrictionst
112114

113115
static restrictionst parse_function_pointer_restrictions_from_file(
114116
const std::list<std::string> &filenames,
117+
const goto_modelt &goto_model,
115118
message_handlert &message_handler);
116119

117120
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)