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/c_types.h>
15 #include <util/std_code.h>
16 #include <util/symbol_table.h>
17 
18 #include "java_expr.h"
19 #include "java_types.h"
20 #include "java_utils.h"
21 
23 {
24 public:
26  symbol_table_baset &_symbol_table,
27  const bool _throw_runtime_exceptions,
28  message_handlert &_message_handler)
29  : symbol_table(_symbol_table),
30  throw_runtime_exceptions(_throw_runtime_exceptions),
31  message_handler(_message_handler)
32  {
33  }
34 
35  void operator()(codet &code);
36 
37 protected:
41 
43  const exprt &cond,
44  const source_locationt &original_loc,
45  const irep_idt &exc_name);
46 
48  const exprt &array_struct,
49  const exprt &idx,
50  const source_locationt &original_loc);
51 
53  const exprt &denominator,
54  const source_locationt &original_loc);
55 
57  const exprt &expr,
58  const source_locationt &original_loc);
59 
61  const exprt &tested_expr,
62  const struct_tag_typet &target_type,
63  const source_locationt &original_loc);
64 
66  const exprt &length,
67  const source_locationt &original_loc);
68 
69  void instrument_code(codet &code);
70  void add_expr_instrumentation(code_blockt &block, const exprt &expr);
71  void prepend_instrumentation(codet &code, code_blockt &instrumentation);
73 };
74 
75 const std::vector<std::string> exception_needed_classes = {
76  "java.lang.ArithmeticException",
77  "java.lang.ArrayIndexOutOfBoundsException",
78  "java.lang.ClassCastException",
79  "java.lang.NegativeArraySizeException",
80  "java.lang.NullPointerException"};
81 
92  const exprt &cond,
93  const source_locationt &original_loc,
94  const irep_idt &exc_name)
95 {
96  irep_idt exc_class_name("java::"+id2string(exc_name));
97 
98  if(!symbol_table.has_symbol(exc_class_name))
99  {
101  exc_name,
102  symbol_table,
105  }
106 
107  pointer_typet exc_ptr_type = pointer_type(struct_tag_typet(exc_class_name));
108 
109  // Allocate and throw an instance of the exception class:
110 
111  symbolt &new_symbol = fresh_java_symbol(
112  exc_ptr_type, "new_exception", original_loc, "new_exception", symbol_table);
113 
114  side_effect_exprt new_instance(ID_java_new, exc_ptr_type, original_loc);
115  code_assignt assign_new(new_symbol.symbol_expr(), new_instance);
116 
117  side_effect_expr_throwt throw_expr(irept(), typet(), original_loc);
118  throw_expr.copy_to_operands(new_symbol.symbol_expr());
119 
120  code_ifthenelset if_code(
121  cond, code_blockt({assign_new, code_expressiont(throw_expr)}));
122 
123  if_code.add_source_location()=original_loc;
124 
125  return if_code;
126 }
127 
136  const exprt &denominator,
137  const source_locationt &original_loc)
138 {
139  const constant_exprt &zero=from_integer(0, denominator.type());
140  const binary_relation_exprt equal_zero(denominator, ID_equal, zero);
141 
143  return throw_exception(
144  equal_zero,
145  original_loc,
146  "java.lang.ArithmeticException");
147 
148  source_locationt assertion_loc = original_loc;
149  assertion_loc.set_comment("Denominator should be nonzero");
150  assertion_loc.set_property_class("integer-divide-by-zero");
151 
152  return create_fatal_assertion(
153  binary_relation_exprt(denominator, ID_notequal, zero), assertion_loc);
154 }
155 
167  const exprt &array_struct,
168  const exprt &idx,
169  const source_locationt &original_loc)
170 {
171  const constant_exprt &zero=from_integer(0, java_int_type());
172  const binary_relation_exprt ge_zero(idx, ID_ge, zero);
173  const member_exprt length_field(array_struct, "length", java_int_type());
174  const binary_relation_exprt lt_length(idx, ID_lt, length_field);
175  const and_exprt cond(ge_zero, lt_length);
176 
178  return throw_exception(
179  not_exprt(cond),
180  original_loc,
181  "java.lang.ArrayIndexOutOfBoundsException");
182 
183  code_blockt bounds_checks;
184 
185  source_locationt low_check_loc = original_loc;
186  low_check_loc.set_comment("Array index should be >= 0");
187  low_check_loc.set_property_class("array-index-out-of-bounds-low");
188 
189  source_locationt high_check_loc = original_loc;
190  high_check_loc.set_comment("Array index should be < length");
191  high_check_loc.set_property_class("array-index-out-of-bounds-high");
192 
193  bounds_checks.add(create_fatal_assertion(ge_zero, low_check_loc));
194  bounds_checks.add(create_fatal_assertion(lt_length, high_check_loc));
195 
196  return std::move(bounds_checks);
197 }
198 
210  const exprt &tested_expr,
211  const struct_tag_typet &target_type,
212  const source_locationt &original_loc)
213 {
214  java_instanceof_exprt class_cast_check(tested_expr, target_type);
215 
217  exprt null_check_op = typecast_exprt::conditional_cast(tested_expr, voidptr);
218 
221  {
222  check_code=
224  not_exprt(class_cast_check),
225  original_loc,
226  "java.lang.ClassCastException");
227  }
228  else
229  {
230  source_locationt check_loc = original_loc;
231  check_loc.set_comment("Dynamic cast check");
232  check_loc.set_property_class("bad-dynamic-cast");
233 
234  codet assert_class = create_fatal_assertion(class_cast_check, check_loc);
235 
236  check_code=std::move(assert_class);
237  }
238 
239  return code_ifthenelset(
240  notequal_exprt(std::move(null_check_op), null_pointer_exprt(voidptr)),
241  std::move(*check_code));
242 }
243 
254  const exprt &expr,
255  const source_locationt &original_loc)
256 {
257  const equal_exprt equal_expr(
258  expr,
260 
262  return throw_exception(
263  equal_expr,
264  original_loc, "java.lang.NullPointerException");
265 
266  source_locationt check_loc = original_loc;
267  check_loc.set_comment("Null pointer check");
268  check_loc.set_property_class("null-pointer-exception");
269 
270  return create_fatal_assertion(not_exprt(equal_expr), check_loc);
271 }
272 
283  const exprt &length,
284  const source_locationt &original_loc)
285 {
286  const constant_exprt &zero=from_integer(0, java_int_type());
287  const binary_relation_exprt ge_zero(length, ID_ge, zero);
288 
290  return throw_exception(
291  not_exprt(ge_zero),
292  original_loc,
293  "java.lang.NegativeArraySizeException");
294 
295  source_locationt check_loc;
296  check_loc.set_comment("Array size should be >= 0");
297  check_loc.set_property_class("array-create-negative-size");
298 
299  return create_fatal_assertion(ge_zero, check_loc);
300 }
301 
307  code_blockt &block,
308  const exprt &expr)
309 {
310  if(optionalt<codet> expr_instrumentation = instrument_expr(expr))
311  {
312  if(expr_instrumentation->get_statement() == ID_block)
313  block.append(to_code_block(*expr_instrumentation));
314  else
315  block.add(std::move(*expr_instrumentation));
316  }
317 }
318 
324  codet &code,
325  code_blockt &instrumentation)
326 {
327  if(instrumentation!=code_blockt())
328  {
329  if(code.get_statement()==ID_block)
330  instrumentation.append(to_code_block(code));
331  else
332  instrumentation.add(code);
333  code=instrumentation;
334  }
335 }
336 
341 {
342  source_locationt old_source_location=code.source_location();
343 
344  const irep_idt &statement=code.get_statement();
345 
346  if(statement==ID_assign)
347  {
348  code_assignt code_assign=to_code_assign(code);
349 
350  code_blockt block;
351  add_expr_instrumentation(block, code_assign.lhs());
352  add_expr_instrumentation(block, code_assign.rhs());
353  prepend_instrumentation(code, block);
354  }
355  else if(statement==ID_expression)
356  {
357  code_expressiont code_expression=
358  to_code_expression(code);
359 
360  code_blockt block;
361  add_expr_instrumentation(block, code_expression.expression());
362  prepend_instrumentation(code, block);
363  }
364  else if(statement==ID_assert)
365  {
366  const code_assertt &code_assert=to_code_assert(code);
367 
368  // does this correspond to checkcast?
369  if(code_assert.assertion().id()==ID_java_instanceof)
370  {
371  code_blockt block;
372  const auto & instanceof
373  = to_java_instanceof_expr(code_assert.assertion());
374 
375  code = check_class_cast(instanceof.tested_expr(),
376  instanceof
377  .target_type(), code_assert.source_location());
378  }
379  }
380  else if(statement==ID_block)
381  {
382  Forall_operands(it, code)
383  instrument_code(to_code(*it));
384  }
385  else if(statement==ID_label)
386  {
387  code_labelt &code_label=to_code_label(code);
388  instrument_code(code_label.code());
389  }
390  else if(statement==ID_ifthenelse)
391  {
392  code_blockt block;
393  code_ifthenelset &code_ifthenelse=to_code_ifthenelse(code);
394  add_expr_instrumentation(block, code_ifthenelse.cond());
395  instrument_code(code_ifthenelse.then_case());
396  if(code_ifthenelse.else_case().is_not_nil())
397  instrument_code(code_ifthenelse.else_case());
398  prepend_instrumentation(code, block);
399  }
400  else if(statement==ID_switch)
401  {
402  code_blockt block;
403  code_switcht &code_switch=to_code_switch(code);
404  add_expr_instrumentation(block, code_switch.value());
405  add_expr_instrumentation(block, code_switch.body());
406  prepend_instrumentation(code, block);
407  }
408  else if(statement==ID_return)
409  {
410  code_blockt block;
411  code_returnt &code_return = to_code_return(code);
412  add_expr_instrumentation(block, code_return.return_value());
413  prepend_instrumentation(code, block);
414  }
415  else if(statement==ID_function_call)
416  {
417  code_blockt block;
418  code_function_callt &code_function_call=to_code_function_call(code);
419  add_expr_instrumentation(block, code_function_call.lhs());
420  add_expr_instrumentation(block, code_function_call.function());
421 
422  const java_method_typet &function_type =
423  to_java_method_type(code_function_call.function().type());
424 
425  for(const auto &arg : code_function_call.arguments())
426  add_expr_instrumentation(block, arg);
427 
428  // Check for a null this-argument of a virtual call:
429  if(function_type.has_this())
430  {
432  code_function_call.arguments()[0],
433  code_function_call.source_location()));
434  }
435 
436  prepend_instrumentation(code, block);
437  }
438 
439  // Ensure source location is retained:
440  if(!old_source_location.get_line().empty())
441  merge_source_location_rec(code, old_source_location);
442 }
443 
449 {
450  code_blockt result;
451  // First check our operands:
452  forall_operands(it, expr)
453  {
454  if(optionalt<codet> op_result = instrument_expr(*it))
455  result.add(std::move(*op_result));
456  }
457 
458  // Add any check due at this node:
459  if(expr.id()==ID_plus &&
460  expr.get_bool(ID_java_array_access))
461  {
462  // this corresponds to ?aload and ?astore so
463  // we check that 0<=index<array.length
464  const plus_exprt &plus_expr=to_plus_expr(expr);
465  if(plus_expr.op0().id()==ID_member)
466  {
467  const member_exprt &member_expr=to_member_expr(plus_expr.op0());
468  if(member_expr.compound().id() == ID_dereference)
469  {
470  const dereference_exprt &dereference_expr =
471  to_dereference_expr(member_expr.compound());
472  codet bounds_check=
474  dereference_expr,
475  plus_expr.op1(),
476  expr.source_location());
477  result.add(std::move(bounds_check));
478  }
479  }
480  }
481  else if(expr.id()==ID_side_effect)
482  {
483  const side_effect_exprt &side_effect_expr=to_side_effect_expr(expr);
484  const irep_idt &statement=side_effect_expr.get_statement();
485  if(statement==ID_throw)
486  {
487  // this corresponds to a throw and so we check that
488  // we don't throw null
490  to_unary_expr(expr).op(), expr.source_location()));
491  }
492  else if(statement==ID_java_new_array)
493  {
494  // this corresponds to new array so we check that
495  // length is >=0
496  result.add(check_array_length(
497  to_multi_ary_expr(expr).op0(), expr.source_location()));
498  }
499  }
500  else if((expr.id()==ID_div || expr.id()==ID_mod) &&
501  expr.type().id()==ID_signedbv)
502  {
503  // check division by zero (for integer types only)
505  to_binary_expr(expr).op1(), expr.source_location()));
506  }
507  else if(expr.id()==ID_dereference &&
508  expr.get_bool(ID_java_member_access))
509  {
510  // Check pointer non-null before access:
511  const dereference_exprt &dereference_expr = to_dereference_expr(expr);
512  codet null_dereference_check = check_null_dereference(
513  dereference_expr.pointer(), dereference_expr.source_location());
514  result.add(std::move(null_dereference_check));
515  }
516 
517  if(result==code_blockt())
518  return {};
519  else
520  return std::move(result);
521 }
522 
526 {
527  instrument_code(code);
528 }
529 
542  symbol_table_baset &symbol_table,
543  symbolt &symbol,
544  const bool throw_runtime_exceptions,
545  message_handlert &message_handler)
546 {
547  java_bytecode_instrumentt instrument(
548  symbol_table,
549  throw_runtime_exceptions,
550  message_handler);
551  INVARIANT(
552  symbol.value.id()==ID_code,
553  "java_bytecode_instrument expects a code-typed symbol but was called with"
554  " " + id2string(symbol.name) + " which has a value with an id of " +
555  id2string(symbol.value.id()));
556  instrument(to_code(symbol.value));
557 }
558 
565  code_blockt &init_code,
566  const symbolt &exc_symbol,
567  const source_locationt &source_location)
568 {
569  // check that there is no uncaught exception
570  code_assertt assert_no_exception(equal_exprt(
571  exc_symbol.symbol_expr(),
572  null_pointer_exprt(to_pointer_type(exc_symbol.type))));
573 
574  source_locationt assert_location = source_location;
575  assert_location.set_comment("no uncaught exception");
576  assert_no_exception.add_source_location() = assert_location;
577 
578  init_code.add(std::move(assert_no_exception));
579 }
580 
592  symbol_tablet &symbol_table,
593  const bool throw_runtime_exceptions,
594  message_handlert &message_handler)
595 {
596  java_bytecode_instrumentt instrument(
597  symbol_table,
598  throw_runtime_exceptions,
599  message_handler);
600 
601  std::vector<irep_idt> symbols_to_instrument;
602  for(const auto &symbol_pair : symbol_table.symbols)
603  {
604  if(symbol_pair.second.value.id() == ID_code)
605  {
606  symbols_to_instrument.push_back(symbol_pair.first);
607  }
608  }
609 
610  // instrument(...) can add symbols to the table, so it's
611  // not safe to hold a reference to a symbol across a call.
612  for(const auto &symbol : symbols_to_instrument)
613  {
614  instrument(to_code(symbol_table.get_writeable_ref(symbol).value));
615  }
616 }
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:135
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:129
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:168
typecast_exprt::conditional_cast
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:1874
symbol_tablet
The symbol table.
Definition: symbol_table.h:14
to_unary_expr
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
Definition: std_expr.h:328
to_code_expression
code_expressiont & to_code_expression(codet &code)
Definition: std_code.h:1874
source_locationt::set_comment
void set_comment(const irep_idt &comment)
Definition: source_location.h:140
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:282
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:684
typet
The type of an expression, extends irept.
Definition: type.h:28
code_assignt::rhs
exprt & rhs()
Definition: std_code.h:315
code_ifthenelset::then_case
const codet & then_case() const
Definition: std_code.h:804
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:306
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
dereference_exprt
Operator to dereference a pointer.
Definition: pointer_expr.h:628
java_bytecode_instrumentt::operator()
void operator()(codet &code)
Instruments code.
Definition: java_bytecode_instrument.cpp:525
java_bytecode_instrumentt
Definition: java_bytecode_instrument.cpp:23
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:166
code_assertt
A non-fatal assertion, which checks a condition then permits execution to continue.
Definition: std_code.h:617
and_exprt
Boolean AND.
Definition: std_expr.h:1920
plus_exprt
The plus expression Associativity is not specified.
Definition: std_expr.h:914
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:140
struct_tag_typet
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:449
java_expr.h
Java-specific exprt subclasses.
code_ifthenelset::cond
const exprt & cond() const
Definition: std_code.h:794
java_bytecode_instrumentt::symbol_table
symbol_table_baset & symbol_table
Definition: java_bytecode_instrument.cpp:38
to_side_effect_expr
side_effect_exprt & to_side_effect_expr(exprt &expr)
Definition: std_code.h:1952
equal_exprt
Equality.
Definition: std_expr.h:1225
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:209
java_bytecode_instrumentt::message_handler
message_handlert & message_handler
Definition: java_bytecode_instrument.cpp:40
code_function_callt::lhs
exprt & lhs()
Definition: std_code.h:1238
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:123
code_ifthenelset
codet representation of an if-then-else statement.
Definition: std_code.h:776
source_locationt::get_line
const irep_idt & get_line() const
Definition: source_location.h:45
notequal_exprt
Disequality.
Definition: std_expr.h:1283
code_labelt::code
codet & code()
Definition: std_code.h:1423
to_code
const codet & to_code(const exprt &expr)
Definition: std_code.h:153
to_binary_expr
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
Definition: std_expr.h:627
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:323
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:448
to_code_assert
const code_assertt & to_code_assert(const codet &code)
Definition: std_code.h:650
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1213
irept::get_bool
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:58
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:391
code_assertt::assertion
const exprt & assertion() const
Definition: std_code.h:623
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:91
null_pointer_exprt
The null pointer constant.
Definition: pointer_expr.h:703
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:2654
java_bytecode_instrumentt::throw_runtime_exceptions
const bool throw_runtime_exceptions
Definition: java_bytecode_instrument.cpp:39
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:846
code_labelt
codet representation of a label for branch targets.
Definition: std_code.h:1405
multi_ary_exprt::op1
exprt & op1()
Definition: std_expr.h:850
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
dereference_exprt::pointer
exprt & pointer()
Definition: pointer_expr.h:641
to_code_label
const code_labelt & to_code_label(const codet &code)
Definition: std_code.h:1450
symbolt::symbol_expr
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:121
to_plus_expr
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
Definition: std_expr.h:953
code_assignt::lhs
exprt & lhs()
Definition: std_code.h:310
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: pointer_expr.h:62
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:1324
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:1389
code_blockt::add
void add(const codet &code)
Definition: std_code.h:206
java_int_type
signedbv_typet java_int_type()
Definition: java_types.cpp:31
std_code.h
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1258
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:616
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:564
side_effect_exprt::get_statement
const irep_idt & get_statement() const
Definition: std_code.h:1918
source_locationt
Definition: source_location.h:19
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:591
member_exprt
Extract member of struct or union.
Definition: std_expr.h:2613
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:871
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:340
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:1340
to_code_assign
const code_assignt & to_code_assign(const codet &code)
Definition: std_code.h:381
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:68
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:75
code_switcht
codet representing a switch statement.
Definition: std_code.h:864
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:89
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:674
code_ifthenelset::else_case
const codet & else_case() const
Definition: std_code.h:814
to_code_switch
const code_switcht & to_code_switch(const codet &code)
Definition: std_code.h:908
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:25
side_effect_expr_throwt
A side_effect_exprt representation of a side effect that throws an exception.
Definition: std_code.h:2203
to_code_block
const code_blockt & to_code_block(const codet &code)
Definition: std_code.h:254
to_member_expr
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition: std_expr.h:2697
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:541
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:1847
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:423
java_types.h
exprt::add_source_location
source_locationt & add_source_location()
Definition: expr.h:235
to_java_method_type
const java_method_typet & to_java_method_type(const typet &type)
Definition: java_types.h:184
java_bytecode_instrument.h
symbol_table.h
Author: Diffblue Ltd.
code_switcht::body
const codet & body() const
Definition: std_code.h:881
pointer_typet
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:24
code_returnt::return_value
const exprt & return_value() const
Definition: std_code.h:1350
java_void_type
empty_typet java_void_type()
Definition: java_types.cpp:37
code_assignt
A codet representing an assignment in the program.
Definition: std_code.h:293
java_utils.h
codet::get_statement
const irep_idt & get_statement() const
Definition: std_code.h:69
constant_exprt
A constant literal expression.
Definition: std_expr.h:2753
multi_ary_exprt::op0
exprt & op0()
Definition: std_expr.h:844
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:899
exprt::source_location
const source_locationt & source_location() const
Definition: expr.h:230
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:253
java_method_typet
Definition: java_types.h:101
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:1248
side_effect_exprt
An expression containing a side effect.
Definition: std_code.h:1896
java_instanceof_exprt
Definition: java_expr.h:18
code_expressiont
codet representation of an expression statement.
Definition: std_code.h:1840
source_locationt::set_property_class
void set_property_class(const irep_idt &property_class)
Definition: source_location.h:135
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code.h:33
not_exprt
Boolean negation.
Definition: std_expr.h:2127