Skip to content

Commit dbe9f09

Browse files
committed
dump-c: Try to guess further system headers
1 parent ff1d994 commit dbe9f09

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* GOTO-ANALYZER: New option --unreachable-functions, --reachable-functions
99
* GOTO-INSTRUMENT: New option --undefined-function-is-assume-false
1010
* GOTO-INSTRUMENT: New option --remove-function-body
11+
* GOTO-INSTRUMENT: New option --use-all-headers
1112

1213

1314
5.7

src/clobber/clobber_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int clobber_parse_optionst::doit()
146146
if(!out)
147147
throw std::string("failed to create file simulator.c");
148148

149-
dump_c(goto_functions, true, ns, out);
149+
dump_c(goto_functions, true, false, ns, out);
150150

151151
status() << "instrumentation complete; compile and execute simulator.c"
152152
<< eom;

src/goto-instrument/dump_c.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,7 @@ bool dump_ct::ignore(const symbolt &symbol)
732732
const std::string &file_str=id2string(symbol.location.get_file());
733733

734734
// don't dump internal GCC builtins
735-
if((file_str=="gcc_builtin_headers_alpha.h" ||
736-
file_str=="gcc_builtin_headers_arm.h" ||
737-
file_str=="gcc_builtin_headers_ia32.h" ||
738-
file_str=="gcc_builtin_headers_mips.h" ||
739-
file_str=="gcc_builtin_headers_power.h" ||
740-
file_str=="gcc_builtin_headers_generic.h") &&
735+
if(has_prefix(file_str, "gcc_builtin_headers_") &&
741736
has_prefix(name_str, "__builtin_"))
742737
return true;
743738

@@ -761,6 +756,19 @@ bool dump_ct::ignore(const symbolt &symbol)
761756
return true;
762757
}
763758

759+
if(use_all_headers &&
760+
has_prefix(file_str, "/usr/include/"))
761+
{
762+
if(file_str.find("/bits/")==std::string::npos)
763+
{
764+
// Do not include transitive includes of system headers!
765+
std::string::size_type prefix_len=std::string("/usr/include/").size();
766+
system_headers.insert(file_str.substr(prefix_len));
767+
}
768+
769+
return true;
770+
}
771+
764772
return false;
765773
}
766774

@@ -1278,19 +1286,23 @@ std::string dump_ct::expr_to_string(const exprt &expr)
12781286
void dump_c(
12791287
const goto_functionst &src,
12801288
const bool use_system_headers,
1289+
const bool use_all_headers,
12811290
const namespacet &ns,
12821291
std::ostream &out)
12831292
{
1284-
dump_ct goto2c(src, use_system_headers, ns, new_ansi_c_language);
1293+
dump_ct goto2c(
1294+
src, use_system_headers, use_all_headers, ns, new_ansi_c_language);
12851295
out << goto2c;
12861296
}
12871297

12881298
void dump_cpp(
12891299
const goto_functionst &src,
12901300
const bool use_system_headers,
1301+
const bool use_all_headers,
12911302
const namespacet &ns,
12921303
std::ostream &out)
12931304
{
1294-
dump_ct goto2cpp(src, use_system_headers, ns, new_cpp_language);
1305+
dump_ct goto2cpp(
1306+
src, use_system_headers, use_all_headers, ns, new_cpp_language);
12951307
out << goto2cpp;
12961308
}

src/goto-instrument/dump_c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ Author: Daniel Kroening, [email protected]
1717
void dump_c(
1818
const goto_functionst &src,
1919
const bool use_system_headers,
20+
const bool use_all_headers,
2021
const namespacet &ns,
2122
std::ostream &out);
2223

2324
void dump_cpp(
2425
const goto_functionst &src,
2526
const bool use_system_headers,
27+
const bool use_all_headers,
2628
const namespacet &ns,
2729
std::ostream &out);
2830

