Skip to content

Commit a9d5aa2

Browse files
committed
C library: add imaxabs
This is another variant of absolute-value functions.
1 parent 8848ad8 commit a9d5aa2

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
@@ -2872,12 +2872,13 @@ exprt c_typecheck_baset::do_special_functions(
28722872

28732873
return std::move(infl_expr);
28742874
}
2875-
else if(identifier==CPROVER_PREFIX "abs" ||
2876-
identifier==CPROVER_PREFIX "labs" ||
2877-
identifier==CPROVER_PREFIX "llabs" ||
2878-
identifier==CPROVER_PREFIX "fabs" ||
2879-
identifier==CPROVER_PREFIX "fabsf" ||
2880-
identifier==CPROVER_PREFIX "fabsl")
2875+
else if(
2876+
identifier == CPROVER_PREFIX "abs" || identifier == CPROVER_PREFIX "labs" ||
2877+
identifier == CPROVER_PREFIX "llabs" ||
2878+
identifier == CPROVER_PREFIX "imaxabs" ||
2879+
identifier == CPROVER_PREFIX "fabs" ||
2880+
identifier == CPROVER_PREFIX "fabsf" ||
2881+
identifier == CPROVER_PREFIX "fabsl")
28812882
{
28822883
if(expr.arguments().size()!=1)
28832884
{

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)