cprover
java_bytecode_instrument.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Instrument codet with assertions/runtime exceptions
4 
5 Author: Cristina David
6 
7 Date: June 2017
8 
9 \*******************************************************************/
10 
12 
13 #include <util/arith_tools.h>
14 #include <util/std_code.h>
15 #include <util/std_expr.h>
16 #include <util/c_types.h>
17 
19 
21 #include "java_entry_point.h"
22 #include "java_expr.h"
23 #include "java_utils.h"
24 
26 {
27 public:
29  symbol_table_baset &_symbol_table,
30  const bool _throw_runtime_exceptions,
31  message_handlert &_message_handler)
32  : symbol_table(_symbol_table),
33  throw_runtime_exceptions(_throw_runtime_exceptions),
34  message_handler(_message_handler)
35  {
36  }
37 
38  void operator()(codet &code);
39 
40 protected:
44 
46  const exprt &cond,
47  const source_locationt &original_loc,
48  const irep_idt &exc_name);
49 
51  const exprt &array_struct,
52  const exprt &idx,
53  const source_locationt &original_loc);
54 
56  const exprt &denominator,
57  const source_locationt &original_loc);
58 
60  const exprt &expr,
61  const source_locationt &original_loc);
62 
64  const exprt &tested_expr,
65  const struct_tag_typet &target_type,
66  const source_locationt &original_loc);
67 
69  const exprt &length,
70  const source_locationt &original_loc);
71 
72  void instrument_code(codet &code);
73  void add_expr_instrumentation(code_blockt &block, const exprt &expr);
74  void prepend_instrumentation(codet &code, code_blockt &instrumentation);
76 };
77 
78 const std::vector<std::string> exception_needed_classes = {
79  "java.lang.ArithmeticException",
80  "java.lang.ArrayIndexOutOfBoundsException",
81  "java.lang.ClassCastException",
82  "java.lang.NegativeArraySizeException",
83  "java.lang.NullPointerException"};
84 
95  const exprt &cond,
96  const source_locationt &original_loc,
97  const irep_idt &exc_name)
98 {
99  irep_idt exc_class_name("java::"+id2string(exc_name));
100 
101  if(!symbol_table.has_symbol(exc_class_name))
102  {
104  exc_name,
105  symbol_table,
108  }
109 
110  pointer_typet exc_ptr_type = pointer_type(struct_tag_typet(exc_class_name));
111 
112  // Allocate and throw an instance of the exception class:
113 
114  symbolt &new_symbol = fresh_java_symbol(
115  exc_ptr_type, "new_exception", original_loc, "new_exception", symbol_table);
116 
117  side_effect_exprt new_instance(ID_java_new, exc_ptr_type, original_loc);
118  code_assignt assign_new(new_symbol.symbol_expr(), new_instance);
119 
120  side_effect_expr_throwt throw_expr(irept(), typet(), original_loc);
121  throw_expr.copy_to_operands(new_symbol.symbol_expr());
122 
123  code_ifthenelset if_code(
124  cond, code_blockt({assign_new, code_expressiont(throw_expr)}));
125 
126  if_code.add_source_location()=original_loc;
127 
128  return if_code;
129 }
130 
139  const exprt &denominator,
140  const source_locationt &original_loc)
141 {
142  const constant_exprt &zero=from_integer(0, denominator.type());
143  const binary_relation_exprt equal_zero(denominator, ID_equal, zero);
144 
146  return throw_exception(
147  equal_zero,
148  original_loc,
149  "java.lang.ArithmeticException");
150 
151  source_locationt assertion_loc = original_loc;
152  assertion_loc.set_comment("Denominator should be nonzero");
153  assertion_loc.set_property_class("integer-divide-by-zero");
154 
155  return create_fatal_assertion(
156  binary_relation_exprt(denominator, ID_notequal, zero), assertion_loc);
157 }
158 
170  const exprt &array_struct,
171  const exprt &idx,
172  const source_locationt &original_loc)
173 {
174  const constant_exprt &zero=from_integer(0, java_int_type());
175  const binary_relation_exprt ge_zero(idx, ID_ge, zero);
176  const member_exprt length_field(array_struct, "length", java_int_type());
177  const binary_relation_exprt lt_length(idx, ID_lt, length_field);
178  const and_exprt cond(ge_zero, lt_length);
179 
181  return throw_exception(
182  not_exprt(cond),
183  original_loc,
184  "java.lang.ArrayIndexOutOfBoundsException");
185 
186  code_blockt bounds_checks;
187 
188  source_locationt low_check_loc = original_loc;
189  low_check_loc.set_comment("Array index should be >= 0");
190  low_check_loc.set_property_class("array-index-out-of-bounds-low");
191 
192  source_locationt high_check_loc = original_loc;
193  high_check_loc.set_comment("Array index should be < length");
194  high_check_loc.set_property_class("array-index-out-of-bounds-high");
195 
196  bounds_checks.add(create_fatal_assertion(ge_zero, low_check_loc));
197  bounds_checks.add(create_fatal_assertion(lt_length, high_check_loc));
198 
199  return std::move(bounds_checks);
200 }
201 
213  const exprt &tested_expr,
214  const struct_tag_typet &target_type,
215  const source_locationt &original_loc)
216 {
217  java_instanceof_exprt class_cast_check(tested_expr, target_type);
218 
220  exprt null_check_op = typecast_exprt::conditional_cast(tested_expr, voidptr);
221 
224  {
225  check_code=
227  not_exprt(class_cast_check),
228  original_loc,
229  "java.lang.ClassCastException");
230  }
231  else
232  {
233  source_locationt check_loc = original_loc;
234  check_loc.set_comment("Dynamic cast check");
235  check_loc.set_property_class("bad-dynamic-cast");
236 
237  codet assert_class = create_fatal_assertion(class_cast_check, check_loc);
238 
239  check_code=std::move(assert_class);
240  }
241 
242  return code_ifthenelset(
243  notequal_exprt(std::move(null_check_op), null_pointer_exprt(voidptr)),
244  std::move(*check_code));
245 }
246 
257  const exprt &expr,
258  const source_locationt &original_loc)
259 {
260  const equal_exprt equal_expr(
261  expr,
263 
265  return throw_exception(
266  equal_expr,
267  original_loc, "java.lang.NullPointerException");
268 
269  source_locationt check_loc = original_loc;
270  check_loc.set_comment("Null pointer check");
271  check_loc.set_property_class("null-pointer-exception");
272 
273  return create_fatal_assertion(not_exprt(equal_expr), check_loc);
274 }
275 
286  const exprt &length,
287  const source_locationt &original_loc)
288 {
289  const constant_exprt &zero=from_integer(0, java_int_type());
290  const binary_relation_exprt ge_zero(length, ID_ge, zero);
291 
293  return throw_exception(
294  not_exprt(ge_zero),
295  original_loc,
296  "java.lang.NegativeArraySizeException");
297 
298  source_locationt check_loc;
299  check_loc.set_comment("Array size should be >= 0");
300  check_loc.set_property_class("array-create-negative-size");
301 
302  return create_fatal_assertion(ge_zero, check_loc);
303 }
304 
310  code_blockt &block,
311  const exprt &expr)
312 {
313  if(optionalt<codet> expr_instrumentation = instrument_expr(expr))
314  {
315  if(expr_instrumentation->get_statement() == ID_block)
316  block.append(to_code_block(*expr_instrumentation));
317  else
318  block.add(std::move(*expr_instrumentation));
319  }
320 }
321 
327  codet &code,
328  code_blockt &instrumentation)
329 {
330  if(instrumentation!=code_blockt())
331  {
332  if(code.get_statement()==ID_block)
333  instrumentation.append(to_code_block(code));
334  else
335  instrumentation.add(code);
336  code=instrumentation;
337  }
338 }
339 
344 {
345  source_locationt old_source_location=code.source_location();
346 
347  const irep_idt &statement=code.get_statement();
348 
349  if(statement==ID_assign)
350  {
351  code_assignt code_assign=to_code_assign(code);
352 
353  code_blockt block;
354  add_expr_instrumentation(block, code_assign.lhs());
355  add_expr_instrumentation(block, code_assign.rhs());
356  prepend_instrumentation(code, block);
357  }
358  else if(statement==ID_expression)
359  {
360  code_expressiont code_expression=
361  to_code_expression(code);
362 
363  code_blockt block;
364  add_expr_instrumentation(block, code_expression.expression());
365  prepend_instrumentation(code, block);
366  }
367  else if(statement==ID_assert)
368  {
369  const code_assertt &code_assert=to_code_assert(code);
370 
371  // does this correspond to checkcast?
372  if(code_assert.assertion().id()==ID_java_instanceof)
373  {
374  code_blockt block;
375  const auto & instanceof
376  = to_java_instanceof_expr(code_assert.assertion());
377 
378  code = check_class_cast(instanceof.tested_expr(),
379  instanceof
380  .target_type(), code_assert.source_location());
381  }
382  }
383  else if(statement==ID_block)
384  {
385  Forall_operands(it, code)
386  instrument_code(to_code(*it));
387  }
388  else if(statement==ID_label)
389  {
390  code_labelt &code_label=to_code_label(code);
391  instrument_code(code_label.code());
392  }
393  else if(statement==ID_ifthenelse)
394  {
395  code_blockt block;
396  code_ifthenelset &code_ifthenelse=to_code_ifthenelse(code);
397  add_expr_instrumentation(block, code_ifthenelse.cond());
398  instrument_code(code_ifthenelse.then_case());
399  if(code_ifthenelse.else_case().is_not_nil())
400  instrument_code(code_ifthenelse.else_case());
401  prepend_instrumentation(code, block);
402  }
403  else if(statement==ID_switch)
404  {
405  code_blockt block;
406  code_switcht &code_switch=to_code_switch(code);
407  add_expr_instrumentation(block, code_switch.value());
408  add_expr_instrumentation(block, code_switch.body());
409  prepend_instrumentation(code, block);
410  }
411  else if(statement==ID_return)
412  {
413  code_blockt block;
414  code_returnt &code_return = to_code_return(code);
415  add_expr_instrumentation(block, code_return.return_value());
416  prepend_instrumentation(code, block);
417  }
418  else if(statement==ID_function_call)
419  {
420  code_blockt block;
421  code_function_callt &code_function_call=to_code_function_call(code);
422  add_expr_instrumentation(block, code_function_call.lhs());
423  add_expr_instrumentation(block, code_function_call.function());
424 
425  const java_method_typet &function_type =
426  to_java_method_type(code_function_call.function().type());
427 
428  for(const auto &arg : code_function_call.arguments())
429  add_expr_instrumentation(block, arg);
430 
431  // Check for a null this-argument of a virtual call:
432  if(function_type.has_this())
433  {
435  code_function_call.arguments()[0],
436  code_function_call.source_location()));
437  }
438 
439  prepend_instrumentation(code, block);
440  }
441 
442  // Ensure source location is retained:
443  if(!old_source_location.get_line().empty())
444  merge_source_location_rec(code, old_source_location);
445 }
446 
452 {
453  code_blockt result;
454  // First check our operands:
455  forall_operands(it, expr)
456  {
457  if(optionalt<codet> op_result = instrument_expr(*it))
458  result.add(std::move(*op_result));
459  }
460 
461  // Add any check due at this node:
462  if(expr.id()==ID_plus &&
463  expr.get_bool(ID_java_array_access))
464  {
465  // this corresponds to ?aload and ?astore so
466  // we check that 0<=index<array.length
467  const plus_exprt &plus_expr=to_plus_expr(expr);
468  if(plus_expr.op0().id()==ID_member)
469  {
470  const member_exprt &member_expr=to_member_expr(plus_expr.op0());
471  if(member_expr.compound().id() == ID_dereference)
472  {
473  const dereference_exprt &dereference_expr =
474  to_dereference_expr(member_expr.compound());
475  codet bounds_check=
477  dereference_expr,
478  plus_expr.op1(),
479  expr.source_location());
480  result.add(std::move(bounds_check));
481  }
482  }
483  }
484  else if(expr.id()==ID_side_effect)
485  {
486  const side_effect_exprt &side_effect_expr=to_side_effect_expr(expr);
487  const irep_idt &statement=side_effect_expr.get_statement();
488  if(statement==ID_throw)
489  {
490  // this corresponds to a throw and so we check that
491  // we don't throw null
493  to_unary_expr(expr).op(), expr.source_location()));
494  }
495  else if(statement==ID_java_new_array)
496  {
497  // this corresponds to new array so we check that
498  // length is >=0
499  result.add(check_array_length(
500  to_multi_ary_expr(expr).op0(), expr.source_location()));
501  }
502  }
503  else if((expr.id()==ID_div || expr.id()==ID_mod) &&
504  expr.type().id()==ID_signedbv)
505  {
506  // check division by zero (for integer types only)
508  to_binary_expr(expr).op1(), expr.source_location()));
509  }
510  else if(expr.id()==ID_dereference &&
511  expr.get_bool(ID_java_member_access))
512  {
513  // Check pointer non-null before access:
514  const dereference_exprt &dereference_expr = to_dereference_expr(expr);
515  codet null_dereference_check = check_null_dereference(
516  dereference_expr.pointer(), dereference_expr.source_location());
517  result.add(std::move(null_dereference_check));
518  }
519 
520  if(result==code_blockt())
521  return {};
522  else
523  return std::move(result);
524 }
525 
529 {
530  instrument_code(code);
531 }
532 
545  symbol_table_baset &symbol_table,
546  symbolt &symbol,
547  const bool throw_runtime_exceptions,
548  message_handlert &message_handler)
549 {
550  java_bytecode_instrumentt instrument(
551  symbol_table,
552  throw_runtime_exceptions,
553  message_handler);
554  INVARIANT(
555  symbol.value.id()==ID_code,
556  "java_bytecode_instrument expects a code-typed symbol but was called with"
557  " " + id2string(symbol.name) + " which has a value with an id of " +
558  id2string(symbol.value.id()));
559  instrument(to_code(symbol.value));
560 }
561 
568  code_blockt &init_code,
569  const symbolt &exc_symbol,
570  const source_locationt &source_location)
571 {
572  // check that there is no uncaught exception
573  code_assertt assert_no_exception(equal_exprt(
574  exc_symbol.symbol_expr(),
575  null_pointer_exprt(to_pointer_type(exc_symbol.type))));
576 
577  source_locationt assert_location = source_location;
578  assert_location.set_comment("no uncaught exception");
579  assert_no_exception.add_source_location() = assert_location;
580 
581  init_code.add(std::move(assert_no_exception));
582 }
583 
595  symbol_tablet &symbol_table,
596  const bool throw_runtime_exceptions,
597  message_handlert &message_handler)
598 {
599  java_bytecode_instrumentt instrument(
600  symbol_table,
601  throw_runtime_exceptions,
602  message_handler);
603 
604  std::vector<irep_idt> symbols_to_instrument;
605  for(const auto &symbol_pair : symbol_table.symbols)
606  {
607  if(symbol_pair.second.value.id() == ID_code)
608  {
609  symbols_to_instrument.push_back(symbol_pair.first);
610  }
611  }
612 
613  // instrument(...) can add symbols to the table, so it's
614  // not safe to hold a reference to a symbol across a call.
615  for(const auto &symbol : symbols_to_instrument)
616  {
617  instrument(to_code(symbol_table.get_writeable_ref(symbol).value));
618  }
619 }
java_bytecode_instrumentt::check_arithmetic_exception
codet check_arithmetic_exception(const exprt &denominator, const source_locationt &original_loc)
Checks whether there is a division by zero and throws ArithmeticException if necessary.
Definition: java_bytecode_instrument.cpp:138
exprt::copy_to_operands
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
Definition: expr.h:133
symbol_table_baset::has_symbol
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
Definition: symbol_table_base.h:87
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
code_blockt
A codet representing sequential composition of program statements.
Definition: std_code.h:170
typecast_exprt::conditional_cast
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:1789
symbol_tablet
The symbol table.
Definition: symbol_table.h:20
to_unary_expr
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
Definition: std_expr.h:329
to_code_expression
code_expressiont & to_code_expression(codet &code)
Definition: std_code.h:1876
source_locationt::set_comment
void set_comment(const irep_idt &comment)
Definition: source_location.h:141
Forall_operands
#define Forall_operands(it, expr)
Definition: expr.h:25
java_bytecode_instrumentt::check_array_length
codet check_array_length(const exprt &length, const source_locationt &original_loc)
Checks whether length >= 0 and throws NegativeArraySizeException/ generates an assertion when necessa...
Definition: java_bytecode_instrument.cpp:285
arith_tools.h
to_dereference_expr
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
Definition: pointer_expr.h:312
typet
The type of an expression, extends irept.
Definition: type.h:28
code_assignt::rhs
exprt & rhs()
Definition: std_code.h:317
code_ifthenelset::then_case
const codet & then_case() const
Definition: std_code.h:806
java_bytecode_instrumentt::add_expr_instrumentation
void add_expr_instrumentation(code_blockt &block, const exprt &expr)
Checks whether expr requires instrumentation, and if so adds it to block.
Definition: java_bytecode_instrument.cpp:309
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
dereference_exprt
Operator to dereference a pointer.
Definition: pointer_expr.h:256
java_bytecode_instrumentt::operator()
void operator()(codet &code)
Instruments code.
Definition: java_bytecode_instrument.cpp:528
java_bytecode_instrumentt
Definition: java_bytecode_instrument.cpp:26
java_bytecode_instrumentt::check_array_access
codet check_array_access(const exprt &array_struct, const exprt &idx, const source_locationt &original_loc)
Checks whether the array access array_struct[idx] is out-of-bounds, and throws ArrayIndexOutofBoundsE...
Definition: java_bytecode_instrument.cpp:169
code_assertt
A non-fatal assertion, which checks a condition then permits execution to continue.
Definition: std_code.h:619
and_exprt
Boolean AND.
Definition: std_expr.h:1835
plus_exprt
The plus expression Associativity is not specified.
Definition: std_expr.h:831
generate_class_stub
void generate_class_stub(const irep_idt &class_name, symbol_table_baset &symbol_table, message_handlert &message_handler, const struct_union_typet::componentst &componentst)
Definition: java_utils.cpp:161
exprt
Base class for all expressions.
Definition: expr.h:54
struct_union_typet::componentst
std::vector< componentt > componentst
Definition: std_types.h:135
struct_tag_typet
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:498
java_expr.h
Java-specific exprt subclasses.
code_ifthenelset::cond
const exprt & cond() const
Definition: std_code.h:796
java_bytecode_instrumentt::symbol_table
symbol_table_baset & symbol_table
Definition: java_bytecode_instrument.cpp:41
to_side_effect_expr
side_effect_exprt & to_side_effect_expr(exprt &expr)
Definition: std_code.h:1954
equal_exprt
Equality.
Definition: std_expr.h:1140
java_bytecode_instrumentt::check_class_cast
code_ifthenelset check_class_cast(const exprt &tested_expr, const struct_tag_typet &target_type, const source_locationt &original_loc)
Checks whether class1 is an instance of class2 and throws ClassCastException/generates an assertion w...
Definition: java_bytecode_instrument.cpp:212
java_bytecode_instrumentt::message_handler
message_handlert & message_handler
Definition: java_bytecode_instrument.cpp:43
code_function_callt::lhs
exprt & lhs()
Definition: std_code.h:1240
create_fatal_assertion
code_blockt create_fatal_assertion(const exprt &condition, const source_locationt &loc)
Create a fatal assertion, which checks a condition and then halts if it does not hold.
Definition: std_code.cpp:122
code_ifthenelset
codet representation of an if-then-else statement.
Definition: std_code.h:778
source_locationt::get_line
const irep_idt & get_line() const
Definition: source_location.h:46
notequal_exprt
Disequality.
Definition: std_expr.h:1198
code_labelt::code
codet & code()
Definition: std_code.h:1425
to_code
const codet & to_code(const exprt &expr)
Definition: std_code.h:155
to_binary_expr
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
Definition: std_expr.h:628
java_bytecode_instrumentt::prepend_instrumentation
void prepend_instrumentation(codet &code, code_blockt &instrumentation)
Appends code to instrumentation and overwrites reference code with the augmented block if instrumenta...
Definition: java_bytecode_instrument.cpp:326
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:82
java_bytecode_instrumentt::instrument_expr
optionalt< codet > instrument_expr(const exprt &expr)
Computes the instrumentation for expr in the form of either assertions or runtime exceptions.
Definition: java_bytecode_instrument.cpp:451
to_code_assert
const code_assertt & to_code_assert(const codet &code)
Definition: std_code.h:652
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1215
irept::get_bool
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:64
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:391
code_assertt::assertion
const exprt & assertion() const
Definition: std_code.h:625
java_bytecode_instrumentt::throw_exception
code_ifthenelset throw_exception(const exprt &cond, const source_locationt &original_loc, const irep_idt &exc_name)
Creates a class stub for exc_name and generates a conditional GOTO such that exc_name is thrown when ...
Definition: java_bytecode_instrument.cpp:94
null_pointer_exprt
The null pointer constant.
Definition: std_expr.h:2751
symbol_table_baset::get_writeable_ref
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
Definition: symbol_table_base.h:121
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
member_exprt::compound
const exprt & compound() const
Definition: std_expr.h:2569
java_bytecode_instrumentt::throw_runtime_exceptions
const bool throw_runtime_exceptions
Definition: java_bytecode_instrument.cpp:42
forall_operands
#define forall_operands(it, expr)
Definition: expr.h:18
to_code_ifthenelse
const code_ifthenelset & to_code_ifthenelse(const codet &code)
Definition: std_code.h:848
code_labelt
codet representation of a label for branch targets.
Definition: std_code.h:1407
multi_ary_exprt::op1
exprt & op1()
Definition: std_expr.h:767
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
dereference_exprt::pointer
exprt & pointer()
Definition: pointer_expr.h:269
to_code_label
const code_labelt & to_code_label(const codet &code)
Definition: std_code.h:1452
symbolt::symbol_expr
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:122
to_plus_expr
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
Definition: std_expr.h:870
code_assignt::lhs
exprt & lhs()
Definition: std_code.h:312
java_entry_point.h
pointer_type
pointer_typet pointer_type(const typet &subtype)
Definition: c_types.cpp:243
irept::id
const irep_idt & id() const
Definition: irep.h:407
message_handlert
Definition: message.h:28
to_code_function_call
const code_function_callt & to_code_function_call(const codet &code)
Definition: std_code.h:1326
dstringt::empty
bool empty() const
Definition: dstring.h:88
to_code_return
const code_returnt & to_code_return(const codet &code)
Definition: std_code.h:1391
code_blockt::add
void add(const codet &code)
Definition: std_code.h:208
java_int_type
signedbv_typet java_int_type()
Definition: java_types.cpp:32
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: std_types.h:1533
std_code.h
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1260
fresh_java_symbol
symbolt & fresh_java_symbol(const typet &type, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &function_name, symbol_table_baset &symbol_table)
Definition: java_utils.cpp:558
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
code_typet::has_this
bool has_this() const
Definition: std_types.h:821
java_bytecode_instrument_uncaught_exceptions
void java_bytecode_instrument_uncaught_exceptions(code_blockt &init_code, const symbolt &exc_symbol, const source_locationt &source_location)
Instruments the start function with an assertion that checks whether an exception has escaped the ent...
Definition: java_bytecode_instrument.cpp:567
side_effect_exprt::get_statement
const irep_idt & get_statement() const
Definition: std_code.h:1920
source_locationt
Definition: source_location.h:20
java_bytecode_instrument
void java_bytecode_instrument(symbol_tablet &symbol_table, const bool throw_runtime_exceptions, message_handlert &message_handler)
Instruments all the code in the symbol_table with runtime exceptions or corresponding assertions.
Definition: java_bytecode_instrument.cpp:594
member_exprt
Extract member of struct or union.
Definition: std_expr.h:2528
merge_source_location_rec
void merge_source_location_rec(exprt &expr, const source_locationt &source_location)
Attaches a source location to an expression and all of its subexpressions.
Definition: java_utils.cpp:200
code_switcht::value
const exprt & value() const
Definition: std_code.h:873
java_bytecode_instrumentt::instrument_code
void instrument_code(codet &code)
Augments code with instrumentation in the form of either assertions or runtime exceptions.
Definition: java_bytecode_instrument.cpp:343
symbolt::value
exprt value
Initial value of symbol.
Definition: symbol.h:34
code_returnt
codet representation of a "return from a function" statement.
Definition: std_code.h:1342
to_code_assign
const code_assignt & to_code_assign(const codet &code)
Definition: std_code.h:383
check_code
void check_code(const codet &code, const validation_modet vm)
Check that the given code statement is well-formed (shallow checks only, i.e., enclosed statements,...
Definition: validate_code.cpp:70
to_java_instanceof_expr
const java_instanceof_exprt & to_java_instanceof_expr(const exprt &expr)
Cast an exprt to a java_instanceof_exprt.
Definition: java_expr.h:86
exception_needed_classes
const std::vector< std::string > exception_needed_classes
Definition: java_bytecode_instrument.cpp:78
code_switcht
codet representing a switch statement.
Definition: std_code.h:866
symbolt
Symbol table entry.
Definition: symbol.h:28
from_integer
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:99
code_blockt::append
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
Definition: std_code.cpp:88
symbol_table_baset::symbols
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Definition: symbol_table_base.h:30
binary_relation_exprt
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition: std_expr.h:675
code_ifthenelset::else_case
const codet & else_case() const
Definition: std_code.h:816
to_code_switch
const code_switcht & to_code_switch(const codet &code)
Definition: std_code.h:910
goto_functions.h
Goto Programs with Functions.
java_bytecode_instrumentt::java_bytecode_instrumentt
java_bytecode_instrumentt(symbol_table_baset &_symbol_table, const bool _throw_runtime_exceptions, message_handlert &_message_handler)
Definition: java_bytecode_instrument.cpp:28
side_effect_expr_throwt
A side_effect_exprt representation of a side effect that throws an exception.
Definition: std_code.h:2205
to_code_block
const code_blockt & to_code_block(const codet &code)
Definition: std_code.h:256
to_member_expr
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition: std_expr.h:2612
java_bytecode_instrument_symbol
void java_bytecode_instrument_symbol(symbol_table_baset &symbol_table, symbolt &symbol, const bool throw_runtime_exceptions, message_handlert &message_handler)
Instruments the code attached to symbol with runtime exceptions or corresponding assertions.
Definition: java_bytecode_instrument.cpp:544
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:383
code_expressiont::expression
const exprt & expression() const
Definition: std_code.h:1849
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
exprt::add_source_location
source_locationt & add_source_location()
Definition: expr.h:239
to_java_method_type
const java_method_typet & to_java_method_type(const typet &type)
Definition: java_types.h:186
java_bytecode_instrument.h
code_switcht::body
const codet & body() const
Definition: std_code.h:883
pointer_typet
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: std_types.h:1495
code_returnt::return_value
const exprt & return_value() const
Definition: std_code.h:1352
java_void_type
empty_typet java_void_type()
Definition: java_types.cpp:38
code_assignt
A codet representing an assignment in the program.
Definition: std_code.h:295
java_utils.h
codet::get_statement
const irep_idt & get_statement() const
Definition: std_code.h:71
constant_exprt
A constant literal expression.
Definition: std_expr.h:2668
multi_ary_exprt::op0
exprt & op0()
Definition: std_expr.h:761
to_multi_ary_expr
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
Definition: std_expr.h:816
std_expr.h
API to expression classes.
exprt::source_location
const source_locationt & source_location() const
Definition: expr.h:234
java_bytecode_instrumentt::check_null_dereference
codet check_null_dereference(const exprt &expr, const source_locationt &original_loc)
Checks whether expr is null and throws NullPointerException/ generates an assertion when necessary; E...
Definition: java_bytecode_instrument.cpp:256
java_method_typet
Definition: java_types.h:103
c_types.h
symbolt::name
irep_idt name
The unique identifier.
Definition: symbol.h:40
code_function_callt::function
exprt & function()
Definition: std_code.h:1250
side_effect_exprt
An expression containing a side effect.
Definition: std_code.h:1898
java_instanceof_exprt
Definition: java_expr.h:18
java_bytecode_convert_class.h
JAVA Bytecode Language Conversion.
code_expressiont
codet representation of an expression statement.
Definition: std_code.h:1842
source_locationt::set_property_class
void set_property_class(const irep_idt &property_class)
Definition: source_location.h:136
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code.h:35
not_exprt
Boolean negation.
Definition: std_expr.h:2042