Skip to content

Commit 53c1efd

Browse files
Merge pull request diffblue#487 from diffblue/CBMC_merge_2018-07-04
CBMC merge 2018-07-04
2 parents 0e117ca + ec74da3 commit 53c1efd

26 files changed

+167
-76
lines changed

cbmc/COMPILING.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ We assume that you have a Debian/Ubuntu or Red Hat-like distribution.
3232
To compile JBMC, you additionally need the JDK and the java-models-library.
3333
For the JDK, on Debian-like distributions, do as root:
3434
```
35-
apt-get install openjdk-8-jdk
35+
apt-get install unzip openjdk-8-jdk
3636
```
3737
On Red Hat/Fedora or derivates, do as root:
3838
```
39-
dnf install java-1.8.0-openjdk-devel
39+
dnf install unzip java-1.8.0-openjdk-devel
4040
```
4141

4242
2. As a user, get the CBMC source via
@@ -180,11 +180,16 @@ Follow these instructions:
180180
have to adjust the section in `src/common` that defines `CC` and `CXX`
181181
for BUILD_ENV = Cygwin.
182182
Then start the Cygwin shell.
183-
4. In the Cygwin shell, type
183+
4. To compile CMBC, open the Cygwin shell and type
184184
```
185185
make -C src DOWNLOADER=wget minisat2-download
186186
make -C src
187187
```
188+
5. To compile JMBC, open the Cygwin shell and type
189+
```
190+
make -C jbmc/src java-models-library-download
191+
make -C jbmc/src
192+
```
188193
189194
(Optional) A Visual Studio project file can be generated with the script
190195
"generate_vcxproj" that is in the subdirectory "scripts". The project file is

cbmc/jbmc/regression/jbmc-strings/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ show:
2828
clean:
2929
find -name '*.out' -execdir $(RM) '{}' \;
3030
find -name '*.gb' -execdir $(RM) '{}' \;
31-
$(RM) tests.log
31+
$(RM) tests.log tests-symex-driven-loading.log

cbmc/jbmc/regression/jbmc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ show:
2020
clean:
2121
find -name '*.out' -execdir $(RM) '{}' \;
2222
find -name '*.gb' -execdir $(RM) '{}' \;
23-
$(RM) tests.log
23+
$(RM) tests.log tests-symex-driven-loading.log
2424

2525
%.class: %.java ../../src/org.cprover.jar
2626
javac -g -cp ../../src/org.cprover.jar:. $<

