Skip to content

Accept more mismatching function definition/declaration pairs #2558

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
Jul 9, 2018
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
7 changes: 7 additions & 0 deletions regression/ansi-c/linking1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void f(int);

int main(int argc, char *argv[])
{
f(argc);
return 0;
}
3 changes: 3 additions & 0 deletions regression/ansi-c/linking1/module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void f(float param)
{
}
8 changes: 8 additions & 0 deletions regression/ansi-c/linking1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
module.c
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
19 changes: 19 additions & 0 deletions regression/cbmc/Linking7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct S
{
void *a;
void *b;
};

typedef void (*fptr)(struct S);

extern void foo(struct S s);

fptr A[] = { foo };

extern void bar();

int main()
{
bar();
return 0;
}
11 changes: 11 additions & 0 deletions regression/cbmc/Linking7/member-name-mismatch.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
KNOWNBUG
main.c
module2.c
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
^\*\* 1 of 2 failed
--
^warning: ignoring
--
This is either a bug in goto-symex or value_sett (where the invariant fails).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an invariant

32 changes: 32 additions & 0 deletions regression/cbmc/Linking7/module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <assert.h>

struct S
{
void *a;
void *b;
};

typedef void (*fptr)(struct S);

extern fptr A[1];

struct real_S
{
int *a;
int *b;
};

void foo(struct real_S g)
{
assert(*g.a == 42);
assert(*g.b == 41);
}

void bar()
{
int x = 42;
struct real_S s;
s.a = &x;
s.b = &x;
A[0]((struct S){ s.a, s.b });
}
32 changes: 32 additions & 0 deletions regression/cbmc/Linking7/module2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <assert.h>

struct S
{
void *a;
void *b;
};

typedef void (*fptr)(struct S);

extern fptr A[1];

struct real_S
{
int *a;
int *c;
};

void foo(struct real_S g)
{
assert(*g.a == 42);
assert(*g.c == 41);
}

void bar()
{
int x = 42;
struct real_S s;
s.a = &x;
s.c = &x;
A[0]((struct S){ s.a, s.c });
}
9 changes: 9 additions & 0 deletions regression/cbmc/Linking7/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
module.c
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
^\*\* 1 of 2 failed
--
^warning: ignoring
14 changes: 7 additions & 7 deletions src/goto-programs/remove_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Author: Daniel Kroening, [email protected]

#include <cassert>

#include <util/base_type.h>
#include <util/c_types.h>
#include <util/fresh_symbol.h>
#include <util/invariant.h>
#include <util/message.h>
#include <util/pointer_offset_size.h>
#include <util/replace_expr.h>
#include <util/source_location.h>
#include <util/std_expr.h>
#include <util/type_eq.h>
#include <util/message.h>
#include <util/base_type.h>

#include <analyses/does_remove_const.h>
#include <util/invariant.h>

#include <util/c_types.h>

#include "remove_skip.h"
#include "compute_called_functions.h"
Expand Down Expand Up @@ -135,8 +135,8 @@ bool remove_function_pointerst::arg_is_type_compatible(
return false;
}

// structs/unions need to match,
// which could be made more generous
return pointer_offset_bits(call_type, ns) ==
pointer_offset_bits(function_type, ns);

return false;
}
Expand Down
11 changes: 11 additions & 0 deletions src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,17 @@ void linkingt::duplicate_code_symbol(
if(!found)
break;
}
// different non-pointer arguments with implementation - the
// implementation is always right, even though such code may
// be severely broken
else if(pointer_offset_bits(t1, ns)==pointer_offset_bits(t2, ns) &&
old_symbol.value.is_nil()!=new_symbol.value.is_nil())
{
if(warn_msg.empty())
warn_msg="non-pointer parameter types differ between "
"declaration and definition";
replace=new_symbol.value.is_not_nil();
}
else
break;

Expand Down