Skip to content

Commit 0d7a943

Browse files
author
Daniel Kroening
authored
Merge pull request #2558 from tautschnig/linking-xen
Accept more mismatching function definition/declaration pairs
2 parents 5acc0b0 + 754b36d commit 0d7a943

File tree

10 files changed

+139
-7
lines changed

10 files changed

+139
-7
lines changed

regression/ansi-c/linking1/main.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void f(int);
2+
3+
int main(int argc, char *argv[])
4+
{
5+
f(argc);
6+
return 0;
7+
}

regression/ansi-c/linking1/module.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void f(float param)
2+
{
3+
}

regression/ansi-c/linking1/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
module.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/cbmc/Linking7/main.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
struct S
2+
{
3+
void *a;
4+
void *b;
5+
};
6+
7+
typedef void (*fptr)(struct S);
8+
9+
extern void foo(struct S s);
10+
11+
fptr A[] = { foo };
12+
13+
extern void bar();
14+
15+
int main()
16+
{
17+
bar();
18+
return 0;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
KNOWNBUG
2+
main.c
3+
module2.c
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\*\* 1 of 2 failed
8+
--
9+
^warning: ignoring
10+
--
11+
This is either a bug in goto-symex or value_sett (where the invariant fails).

regression/cbmc/Linking7/module.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <assert.h>
2+
3+
struct S
4+
{
5+
void *a;
6+
void *b;
7+
};
8+
9+
typedef void (*fptr)(struct S);
10+
11+
extern fptr A[1];
12+
13+
struct real_S
14+
{
15+
int *a;
16+
int *b;
17+
};
18+
19+
void foo(struct real_S g)
20+
{
21+
assert(*g.a == 42);
22+
assert(*g.b == 41);
23+
}
24+
25+
void bar()
26+
{
27+
int x = 42;
28+
struct real_S s;
29+
s.a = &x;
30+
s.b = &x;
31+
A[0]((struct S){ s.a, s.b });
32+
}

regression/cbmc/Linking7/module2.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <assert.h>
2+
3+
struct S
4+
{
5+
void *a;
6+
void *b;
7+
};
8+
9+
typedef void (*fptr)(struct S);
10+
11+
extern fptr A[1];
12+
13+
struct real_S
14+
{
15+
int *a;
16+
int *c;
17+
};
18+
19+
void foo(struct real_S g)
20+
{
21+
assert(*g.a == 42);
22+
assert(*g.c == 41);
23+
}
24+
25+
void bar()
26+
{
27+
int x = 42;
28+
struct real_S s;
29+
s.a = &x;
30+
s.c = &x;
31+
A[0]((struct S){ s.a, s.c });
32+
}

regression/cbmc/Linking7/test.desc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
module.c
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\*\* 1 of 2 failed
8+
--
9+
^warning: ignoring

src/goto-programs/remove_function_pointers.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <cassert>
1515

16+
#include <util/base_type.h>
17+
#include <util/c_types.h>
1618
#include <util/fresh_symbol.h>
19+
#include <util/invariant.h>
20+
#include <util/message.h>
21+
#include <util/pointer_offset_size.h>
1722
#include <util/replace_expr.h>
1823
#include <util/source_location.h>
1924
#include <util/std_expr.h>
2025
#include <util/type_eq.h>
21-
#include <util/message.h>
22-
#include <util/base_type.h>
2326

2427
#include <analyses/does_remove_const.h>
25-
#include <util/invariant.h>
26-
27-
#include <util/c_types.h>
2828

2929
#include "remove_skip.h"
3030
#include "compute_called_functions.h"
@@ -135,8 +135,8 @@ bool remove_function_pointerst::arg_is_type_compatible(
135135
return false;
136136
}
137137

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

141141
return false;
142142
}

src/linking/linking.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,17 @@ void linkingt::duplicate_code_symbol(
701701
if(!found)
702702
break;
703703
}
704+
// different non-pointer arguments with implementation - the
705+
// implementation is always right, even though such code may
706+
// be severely broken
707+
else if(pointer_offset_bits(t1, ns)==pointer_offset_bits(t2, ns) &&
708+
old_symbol.value.is_nil()!=new_symbol.value.is_nil())
709+
{
710+
if(warn_msg.empty())
711+
warn_msg="non-pointer parameter types differ between "
712+
"declaration and definition";
713+
replace=new_symbol.value.is_not_nil();
714+
}
704715
else
705716
break;
706717

0 commit comments

Comments
 (0)