File tree 12 files changed +124
-12
lines changed
regression/goto-cc-static 12 files changed +124
-12
lines changed Original file line number Diff line number Diff line change 5
5
endif ()
6
6
7
7
add_test_pl_tests(
8
- "${CMAKE_CURRENT_SOURCE_DIR} /chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:cbmc > ${is_windows} "
8
+ "${CMAKE_CURRENT_SOURCE_DIR} /chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument > ${is_windows} "
9
9
)
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
3
goto_cc=$1
4
- cbmc =$2
4
+ goto_instrument =$2
5
5
is_windows=$3
6
6
7
7
to_keep=" "
8
8
if [ $# -gt 3 ]; then
9
- if [ $4 != ' ' ]; then
9
+ if [[ $4 != ' ' ] ]; then
10
10
to_keep=" --keep-implementations $4 "
11
+ strip_static=" --strip-static $4 "
11
12
fi
12
13
fi
13
14
14
- cbmc_options=" "
15
- if [ $# -gt 4 ]; then
16
- cbmc_options=${*: 5: $# -5}
17
- fi
18
-
19
15
name=${*: $# }
20
16
name=${name% .c}
21
17
26
22
" ${goto_cc} " ${to_keep} " ${name} .c" -o " ${name} .gb"
27
23
fi
28
24
29
- " ${cbmc} " ${cbmc_options} " ${name} .gb" ${cbmc_options}
25
+ if [[ " $to_keep " = ' ' ]]; then
26
+ cp " ${name} .gb" " ${name} -mod.gb"
27
+ else
28
+ ${goto_instrument} ${strip_static} " ${name} .gb" " ${name} -mod.gb"
29
+ fi
30
+
31
+ " ${goto_instrument} " --show-symbol-table " ${name} -mod.gb" " ${name} -mod-2.gb"
Original file line number Diff line number Diff line change 1
1
CORE
2
2
main.c
3
- foo --show-symbol-table
3
+ foo
4
4
5
5
^EXIT=0$
6
6
^SIGNAL=0$
Original file line number Diff line number Diff line change 1
1
CORE
2
2
main.c
3
- main --show-symbol-table
4
3
5
4
^EXIT=0$
6
5
^SIGNAL=0$
Original file line number Diff line number Diff line change 1
1
CORE
2
2
main.c
3
- foo,bar --show-symbol-table
3
+ foo,bar
4
4
5
5
^EXIT=0$
6
6
^SIGNAL=0$
Original file line number Diff line number Diff line change
1
+ static int foo ()
2
+ {
3
+ return 3 ;
4
+ }
5
+
6
+ int main ()
7
+ {
8
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ foo
4
+ activate-multi-line-match
5
+ ^EXIT=0$
6
+ ^SIGNAL=0$
7
+ Symbol......: foo\nPretty name.: .+\nModule......: .+\nBase name...: .+\nMode........: .+\nType........: .+\nValue.......: .+\nFlags.......: lvalue
8
+ --
9
+ Symbol......: foo\nPretty name.: .+\nModule......: .+\nBase name...: .+\nMode........: .+\nType........: .+\nValue.......: .+\nFlags.......: .*file_local.*
10
+ --
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ SRC = accelerate/accelerate.cpp \
60
60
source_lines.cpp \
61
61
splice_call.cpp \
62
62
stack_depth.cpp \
63
+ strip_static.cpp \
63
64
thread_instrumentation.cpp \
64
65
undefined_functions.cpp \
65
66
uninitialized.cpp \
Original file line number Diff line number Diff line change @@ -232,6 +232,22 @@ int goto_instrument_parse_optionst::doit()
232
232
}
233
233
}
234
234
235
+ if (cmdline.isset (" strip-static" ))
236
+ {
237
+ std::list<std::string> funs_to_strip =
238
+ cmdline.get_comma_separated_values (" strip-static" );
239
+ if (funs_to_strip.empty ())
240
+ {
241
+ error () << " Provide a comma-delimited list of functions to remove"
242
+ " the static attribute from"
243
+ << eom;
244
+ return CPROVER_EXIT_USAGE_ERROR;
245
+ }
246
+
247
+ static_strippert ss (goto_model, *this );
248
+ ss.strip_statics_from_funs (funs_to_strip);
249
+ }
250
+
235
251
if (cmdline.isset (" show-threaded" ))
236
252
{
237
253
namespacet ns (goto_model.symbol_table );
@@ -1668,6 +1684,7 @@ void goto_instrument_parse_optionst::help()
1668
1684
" --remove-function-pointers replace function pointers by case statement over function calls\n " // NOLINT(*)
1669
1685
HELP_REMOVE_CALLS_NO_BODY
1670
1686
HELP_REMOVE_CONST_FUNCTION_POINTERS
1687
+ HELP_STRIP_STATIC
1671
1688
" --add-library add models of C library functions\n "
1672
1689
" --model-argc-argv <n> model up to <n> command line arguments\n "
1673
1690
// NOLINTNEXTLINE(whitespace/line_length)
Original file line number Diff line number Diff line change 33
33
#include " generate_function_bodies.h"
34
34
35
35
#include " count_eloc.h"
36
+ #include " strip_static.h"
36
37
37
38
// clang-format off
38
39
#define GOTO_INSTRUMENT_OPTIONS \
83
84
" (show-symbol-table)(show-points-to)(show-rw-set)" \
84
85
" (cav11)" \
85
86
OPT_TIMESTAMP \
87
+ OPT_STRIP_STATIC \
86
88
" (show-natural-loops)(accelerate)(havoc-loops)" \
87
89
" (error-label):(string-abstraction)" \
88
90
" (verbosity):(version)(xml-ui)(json-ui)(show-loops)" \
Original file line number Diff line number Diff line change
1
+ /* ******************************************************************\
2
+
3
+ Module: Strip static
4
+
5
+ Author: Kareem Khazem <[email protected] >
6
+
7
+ \*******************************************************************/
8
+
9
+ #include " strip_static.h"
10
+
11
+ bool static_strippert::strip_statics_from_funs (
12
+ const std::list<std::string> &funs)
13
+ {
14
+ bool fail = false ;
15
+
16
+ for (const auto fun : funs)
17
+ {
18
+ if (!model.symbol_table .has_symbol (fun))
19
+ {
20
+ log .error () << " Could not find symbol '" << fun << " ' to remove static"
21
+ << log .eom ;
22
+ fail = true ;
23
+ continue ;
24
+ }
25
+ symbolt &sym = model.symbol_table .get_writeable_ref (fun);
26
+ if (!sym.is_file_local )
27
+ {
28
+ log .warning () << " Not removing static attribute from symbol '" << fun
29
+ << " ': symbol is already externally visible" << log .eom ;
30
+ continue ;
31
+ }
32
+ sym.is_file_local = false ;
33
+ }
34
+
35
+ return fail;
36
+ }
Original file line number Diff line number Diff line change
1
+ // / \file strip_static.h
2
+ // / \brief Remove static attribute from functions
3
+ // / \author Kareem Khazem <[email protected] >
4
+
5
+ #ifndef CPROVER_GOTO_INSTRUMENT_STRIP_STATIC_H
6
+ #define CPROVER_GOTO_INSTRUMENT_STRIP_STATIC_H
7
+
8
+ #include < goto-programs/goto_model.h>
9
+ #include < util/message.h>
10
+
11
+ #include < forward_list>
12
+ #include < string>
13
+
14
+ // / \brief Remove static attribute from functions
15
+ class static_strippert
16
+ {
17
+ public:
18
+ explicit static_strippert (goto_modelt &goto_model, messaget &log)
19
+ : model(goto_model), log(log)
20
+ {
21
+ }
22
+
23
+ // / \brief Removes the static attribute from functions
24
+ // /
25
+ // / \return `true` on failure, `false` otherwise
26
+ bool strip_statics_from_funs (const std::list<std::string> &);
27
+
28
+ protected:
29
+ goto_modelt &model;
30
+ messaget &log;
31
+ };
32
+
33
+ #define OPT_STRIP_STATIC " (strip-static):"
34
+ #define HELP_STRIP_STATIC \
35
+ " --strip-static fun[,fun...] remove static from functions\n "
36
+
37
+ #endif /* CPROVER_GOTO_INSTRUMENT_STRIP_STATIC_H */
You can’t perform that action at this time.
0 commit comments