Skip to content

Commit b9d5aa3

Browse files
authored
Merge pull request #7374 from tautschnig/feature/imaxabs
C library: add imaxabs
2 parents 7939303 + a9d5aa2 commit b9d5aa3

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <inttypes.h>
3+
#include <stdlib.h>
4+
5+
int main()
6+
{
7+
assert(imaxabs(INTMAX_MIN + 1) == INTMAX_MAX);
8+
return 0;
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check --signed-overflow-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,12 +2944,13 @@ exprt c_typecheck_baset::do_special_functions(
29442944

29452945
return std::move(infl_expr);
29462946
}
2947-
else if(identifier==CPROVER_PREFIX "abs" ||
2948-
identifier==CPROVER_PREFIX "labs" ||
2949-
identifier==CPROVER_PREFIX "llabs" ||
2950-
identifier==CPROVER_PREFIX "fabs" ||
2951-
identifier==CPROVER_PREFIX "fabsf" ||
2952-
identifier==CPROVER_PREFIX "fabsl")
2947+
else if(
2948+
identifier == CPROVER_PREFIX "abs" || identifier == CPROVER_PREFIX "labs" ||
2949+
identifier == CPROVER_PREFIX "llabs" ||
2950+
identifier == CPROVER_PREFIX "imaxabs" ||
2951+
identifier == CPROVER_PREFIX "fabs" ||
2952+
identifier == CPROVER_PREFIX "fabsf" ||
2953+
identifier == CPROVER_PREFIX "fabsl")
29532954
{
29542955
if(expr.arguments().size()!=1)
29552956
{

src/ansi-c/library/stdlib.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ long long int llabs(long long int i)
2525
return __CPROVER_llabs(i);
2626
}
2727

28+
/* FUNCTION: imaxabs */
29+
30+
#ifndef __CPROVER_INTTYPES_H_INCLUDED
31+
# include <inttypes.h>
32+
# define __CPROVER_INTTYPES_H_INCLUDED
33+
#endif
34+
35+
#undef imaxabs
36+
37+
intmax_t __CPROVER_imaxabs(intmax_t);
38+
39+
intmax_t imaxabs(intmax_t i)
40+
{
41+
return __CPROVER_imaxabs(i);
42+
}
43+
2844
/* FUNCTION: __builtin_abs */
2945

3046
int __builtin_abs(int i)

0 commit comments

Comments
 (0)