Export-function-local-symbols name mangling: rename initial values

We previously renamed all occurrences in goto functions, but did not
consider the initial values of symbols with static lifetime, which are
stored in the symbol table. To make this reasonably efficient, make
rename_symbolt::operator() expose the return value (and document the
methods).

To test this, include the test suite in Makefile-based test set-ups
(CMake was already done), and fix the chain.sh file.
This commit is contained in:
Michael Tautschnig 2019-04-23 17:49:08 +00:00
parent 8811606378
commit fcf6fc0b37
7 changed files with 84 additions and 4 deletions

View File

@ -25,6 +25,7 @@ DIRS = cbmc \
goto-cc-goto-analyzer \
systemc \
contracts \
goto-cc-file-local \
# Empty last line
# Run all test directories in sequence

View File

@ -0,0 +1,35 @@
default: tests.log
include ../../src/config.inc
include ../../src/common
ifeq ($(BUILD_ENV_),MSVC)
exe=../../../src/goto-cc/goto-cl
is_windows=true
else
exe=../../../src/goto-cc/goto-cc
is_windows=false
endif
test:
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)'
tests.log:
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)'
show:
@for dir in *; do \
if [ -d "$$dir" ]; then \
vim -o "$$dir/*.c" "$$dir/*.out"; \
fi; \
done;
clean:
@for dir in *; do \
$(RM) tests.log; \
if [ -d "$$dir" ]; then \
cd "$$dir"; \
$(RM) *.out *.gb; \
cd ..; \
fi \
done

View File

@ -4,6 +4,8 @@
#
# Author: Kareem Khazem <karkhaz@karkhaz.com>
set -e
is_in()
{
[[ "$2" =~ $1 ]] && return 0 || return 1
@ -81,6 +83,7 @@ done
if is_in final-link "$ALL_ARGS"; then
OUT_FILE=final-link.gb
rm -f ${OUT_FILE}
if [[ "${is_windows}" == "true" ]]; then
"${goto_cc}" \
--export-function-local-symbols \

View File

@ -0,0 +1,14 @@
#include <assert.h>
static int foo()
{
return 3;
}
int (*fptrs[])(void) = {foo};
int main()
{
int x = fptrs[0]();
assert(x == 3);
}

View File

@ -0,0 +1,9 @@
CORE
main.c
final-link assertion-check
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^\*\*\*\* WARNING: no body for function

View File

@ -84,6 +84,20 @@ public:
for(const auto &sym : old_syms)
model.symbol_table.erase(sym);
for(const auto &sym_pair : model.symbol_table)
{
const symbolt &sym = sym_pair.second;
exprt e = sym.value;
typet t = sym.type;
if(rename(e) && rename(t))
continue;
symbolt &new_sym = model.symbol_table.get_writeable_ref(sym.name);
new_sym.value = e;
new_sym.type = t;
}
for(auto &fun : model.goto_functions.function_map)
{
if(!fun.second.body_available())

View File

@ -43,14 +43,18 @@ public:
type_map.insert(std::pair<irep_idt, irep_idt>(old_id, new_id));
}
void operator()(exprt &dest) const
/// Rename symbols in \p dest.
/// \return True if, and only if, the expression was not modified.
bool operator()(exprt &dest) const
{
rename(dest);
return rename(dest);
}
void operator()(typet &dest) const
/// Rename symbols in \p dest.
/// \return True if, and only if, the type was not modified.
bool operator()(typet &dest) const
{
rename(dest);
return rename(dest);
}
rename_symbolt();