cbmc/jbmc/src/java_bytecode/expr2java.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ std::string type2java(const typet &type, const namespacet &ns);
5858
template <typename float_type>
5959
std::string floating_point_to_java_string(float_type value)
6060
{
61-
static const bool is_float = std::is_same<float_type, float>::value;
62-
static const std::string class_name = is_float ? "Float" : "Double";
61+
const bool is_float = std::is_same<float_type, float>::value;
62+
const std::string class_name = is_float ? "Float" : "Double";
6363
if(std::isnan(value))
6464
return class_name + ".NaN";
6565
if(std::isinf(value) && value >= 0.)

cbmc/jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ class java_bytecode_convert_classt:public messaget
118118
// see definition below for more info
119119
static void add_array_types(symbol_tablet &symbol_table);
120120

121-
static bool is_overlay_method(const methodt &method);
121+
static bool is_overlay_method(const methodt &method)
122+
{
123+
return method.has_annotation(ID_overlay_method);
124+
}
125+
126+
static bool is_ignored_method(const methodt &method)
127+
{
128+
return method.has_annotation(ID_ignored_method);
129+
}
122130

123131
bool check_field_exists(
124132
const fieldt &field,
@@ -393,7 +401,7 @@ void java_bytecode_convert_classt::convert(
393401
new_symbol.base_name = base_name;
394402
new_symbol.pretty_name=c.name;
395403
new_symbol.name=qualified_classname;
396-
class_type.set(ID_name, new_symbol.name);
404+
class_type.set_name(new_symbol.name);
397405
new_symbol.type=class_type;
398406
new_symbol.mode=ID_java;
399407
new_symbol.is_type=true;
@@ -455,6 +463,8 @@ void java_bytecode_convert_classt::convert(
455463
{
456464
for(const methodt &method : overlay_class.get().methods)
457465
{
466+
if(is_ignored_method(method))
467+
continue;
458468
const irep_idt method_identifier =
459469
qualified_classname + "." + id2string(method.name)
460470
+ ":" + method.descriptor;
@@ -496,6 +506,8 @@ void java_bytecode_convert_classt::convert(
496506
}
497507
for(const methodt &method : c.methods)
498508
{
509+
if(is_ignored_method(method))
510+
continue;
499511
const irep_idt method_identifier=
500512
qualified_classname + "." + id2string(method.name)
501513
+ ":" + method.descriptor;
@@ -716,15 +728,15 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
716728
if(symbol_table.has_symbol(symbol_type_identifier))
717729
return;
718730

719-
class_typet class_type;
731+
java_class_typet class_type;
720732
// we have the base class, java.lang.Object, length and data
721733
// of appropriate type
722734
class_type.set_tag(symbol_type_identifier);
723735
// Note that non-array types don't have "java::" at the beginning of their
724736
// tag, and their name is "java::" + their tag. Since arrays do have
725737
// "java::" at the beginning of their tag we set the name to be the same as
726738
// the tag.
727-
class_type.set(ID_name, symbol_type_identifier);
739+
class_type.set_name(symbol_type_identifier);
728740

729741
class_type.components().reserve(3);
730742
class_typet::componentt base_class_component(
@@ -877,13 +889,6 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
877889
}
878890
}
879891

880-
bool java_bytecode_convert_classt::is_overlay_method(const methodt &method)
881-
{
882-
return java_bytecode_parse_treet::find_annotation(
883-
method.annotations, ID_overlay_method)
884-
.has_value();
885-
}
886-
887892
bool java_bytecode_convert_class(
888893
const java_class_loadert::parse_tree_with_overlayst &parse_trees,
889894
symbol_tablet &symbol_table,

cbmc/jbmc/src/java_bytecode/java_bytecode_language.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ const select_pointer_typet &
849849
void java_bytecode_languaget::methods_provided(
850850
std::unordered_set<irep_idt> &methods) const
851851
{
852-
static std::string cprover_class_prefix = "java::org.cprover.CProver.";
852+
const std::string cprover_class_prefix = "java::org.cprover.CProver.";
853853

854854
// Add all string solver methods to map
855855
string_preprocess.get_all_function_names(methods);

cbmc/jbmc/src/java_bytecode/java_bytecode_parse_tree.h

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class java_bytecode_parse_treet
8484
is_private(false), is_static(false), is_final(false)
8585
{
8686
}
87+
88+
bool has_annotation(const irep_idt &annotation_id) const
89+
{
90+
return find_annotation(annotations, annotation_id).has_value();
91+
}
8792
};
8893

8994
class methodt:public membert

cbmc/jbmc/src/java_bytecode/java_bytecode_parser.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ class base_ref_infot : public structured_pool_entryt
301301
public:
302302
explicit base_ref_infot(pool_entryt entry) : structured_pool_entryt(entry)
303303
{
304-
static std::set<u1> info_tags = {
305-
CONSTANT_Fieldref, CONSTANT_Methodref, CONSTANT_InterfaceMethodref};
306-
PRECONDITION(info_tags.find(entry.tag) != info_tags.end());
304+
PRECONDITION(
305+
entry.tag == CONSTANT_Fieldref || entry.tag == CONSTANT_Methodref ||
306+
entry.tag == CONSTANT_InterfaceMethodref);
307307
class_index = entry.ref1;
308308
name_and_type_index = entry.ref2;
309309
}

cbmc/jbmc/src/java_bytecode/java_class_loader.cpp

+34-36
Original file line numberDiff line numberDiff line change
@@ -168,50 +168,48 @@ java_class_loadert::get_parse_tree(
168168
}
169169
}
170170

171-
if(!parse_trees.empty())
171+
auto parse_tree_it = parse_trees.begin();
172+
// If the first class implementation is an overlay emit a warning and
173+
// skip over it until we find a non-overlay class
174+
while(parse_tree_it != parse_trees.end())
172175
{
173-
auto parse_tree_it = parse_trees.begin();
174-
// If the first class implementation is an overlay emit a warning and
175-
// skip over it until we find a non-overlay class
176-
while(parse_tree_it != parse_trees.end())
177-
{
178-
// Skip parse trees that failed to load - though these shouldn't exist yet
179-
if(parse_tree_it->loading_successful)
180-
{
181-
if(!is_overlay_class(parse_tree_it->parsed_class))
182-
{
183-
// Keep the non-overlay class
184-
++parse_tree_it;
185-
break;
186-
}
187-
warning()
188-
<< "Skipping class " << class_name
189-
<< " marked with OverlayClassImplementation but found before"
190-
" original definition"
191-
<< eom;
192-
}
193-
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
194-
++parse_tree_it;
195-
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
196-
}
197-
// Collect overlay classes
198-
while(parse_tree_it != parse_trees.end())
176+
// Skip parse trees that failed to load - though these shouldn't exist yet
177+
if(parse_tree_it->loading_successful)
199178
{
200-
// Remove non-initial classes that aren't overlays
201179
if(!is_overlay_class(parse_tree_it->parsed_class))
202180
{
203-
warning()
204-
<< "Skipping duplicate definition of class " << class_name
205-
<< " not marked with OverlayClassImplementation" << eom;
206-
auto duplicate_non_overlay_it = parse_tree_it;
181+
// Keep the non-overlay class
207182
++parse_tree_it;
208-
parse_trees.erase(duplicate_non_overlay_it);
183+
break;
209184
}
210-
else
211-
++parse_tree_it;
185+
warning()
186+
<< "Skipping class " << class_name
187+
<< " marked with OverlayClassImplementation but found before"
188+
" original definition"
189+
<< eom;
212190
}
213-
return parse_trees;
191+
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
192+
++parse_tree_it;
193+
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
214194
}
195+
// Collect overlay classes
196+
while(parse_tree_it != parse_trees.end())
197+
{
198+
// Remove non-initial classes that aren't overlays
199+
if(!is_overlay_class(parse_tree_it->parsed_class))
200+
{
201+
warning()
202+
<< "Skipping duplicate definition of class " << class_name
203+
<< " not marked with OverlayClassImplementation" << eom;
204+
auto duplicate_non_overlay_it = parse_tree_it;
205+
++parse_tree_it;
206+
parse_trees.erase(duplicate_non_overlay_it);
207+
}
208+
else
209+
++parse_tree_it;
210+
}
211+
if(!parse_trees.empty())
212+
return parse_trees;
215213

216214
// Not found or failed to load
217215
warning() << "failed to load class `" << class_name << '\'' << eom;

cbmc/jbmc/src/java_bytecode/java_string_library_preprocess.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void java_string_library_preprocesst::add_string_type(
210210
{
211211
java_class_typet string_type;
212212
string_type.set_tag(class_name);
213+
string_type.set_name("java::" + id2string(class_name));
213214
string_type.components().resize(3);
214215
string_type.components()[0].set_name("@java.lang.Object");
215216
string_type.components()[0].set_pretty_name("@java.lang.Object");

cbmc/jbmc/src/java_bytecode/java_types.h

+14
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ class java_class_typet:public class_typet
158158
return type_checked_cast<annotated_typet>(
159159
static_cast<typet &>(*this)).get_annotations();
160160
}
161+
162+
/// Get the name of the struct, which can be used to look up its symbol
163+
/// in the symbol table.
164+
const irep_idt &get_name() const
165+
{
166+
return get(ID_name);
167+
}
168+
169+
/// Set the name of the struct, which can be used to look up its symbol
170+
/// in the symbol table.
171+
void set_name(const irep_idt &name)
172+
{
173+
set(ID_name, name);
174+
}
161175
};
162176

163177
inline const java_class_typet &to_java_class_type(const typet &type)

cbmc/jbmc/src/java_bytecode/java_utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void generate_class_stub(
6767
message_handlert &message_handler,
6868
const struct_union_typet::componentst &componentst)
6969
{
70-
class_typet class_type;
70+
java_class_typet class_type;
7171

7272
class_type.set_tag(class_name);
7373
class_type.set(ID_base_name, class_name);
@@ -79,7 +79,7 @@ void generate_class_stub(
7979
new_symbol.base_name=class_name;
8080
new_symbol.pretty_name=class_name;
8181
new_symbol.name="java::"+id2string(class_name);
82-
class_type.set(ID_name, new_symbol.name);
82+
class_type.set_name(new_symbol.name);
8383
new_symbol.type=class_type;
8484
new_symbol.mode=ID_java;
8585
new_symbol.is_type=true;

cbmc/jbmc/src/java_bytecode/load_method_by_regex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool does_pattern_miss_descriptor(const std::string &pattern)
4141
if(descriptor_index == std::string::npos)
4242
return true;
4343

44-
static const std::string java_prefix = "java::";
44+
const std::string java_prefix = "java::";
4545
return descriptor_index == java_prefix.length() - 1 &&
4646
has_prefix(pattern, java_prefix);
4747
}

cbmc/regression/cbmc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ show:
1515

1616
clean:
1717
find -name '*.out' -execdir $(RM) '{}' \;
18-
find -name '*.gb' -execdir $(RM) '{}' \;
18+
find -name '*.smt2' -execdir $(RM) '{}' \;
1919
$(RM) tests.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
typedef enum
2+
{
3+
VALUE_1,
4+
VALUE_2,
5+
VALUE_3,
6+
VALUE_4
7+
} values;
8+
9+
int main()
10+
{
11+
unsigned x;
12+
switch(x)
13+
{
14+
case VALUE_1:
15+
__CPROVER_assert(0, "0 works");
16+
break;
17+
#ifdef __GNUC__
18+
case VALUE_2 ... 3:
19+
#else
20+
case VALUE_2:
21+
case VALUE_3:
22+
case VALUE_4:
23+
#endif
24+
__CPROVER_assert(0, "... works");
25+
break;
26+
default:
27+
__CPROVER_assert(0, "default works");
28+
break;
29+
}
30+
31+
return 0;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\*\* 3 of 3 failed
8+
--
9+
^warning: ignoring

cbmc/regression/goto-gcc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ show:
1818
clean:
1919
find -name '*.out' -execdir $(RM) '{}' \;
2020
find -name '*.gb' -execdir $(RM) '{}' \;
21+
find -name '*.goto-cc-saved' -execdir $(RM) '{}' \;
2122
$(RM) tests.log

cbmc/regression/invariants/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ show:
2525

2626
driver$(EXEEXT): $(OBJ)
2727
$(LINKBIN)
28+
29+
clean:
30+
find -name '*.out' -execdir $(RM) '{}' \;
31+
$(RM) driver$(EXEEXT) driver$(DEPEXT) driver$(OBJEXT)
32+
$(RM) tests.log

cbmc/regression/test.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ ($)
421421
close LOG;
422422

423423
if($opt_p && $failures != 0) {
424-
open LOG,"<tests.log" or die "Failed to open tests.log\n";
424+
open LOG,"<$logfile_name" or die "Failed to open $logfile_name\n";
425425

426426
my $printed_this_test = 1;
427427
my $current_test = "";

cbmc/src/ansi-c/c_typecheck_code.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ void c_typecheck_baset::typecheck_switch_case(code_switch_caset &code)
535535
exprt &case_expr=code.case_op();
536536
typecheck_expr(case_expr);
537537
implicit_typecast(case_expr, switch_op_type);
538+
make_constant(case_expr);
538539
}
539540
}
540541

@@ -561,6 +562,8 @@ void c_typecheck_baset::typecheck_gcc_switch_case_range(codet &code)
561562
typecheck_expr(code.op1());
562563
implicit_typecast(code.op0(), switch_op_type);
563564
implicit_typecast(code.op1(), switch_op_type);
565+
make_constant(code.op0());
566+
make_constant(code.op1());
564567
}
565568

566569
void c_typecheck_baset::typecheck_gcc_local_label(codet &code)

0 commit comments

Comments
 (0)