Skip to content

goto-analyzer --(un)reachable-functions should not rely on base names #6338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
static int foo(int x)
{
return x + 1;
}

static int bar(int x)
{
return x + 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int __CPROVER_file_local_project_c_foo(int x);

int main()
{
int x = __CPROVER_file_local_project_c_foo(1);
assert(x == 2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CORE
test.c
--reachable-functions
^.* foo 1 4$
^EXIT=0$
^SIGNAL=0$
--
^.* [a-zA-Z0-9_]+foo \d+ \d+$
--
This test checks that after building the goto binary (see test.sh) with
--export-file-local-symbols function "foo" is still reported as reachable. Note,
that the symbol representing "foo" has a mangled name in the goto binary, which
makes the symbol name different from its base name.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e

goto_cc=$1
is_windows=$2

if [[ "${is_windows}" == "true" ]]; then
${goto_cc} "/c" "/Foproject.gb" --export-file-local-symbols project.c
${goto_cc} "/c" "/Foproof.gb" --export-file-local-symbols proof.c
${goto_cc} "/Fetest.gb" project.gb proof.gb
else
${goto_cc} -o project.gb --export-file-local-symbols project.c
${goto_cc} -o proof.gb --export-file-local-symbols proof.c
${goto_cc} -o test.gb project.gb proof.gb
fi
8 changes: 2 additions & 6 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ void unreachable_instructions(

const symbolt &decl = ns.lookup(gf_entry.first);

// gf_entry.first may be a link-time renamed version, use the
// base_name instead; do not list inlined functions
if(
called.find(decl.base_name) != called.end() ||
called.find(decl.name) != called.end() ||
to_code_type(decl.type).get_inlined())
{
unreachable_instructions(goto_program, dead_map);
Expand Down Expand Up @@ -314,10 +312,8 @@ static void list_functions(
{
const symbolt &decl = ns.lookup(gf_entry.first);

// gf_entry.first may be a link-time renamed version, use the
// base_name instead; do not list inlined functions
if(
unreachable == (called.find(decl.base_name) != called.end() ||
unreachable == (called.find(decl.name) != called.end() ||
to_code_type(decl.type).get_inlined()))
{
continue;
Expand Down