Skip to content

Commit 1f2bb67

Browse files
authored
Merge pull request #1229 from smowton/smowton/feature/use_null_check_annotation_everywhere
Use null check annotation everywhere
2 parents c659d13 + 1b47689 commit 1f2bb67

File tree

13 files changed

+90
-55
lines changed

13 files changed

+90
-55
lines changed

regression/cbmc-java/stack_var4/test.desc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ stack_test.class
33

44
^EXIT=0$
55
^SIGNAL=0$
6-
^.*assertion at file stack_test.java line 5 function.*: SUCCESS
7-
$
86
^VERIFICATION SUCCESSFUL$
97
--
108
^warning: ignoring

regression/cbmc-java/stack_var5/test.desc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ stack_test.class
33

44
^EXIT=0$
55
^SIGNAL=0$
6-
^.*assertion at file stack_test.java line 5 function.*: SUCCESS
7-
$
86
^VERIFICATION SUCCESSFUL$
97
--
108
^warning: ignoring

regression/cbmc-java/stack_var6/test.desc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ stack_test.class
33

44
^EXIT=0$
55
^SIGNAL=0$
6-
^.*assertion at file stack_test.java line 5 function.*: SUCCESS
7-
$
86
^VERIFICATION SUCCESSFUL$
97
--
108
^warning: ignoring

regression/cbmc-java/stack_var7/test.desc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ stack_test.class
33

44
^EXIT=0$
55
^SIGNAL=0$
6-
^.*assertion at file stack_test.java line 5 function.*: SUCCESS
7-
$
86
^VERIFICATION SUCCESSFUL$
97
--
108
^warning: ignoring

regression/strings/StaticCharMethods05/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ StaticCharMethods05.class
33
--refine-strings
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[pointer_dereference\.2\] reference is null in \*this->data: FAILURE$
6+
null-pointer-exception\.14\] Throw null: FAILURE
77
^\[.*assertion\.1\] .* line 12 .* FAILURE$
88
^\[.*assertion\.2\] .* line 22 .* FAILURE$
99
^VERIFICATION FAILED$

src/analyses/goto_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ void goto_checkt::pointer_validity_check(
909909
const exprt &access_ub,
910910
const irep_idt &mode)
911911
{
912-
if(mode!=ID_java && !enable_pointer_check)
912+
if(!enable_pointer_check)
913913
return;
914914

915915
const exprt &pointer=expr.op0();

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,7 @@ static member_exprt to_member(const exprt &pointer, const exprt &fieldref)
524524
exprt pointer2=
525525
typecast_exprt(pointer, java_reference_type(class_type));
526526

527-
dereference_exprt obj_deref(pointer2, class_type);
528-
// tag it so it's easy to identify during instrumentation
529-
obj_deref.set(ID_java_member_access, true);
527+
dereference_exprt obj_deref=checked_dereference(pointer2, class_type);
530528

531529
const member_exprt member_expr(
532530
obj_deref,

src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ class java_bytecode_instrumentt:public messaget
2929
java_bytecode_instrumentt(
3030
symbol_tablet &_symbol_table,
3131
const bool _throw_runtime_exceptions,
32-
message_handlert &_message_handler,
33-
const size_t _max_array_length,
34-
const size_t _max_tree_depth):
32+
message_handlert &_message_handler):
3533
messaget(_message_handler),
3634
symbol_table(_symbol_table),
3735
throw_runtime_exceptions(_throw_runtime_exceptions),
38-
message_handler(_message_handler),
39-
max_array_length(_max_array_length),
40-
max_tree_depth(_max_tree_depth)
36+
message_handler(_message_handler)
4137
{
4238
}
4339

@@ -47,8 +43,6 @@ class java_bytecode_instrumentt:public messaget
4743
symbol_tablet &symbol_table;
4844
const bool throw_runtime_exceptions;
4945
message_handlert &message_handler;
50-
const size_t max_array_length;
51-
const size_t max_tree_depth;
5246

5347
codet throw_exception(
5448
const exprt &cond,
@@ -566,29 +560,52 @@ void java_bytecode_instrumentt::operator()(exprt &expr)
566560
instrument_code(expr);
567561
}
568562

563+
/// Instruments the code attached to `symbol` with
564+
/// runtime exceptions or corresponding assertions.
565+
/// Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
566+
/// Otherwise, assertions are emitted.
567+
/// \param symbol_table: global symbol table (may gain exception type stubs and
568+
/// similar)
569+
/// \param symbol: the symbol to instrument
570+
/// \param throw_runtime_exceptions: flag determining whether we instrument the
571+
/// code with runtime exceptions or with assertions. The former applies if
572+
/// this flag is set to true.
573+
/// \param message_handler: stream to report status and warnings
574+
void java_bytecode_instrument_symbol(
575+
symbol_tablet &symbol_table,
576+
symbolt &symbol,
577+
const bool throw_runtime_exceptions,
578+
message_handlert &message_handler)
579+
{
580+
java_bytecode_instrumentt instrument(
581+
symbol_table,
582+
throw_runtime_exceptions,
583+
message_handler);
584+
INVARIANT(
585+
symbol.value.id()==ID_code,
586+
"java_bytecode_instrument expects a code-typed symbol");
587+
instrument(symbol.value);
588+
}
589+
569590
/// Instruments all the code in the symbol_table with
570591
/// runtime exceptions or corresponding assertions.
571592
/// Exceptions are thrown when the `throw_runtime_exceptions` flag is set.
572593
/// Otherwise, assertions are emitted.
573-
/// \par parameters: `symbol_table`: the symbol table to instrument
574-
/// `throw_runtime_exceptions`: flag determining whether we instrument the code
575-
/// with runtime exceptions or with assertions. The former applies if this flag
576-
/// is set to true.
577-
/// `max_array_length`: maximum array length; the only reason we need this is
578-
/// in order to be able to call the object factory to create exceptions.
594+
/// \param symbol_table: global symbol table, all of whose code members
595+
/// will be annotated (may gain exception type stubs and similar)
596+
/// \param throw_runtime_exceptions: flag determining whether we instrument the
597+
/// code with runtime exceptions or with assertions. The former applies if
598+
/// this flag is set to true.
599+
/// \param message_handler: stream to report status and warnings
579600
void java_bytecode_instrument(
580601
symbol_tablet &symbol_table,
581602
const bool throw_runtime_exceptions,
582-
message_handlert &message_handler,
583-
const size_t max_array_length,
584-
const size_t max_tree_depth)
603+
message_handlert &message_handler)
585604
{
586605
java_bytecode_instrumentt instrument(
587606
symbol_table,
588607
throw_runtime_exceptions,
589-
message_handler,
590-
max_array_length,
591-
max_tree_depth);
608+
message_handler);
592609

