Skip to content

Commit 1f088d7

Browse files
authored
Merge pull request #7475 from tautschnig/bugfixes/library-inline
Library functions may require converting additional inline functions
2 parents a8d3c21 + d8f7930 commit 1f088d7

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include <assert.h>
22
#include <math.h>
33

4+
int __signbitd(double);
5+
int __signbitf(float);
6+
47
int main()
58
{
6-
__signbitd();
7-
assert(0);
9+
float f;
10+
double df = (double)f;
11+
__CPROVER_assert(
12+
isnan(f) || __signbitd(df) == __signbitf(f), "cast preserves sign");
813
return 0;
914
}

regression/cbmc-library/__signbitd-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$
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/ansi-c/compiler_headers/gcc_builtin_headers_math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ long double __builtin_scalblnl(long double, long);
339339
double __builtin_scalbn(double, int);
340340
float __builtin_scalbnf(float, int);
341341
long double __builtin_scalbnl(long double, int);
342-
int __builtin_signbit(double);
342+
int __builtin_signbit(); // this is type-generic
343343
int __builtin_signbitf(float);
344344
int __builtin_signbitl(long double);
345345
double __builtin_significand(double);

src/ansi-c/library/math.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ float fabsf (float d);
24002400

24012401
float copysignf(float x, float y)
24022402
{
2403-
float abs = fabs(x);
2403+
float abs = fabsf(x);
24042404
return (signbit(y)) ? -abs : abs;
24052405
}
24062406

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)