Skip to content

Commit 9c78d20

Browse files
author
Daniel Kroening
committed
__CPROVER_r_ok and __CPROVER_w_ok added to ANSI-C front-end
1 parent 0c8eff6 commit 9c78d20

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,23 @@ exprt c_typecheck_baset::do_special_functions(
23342334

23352335
return malloc_expr;
23362336
}
2337+
else if(identifier==CPROVER_PREFIX "r_ok" ||
2338+
identifier==CPROVER_PREFIX "w_ok")
2339+
{
2340+
if(expr.arguments().size()!=2)
2341+
{
2342+
err_location(f_op);
2343+
error() << identifier << " expects two operands" << eom;
2344+
throw 0;
2345+
}
2346+
2347+
irep_idt id=identifier==CPROVER_PREFIX "r_ok"?ID_r_ok:ID_w_ok;
2348+
2349+
predicate_exprt ok_expr(id, expr.arguments()[0], expr.arguments()[1]);
2350+
ok_expr.add_source_location()=source_location;
2351+
2352+
return ok_expr;
2353+
}
23372354
else if(identifier==CPROVER_PREFIX "isinff" ||
23382355
identifier==CPROVER_PREFIX "isinfd" ||
23392356
identifier==CPROVER_PREFIX "isinfld" ||

src/ansi-c/cprover_builtin_headers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ __CPROVER_bool __CPROVER_invalid_pointer(const void *);
99
__CPROVER_bool __CPROVER_is_zero_string(const void *);
1010
__CPROVER_size_t __CPROVER_zero_string_length(const void *);
1111
__CPROVER_size_t __CPROVER_buffer_size(const void *);
12+
__CPROVER_bool __CPROVER_r_ok(const void *, __CPROVER_size_t);
13+
__CPROVER_bool __CPROVER_w_ok(const void *, __CPROVER_size_t);
1214

1315
// bitvector analysis
1416
__CPROVER_bool __CPROVER_get_flag(const void *, const char *);

src/ansi-c/expr2c.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,6 +3515,12 @@ std::string expr2ct::convert_with_precedence(
35153515
return convert_function(src, "__builtin_popcount", precedence=16);
35163516
}
35173517

3518+
else if(src.id()==ID_r_ok)
3519+
return convert_function(src, "R_OK", precedence=16);
3520+
3521+
else if(src.id()==ID_w_ok)
3522+
return convert_function(src, "W_OK", precedence=16);
3523+
35183524
else if(src.id()==ID_invalid_pointer)
35193525
return convert_function(src, "INVALID-POINTER", precedence=16);
35203526

src/ansi-c/library/cprover.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void __CPROVER_precondition(__CPROVER_bool assertion, const char *description);
2424
__CPROVER_bool __CPROVER_is_zero_string(const void *);
2525
__CPROVER_size_t __CPROVER_zero_string_length(const void *);
2626
__CPROVER_size_t __CPROVER_buffer_size(const void *);
27+
__CPROVER_bool __CPROVER_r_ok(const void *, __CPROVER_size_t);
28+
__CPROVER_bool __CPROVER_w_ok(const void *, __CPROVER_size_t);
2729

2830
#if 0
2931
__CPROVER_bool __CPROVER_equal();

src/util/irep_ids.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ IREP_ID_TWO(C_unnamed_object, #unnamed_object)
691691
IREP_ID_TWO(C_temporary_avoided, #temporary_avoided)
692692
IREP_ID_TWO(C_qualifier, #qualifier)
693693
IREP_ID_TWO(C_array_ini, #array_ini)
694+
IREP_ID_ONE(r_ok)
695+
IREP_ID_ONE(w_ok)
694696

695697
// Projects depending on this code base that wish to extend the list of
696698
// available ids should provide a file local_irep_ids.def in their source tree

0 commit comments

Comments
 (0)