593610
std::vector<irep_idt> symbols_to_instrument;
594611
forall_symbols(s_it, symbol_table.symbols)
@@ -600,9 +617,5 @@ void java_bytecode_instrument(
600617
// instrument(...) can add symbols to the table, so it's
601618
// not safe to hold a reference to a symbol across a call.
602619
for(const auto &symbol : symbols_to_instrument)
603-
{
604-
exprt value=symbol_table.lookup(symbol).value;
605-
instrument(value);
606-
symbol_table.lookup(symbol).value=value;
607-
}
620+
instrument(symbol_table.lookup(symbol).value);
608621
}

src/java_bytecode/java_bytecode_instrument.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ Date: June 2017
1111
#ifndef CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INSTRUMENT_H
1212
#define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INSTRUMENT_H
1313

14+
void java_bytecode_instrument_symbol(
15+
symbol_tablet &symbol_table,
16+
symbolt &symbol,
17+
const bool throw_runtime_exceptions,
18+
message_handlert &_message_handler);
19+
1420
void java_bytecode_instrument(
1521
symbol_tablet &symbol_table,
1622
const bool throw_runtime_exceptions,
17-
message_handlert &_message_handler,
18-
const size_t max_array_length,
19-
const size_t max_depth);
23+
message_handlert &_message_handler);
24+
2025
#endif

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,7 @@ bool java_bytecode_languaget::typecheck(
459459
java_bytecode_instrument(
460460
symbol_table,
461461
throw_runtime_exceptions,
462-
get_message_handler(),
463-
max_nondet_array_length,
464-
max_nondet_tree_depth);
462+
get_message_handler());
465463

466464
// now typecheck all
467465
if(java_bytecode_typecheck(
@@ -746,6 +744,13 @@ void java_bytecode_languaget::replace_string_methods(
746744
// Replace body of the function by code generated by string preprocess
747745
symbolt &symbol=context.lookup(id);
748746
symbol.value=generated_code;
747+
// Specifically instrument the new code, since this comes after the
748+
// blanket instrumentation pass called before typechecking.
749+
java_bytecode_instrument_symbol(
750+
context,
751+
symbol,
752+
throw_runtime_exceptions,
753+
get_message_handler());
749754
}
750755
}
751756
}

0 commit comments

Comments
 (0)