Skip to content

Commit d8f7930

Browse files
committed
Library functions may require converting additional inline functions
Library functions may make use of (inline) functions defined in header files. One such case is `copysignf`, which uses `signbit`, which in turn is inlined on macOS. When these functions hadn't been seen before linking the library, then converting just the `library_model` symbol table would be insufficient for it would not include functions outside our own model library. Fall back to the `goto_model` symbol table for those cases. This was originally reported via Kani in model-checking/kani#1993.
1 parent 94ab0eb commit d8f7930

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#include <assert.h>
2-
#include <math.h>
1+
// Use a forward declaration instead of including math.h to demonstrate a bugfix
2+
// in library linking.
3+
float copysignf(float, float);
34

45
int main()
56
{
6-
copysignf();
7-
assert(0);
7+
float x;
8+
float y;
9+
float result = copysignf(x, y);
10+
__CPROVER_assert(
11+
__CPROVER_signf(result) == __CPROVER_signf(y), "signs match");
812
return 0;
913
}

regression/cbmc-library/copysignf-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

src/goto-programs/link_to_library.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ static std::pair<optionalt<replace_symbolt::expr_mapt>, bool> add_one_function(
4747
library_model.goto_functions,
4848
message_handler);
4949
}
50+
// We might need a function that's outside our own library, but brought in via
51+
// some header file included by the library. Those functions already exist in
52+
// goto_model.symbol_table, but haven't been converted just yet.
53+
else if(
54+
goto_model.symbol_table.symbols.find(missing_function) !=
55+
goto_model.symbol_table.symbols.end())
56+
{
57+
goto_convert(
58+
missing_function,
59+
goto_model.symbol_table,
60+
library_model.goto_functions,
61+
message_handler);
62+
}
5063

5164
// check whether additional initialization may be required
5265
bool init_required = false;

0 commit comments

Comments
 (0)