src/goto-instrument/dump_c_class.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class dump_ct
2525
dump_ct(
2626
const goto_functionst &_goto_functions,
2727
const bool use_system_headers,
28+
const bool use_all_headers,
2829
const namespacet &_ns,
2930
language_factoryt factory):
3031
goto_functions(_goto_functions),
3132
copied_symbol_table(_ns.get_symbol_table()),
3233
ns(copied_symbol_table),
33-
language(factory())
34+
language(factory()),
35+
use_all_headers(use_all_headers)
3436
{
3537
if(use_system_headers)
3638
init_system_library_map();
@@ -48,6 +50,7 @@ class dump_ct
4850
symbol_tablet copied_symbol_table;
4951
const namespacet ns;
5052
languaget *language;
53+
const bool use_all_headers;
5154

5255
typedef std::unordered_set<irep_idt, irep_id_hash> convertedt;
5356
convertedt converted_compound, converted_global, converted_enum;

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ int goto_instrument_parse_optionst::doit()
608608
if(cmdline.isset("dump-c") || cmdline.isset("dump-cpp"))
609609
{
610610
const bool is_cpp=cmdline.isset("dump-cpp");
611-
const bool h=cmdline.isset("use-system-headers");
611+
const bool h_libc=cmdline.isset("use-system-headers");
612+
const bool h_all=cmdline.isset("use-all-headers");
612613
namespacet ns(symbol_table);
613614

614615
// restore RETURN instructions in case remove_returns had been
@@ -627,10 +628,11 @@ int goto_instrument_parse_optionst::doit()
627628
error() << "failed to write to `" << cmdline.args[1] << "'";
628629
return 10;
629630
}
630-
(is_cpp ? dump_cpp : dump_c)(goto_functions, h, ns, out);
631+
(is_cpp ? dump_cpp : dump_c)(goto_functions, h_libc, h_all, ns, out);
631632
}
632633
else
633-
(is_cpp ? dump_cpp : dump_c)(goto_functions, h, ns, std::cout);
634+
(is_cpp ? dump_cpp : dump_c)(
635+
goto_functions, h_libc, h_all, ns, std::cout);
634636

635637
return 0;
636638
}
@@ -1482,7 +1484,7 @@ void goto_instrument_parse_optionst::help()
14821484
" --check-invariant function instruments invariant checking function\n"
14831485
" --remove-pointers converts pointer arithmetic to base+offset expressions\n" // NOLINT(*)
14841486
" --undefined-function-is-assume-false\n"
1485-
" convert each call to an undefined function to assume(false)\n"
1487+
" convert each call to an undefined function to assume(false)\n" // NOLINT(*)
14861488
"\n"
14871489
"Loop transformations:\n"
14881490
" --k-induction <k> check loops with k-induction\n"
@@ -1526,7 +1528,8 @@ void goto_instrument_parse_optionst::help()
15261528
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
15271529
"\n"
15281530
"Other options:\n"
1529-
" --use-system-headers with --dump-c/--dump-cpp: generate C source with includes\n" // NOLINT(*)
1531+
" --use-system-headers with --dump-c/--dump-cpp: generate C source with libc includes\n" // NOLINT(*)
1532+
" --use-all-headers with --dump-c/--dump-cpp: generate C source with all includes\n" // NOLINT(*)
15301533
" --version show version and exit\n"
15311534
" --xml-ui use XML-formatted output\n"
15321535
" --json-ui use JSON-formatted output\n"

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
"(all)" \
2727
"(document-claims-latex)(document-claims-html)" \
2828
"(document-properties-latex)(document-properties-html)" \
29-
"(dump-c)(dump-cpp)(use-system-headers)(dot)(xml)" \
29+
"(dump-c)(dump-cpp)(use-system-headers)(use-all-headers)(dot)(xml)" \
3030
OPT_GOTO_CHECK \
3131
/* no-X-check are deprecated and ignored */ \
3232
"(no-bounds-check)(no-pointer-check)(no-div-by-zero-check)" \

0 commit comments

Comments
 (0)