Skip to content

Commit 0863c63

Browse files
authored
Merge pull request #4563 from tautschnig/fix-name-mangling
Export-function-local-symbols name mangling: rename initial values
2 parents 3c6293a + fcf6fc0 commit 0863c63

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ DIRS = cbmc \
2525
goto-cc-goto-analyzer \
2626
systemc \
2727
contracts \
28+
goto-cc-file-local \
2829
# Empty last line
2930

3031
# Run all test directories in sequence
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows=true
9+
else
10+
exe=../../../src/goto-cc/goto-cc
11+
is_windows=false
12+
endif
13+
14+
test:
15+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)'
16+
17+
tests.log:
18+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)'
19+
20+
show:
21+
@for dir in *; do \
22+
if [ -d "$$dir" ]; then \
23+
vim -o "$$dir/*.c" "$$dir/*.out"; \
24+
fi; \
25+
done;
26+
27+
clean:
28+
@for dir in *; do \
29+
$(RM) tests.log; \
30+
if [ -d "$$dir" ]; then \
31+
cd "$$dir"; \
32+
$(RM) *.out *.gb; \
33+
cd ..; \
34+
fi \
35+
done

regression/goto-cc-file-local/chain.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# Author: Kareem Khazem <[email protected]>
66

7+
set -e
8+
79
is_in()
810
{
911
[[ "$2" =~ $1 ]] && return 0 || return 1
@@ -81,6 +83,7 @@ done
8183

8284
if is_in final-link "$ALL_ARGS"; then
8385
OUT_FILE=final-link.gb
86+
rm -f ${OUT_FILE}
8487
if [[ "${is_windows}" == "true" ]]; then
8588
"${goto_cc}" \
8689
--export-function-local-symbols \
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <assert.h>
2+
3+
static int foo()
4+
{
5+
return 3;
6+
}
7+
8+
int (*fptrs[])(void) = {foo};
9+
10+
int main()
11+
{
12+
int x = fptrs[0]();
13+
assert(x == 3);
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
final-link assertion-check
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
^\*\*\*\* WARNING: no body for function

src/goto-programs/name_mangler.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ class function_name_manglert
8484
for(const auto &sym : old_syms)
8585
model.symbol_table.erase(sym);
8686

87+
for(const auto &sym_pair : model.symbol_table)
88+
{
89+
const symbolt &sym = sym_pair.second;
90+
91+
exprt e = sym.value;
92+
typet t = sym.type;
93+
if(rename(e) && rename(t))
94+
continue;
95+
96+
symbolt &new_sym = model.symbol_table.get_writeable_ref(sym.name);
97+
new_sym.value = e;
98+
new_sym.type = t;
99+
}
100+
87101
for(auto &fun : model.goto_functions.function_map)
88102
{
89103
if(!fun.second.body_available())

src/util/rename_symbol.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ class rename_symbolt
4343
type_map.insert(std::pair<irep_idt, irep_idt>(old_id, new_id));
4444
}
4545

46-
void operator()(exprt &dest) const
46+
/// Rename symbols in \p dest.
47+
/// \return True if, and only if, the expression was not modified.
48+
bool operator()(exprt &dest) const
4749
{
48-
rename(dest);
50+
return rename(dest);
4951
}
5052

51-
void operator()(typet &dest) const
53+
/// Rename symbols in \p dest.
54+
/// \return True if, and only if, the type was not modified.
55+
bool operator()(typet &dest) const
5256
{
53-
rename(dest);
57+
return rename(dest);
5458
}
5559

5660
rename_symbolt();

0 commit comments

Comments
 (0)