Skip to content

Commit d932d6f

Browse files
authored
Merge pull request diffblue#7235 from tautschnig/cleanup/iwyu-2
Remove unnecessary includes
2 parents d4b5f48 + a8514e0 commit d932d6f

File tree

527 files changed

+1862
-1774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

527 files changed

+1862
-1774
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,33 @@ jobs:
785785
- name: Smoke test goto-analyzer
786786
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-analyzer /mnt/smoke/test.goto --unreachable-functions
787787

788+
include-what-you-use:
789+
runs-on: ubuntu-22.04
790+
steps:
791+
- uses: actions/checkout@v3
792+
with:
793+
submodules: recursive
794+
- name: Fetch dependencies
795+
env:
796+
# This is needed in addition to -yq to prevent apt-get from asking for
797+
# user input
798+
DEBIAN_FRONTEND: noninteractive
799+
run: |
800+
sudo apt-get update
801+
sudo apt-get install --no-install-recommends -yq cmake ninja-build gcc gdb g++ maven flex bison iwyu
802+
- name: Configure using CMake
803+
run: |
804+
mkdir build
805+
cd build
806+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
807+
- name: Run include-what-you-use
808+
run: |
809+
iwyu_tool -p build/compile_commands.json -j2 | tee includes.txt
810+
if sed '/minisat2-src/,/^--$/d' includes.txt | grep '^- ' -B1 ; then
811+
echo "Unnecessary includes found. Use '// IWYU pragma: keep' to override this."
812+
exit 1
813+
fi
814+
788815
codecov-coverage-report:
789816
runs-on: ubuntu-20.04
790817
steps:

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Author: Daniel Kroening, [email protected]
4343
#include <linking/static_lifetime_init.h>
4444

4545
#include <cstdlib> // exit()
46-
#include <fstream>
46+
#include <fstream> // IWYU pragma: keep
4747
#include <iostream>
4848
#include <memory>
4949

jbmc/src/java_bytecode/character_refine_preprocess.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Date: March 2017
1919
#include <util/bitvector_expr.h>
2020
#include <util/std_expr.h>
2121

22+
#include <goto-programs/goto_instruction_code.h>
23+
2224
/// converts based on a function on expressions
2325
/// \param expr_function: A reference to a function on expressions
2426
/// \param target: A position in a goto program

jbmc/src/java_bytecode/character_refine_preprocess.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Date: March 2017
2020
#ifndef CPROVER_JAVA_BYTECODE_CHARACTER_REFINE_PREPROCESS_H
2121
#define CPROVER_JAVA_BYTECODE_CHARACTER_REFINE_PREPROCESS_H
2222

23-
#include <goto-programs/goto_instruction_code.h>
24-
2523
#include <util/mp_arith.h>
26-
#include <util/std_code.h>
24+
#include <util/std_code_base.h>
2725

2826
#include <unordered_map>
2927

28+
class code_function_callt;
29+
3030
class character_refine_preprocesst
3131
{
3232
public:

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ Author: Diffblue Ltd.
77
\*******************************************************************/
88

99
#include "ci_lazy_methods.h"
10-
#include "java_bytecode_language.h"
11-
#include "java_class_loader.h"
12-
#include "java_entry_point.h"
13-
#include "remove_exceptions.h"
1410

1511
#include <util/expr_iterator.h>
1612
#include <util/namespace.h>
1713
#include <util/suffix.h>
14+
#include <util/symbol_table.h>
1815

1916
#include <goto-programs/resolve_inherited_component.h>
2017

18+
#include "java_bytecode_language.h"
19+
#include "java_class_loader.h"
20+
#include "java_entry_point.h"
21+
#include "remove_exceptions.h"
22+
2123
/// Constructor for lazy-method loading
2224
/// \param symbol_table: the symbol table to use
2325
/// \param main_class: identifier of the entry point / main class
@@ -34,7 +36,7 @@ Author: Diffblue Ltd.
3436
/// these method bodies are produced internally, rather than generated from
3537
/// Java bytecode.
3638
ci_lazy_methodst::ci_lazy_methodst(
37-
const symbol_tablet &symbol_table,
39+
const symbol_table_baset &symbol_table,
3840
const irep_idt &main_class,
3941
const std::vector<irep_idt> &main_jar_classes,
4042
const std::vector<load_extra_methodst> &lazy_methods_extra_entry_points,
@@ -96,7 +98,7 @@ static bool references_class_model(const exprt &expr)
9698
/// \param message_handler: the message handler to use for output
9799
/// \return Returns false on success
98100
bool ci_lazy_methodst::operator()(
99-
symbol_tablet &symbol_table,
101+
symbol_table_baset &symbol_table,
100102
method_bytecodet &method_bytecode,
101103
const method_convertert &method_converter,
102104
message_handlert &message_handler)
@@ -221,7 +223,16 @@ bool ci_lazy_methodst::operator()(
221223
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
222224
<< " unreachable methods and globals" << messaget::eom;
223225

224-
symbol_table.swap(keep_symbols);
226+
auto sorted_to_keep = keep_symbols.sorted_symbol_names();
227+
auto all_sorted = symbol_table.sorted_symbol_names();
228+
auto it = sorted_to_keep.cbegin();
229+
for(const auto &id : all_sorted)
230+
{
231+
if(it == sorted_to_keep.cend() || id != *it)
232+
symbol_table.remove(id);
233+
else
234+
++it;
235+
}
225236

226237
return false;
227238
}
@@ -238,7 +249,7 @@ bool ci_lazy_methodst::handle_virtual_methods_with_no_callees(
238249
std::unordered_set<irep_idt> &instantiated_classes,
239250
const std::unordered_set<class_method_descriptor_exprt, irep_hash>
240251
&virtual_functions,
241-
symbol_tablet &symbol_table)
252+
symbol_table_baset &symbol_table)
242253
{
243254
ci_lazy_methods_neededt lazy_methods_loader(
244255
methods_to_convert_later,
@@ -321,7 +332,7 @@ ci_lazy_methodst::convert_and_analyze_method(
321332
std::unordered_set<irep_idt> &methods_already_populated,
322333
const bool class_initializer_already_seen,
323334
const irep_idt &method_name,
324-
symbol_tablet &symbol_table,
335+
symbol_table_baset &symbol_table,
325336
std::unordered_set<irep_idt> &methods_to_convert_later,
326337
std::unordered_set<irep_idt> &instantiated_classes,
327338
std::unordered_set<class_method_descriptor_exprt, irep_hash>
@@ -367,7 +378,7 @@ ci_lazy_methodst::convert_and_analyze_method(
367378
/// * all the methods of the main jar file
368379
/// \return set of identifiers of entry point methods
369380
std::unordered_set<irep_idt> ci_lazy_methodst::entry_point_methods(
370-
const symbol_tablet &symbol_table,
381+
const symbol_table_baset &symbol_table,
371382
message_handlert &message_handler)
372383
{
373384
std::unordered_set<irep_idt> methods_to_convert_later;
@@ -481,7 +492,7 @@ void ci_lazy_methodst::get_virtual_method_targets(
481492
const class_method_descriptor_exprt &called_function,
482493
const std::unordered_set<irep_idt> &instantiated_classes,
483494
std::unordered_set<irep_idt> &callable_methods,
484-
symbol_tablet &symbol_table)
495+
symbol_table_baset &symbol_table)
485496
{
486497
const auto &call_class = called_function.class_id();
487498
const auto &method_name = called_function.mangled_method_name();
@@ -506,8 +517,8 @@ void ci_lazy_methodst::get_virtual_method_targets(
506517
/// `e` or its children.
507518
void ci_lazy_methodst::gather_needed_globals(
508519
const exprt &e,
509-
const symbol_tablet &symbol_table,
510-
symbol_tablet &needed)
520+
const symbol_table_baset &symbol_table,
521+
symbol_table_baset &needed)
511522
{
512523
if(e.id()==ID_symbol)
513524
{
@@ -546,7 +557,7 @@ irep_idt ci_lazy_methodst::get_virtual_method_target(
546557
const std::unordered_set<irep_idt> &instantiated_classes,
547558
const irep_idt &call_basename,
548559
const irep_idt &classname,
549-
const symbol_tablet &symbol_table)
560+
const symbol_table_baset &symbol_table)
550561
{
551562
// Program-wide, is this class ever instantiated?
552563
if(!instantiated_classes.count(classname))

jbmc/src/java_bytecode/ci_lazy_methods.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ci_lazy_methods_neededt;
2727
class java_class_loadert;
2828
class message_handlert;
2929
class select_pointer_typet;
30+
class symbol_table_baset;
3031

3132
// Map from method id to class_method_and_bytecodet
3233
class method_bytecodet
@@ -90,14 +91,14 @@ typedef std::function<
9091
bool(const irep_idt &function_id, ci_lazy_methods_neededt)>
9192
method_convertert;
9293

93-
typedef std::function<std::vector<irep_idt>(const symbol_tablet &)>
94+
typedef std::function<std::vector<irep_idt>(const symbol_table_baset &)>
9495
load_extra_methodst;
9596

9697
class ci_lazy_methodst
9798
{
9899
public:
99100
ci_lazy_methodst(
100-
const symbol_tablet &symbol_table,
101+
const symbol_table_baset &symbol_table,
101102
const irep_idt &main_class,
102103
const std::vector<irep_idt> &main_jar_classes,
103104
const std::vector<load_extra_methodst> &lazy_methods_extra_entry_points,
@@ -108,7 +109,7 @@ class ci_lazy_methodst
108109

109110
// not const since messaget
110111
bool operator()(
111-
symbol_tablet &symbol_table,
112+
symbol_table_baset &symbol_table,
112113
method_bytecodet &method_bytecode,
113114
const method_convertert &method_converter,
114115
message_handlert &message_handler);
@@ -127,18 +128,18 @@ class ci_lazy_methodst
127128
const class_method_descriptor_exprt &called_function,
128129
const std::unordered_set<irep_idt> &instantiated_classes,
129130
std::unordered_set<irep_idt> &callable_methods,
130-
symbol_tablet &symbol_table);
131+
symbol_table_baset &symbol_table);
131132

132133
void gather_needed_globals(
133134
const exprt &e,
134-
const symbol_tablet &symbol_table,
135-
symbol_tablet &needed);
135+
const symbol_table_baset &symbol_table,
136+
symbol_table_baset &needed);
136137

137138
irep_idt get_virtual_method_target(
138139
const std::unordered_set<irep_idt> &instantiated_classes,
139140
const irep_idt &call_basename,
140141
const irep_idt &classname,
141-
const symbol_tablet &symbol_table);
142+
const symbol_table_baset &symbol_table);
142143

143144
static irep_idt build_virtual_method_name(
144145
const irep_idt &class_name,
@@ -154,7 +155,7 @@ class ci_lazy_methodst
154155
const synthetic_methods_mapt &synthetic_methods;
155156

156157
std::unordered_set<irep_idt> entry_point_methods(
157-
const symbol_tablet &symbol_table,
158+
const symbol_table_baset &symbol_table,
158159
message_handlert &message_handler);
159160

160161
struct convert_method_resultt
@@ -168,7 +169,7 @@ class ci_lazy_methodst
168169
std::unordered_set<irep_idt> &methods_already_populated,
169170
const bool class_initializer_already_seen,
170171
const irep_idt &method_name,
171-
symbol_tablet &symbol_table,
172+
symbol_table_baset &symbol_table,
172173
std::unordered_set<irep_idt> &methods_to_convert_later,
173174
std::unordered_set<irep_idt> &instantiated_classes,
174175
std::unordered_set<class_method_descriptor_exprt, irep_hash>
@@ -180,7 +181,7 @@ class ci_lazy_methodst
180181
std::unordered_set<irep_idt> &instantiated_classes,
181182
const std::unordered_set<class_method_descriptor_exprt, irep_hash>
182183
&virtual_functions,
183-
symbol_tablet &symbol_table);
184+
symbol_table_baset &symbol_table);
184185
};
185186

186187
#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Author: Chris Smowton, [email protected]
1111

1212
#include "ci_lazy_methods_needed.h"
1313

14-
#include <goto-programs/resolve_inherited_component.h>
15-
1614
#include <util/namespace.h>
1715
#include <util/std_types.h>
18-
#include <util/symbol_table.h>
16+
#include <util/symbol_table_base.h>
17+
18+
#include <goto-programs/resolve_inherited_component.h>
1919

20-
#include "generic_parameter_specialization_map.h"
20+
#include "generic_parameter_specialization_map.h" // IWYU pragma: keep
2121
#include "java_static_initializers.h"
2222
#include "java_types.h"
2323
#include "select_pointer_type.h"

jbmc/src/java_bytecode/ci_lazy_methods_needed.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Author: Chris Smowton, [email protected]
1919
class namespacet;
2020
class pointer_typet;
2121
class select_pointer_typet;
22-
class symbol_tablet;
22+
class symbol_table_baset;
2323
class typet;
2424

2525
class ci_lazy_methods_neededt
@@ -28,7 +28,7 @@ class ci_lazy_methods_neededt
2828
ci_lazy_methods_neededt(
2929
std::unordered_set<irep_idt> &_callable_methods,
3030
std::unordered_set<irep_idt> &_instantiated_classes,
31-
const symbol_tablet &_symbol_table,
31+
const symbol_table_baset &_symbol_table,
3232
const select_pointer_typet &pointer_type_selector)
3333
: callable_methods(_callable_methods),
3434
instantiated_classes(_instantiated_classes),
@@ -53,7 +53,7 @@ class ci_lazy_methods_neededt
5353
// found so far, so we can use a membership test to avoid
5454
// repeatedly exploring a class hierarchy.
5555
std::unordered_set<irep_idt> &instantiated_classes;
56-
const symbol_tablet &symbol_table;
56+
const symbol_table_baset &symbol_table;
5757

5858
const select_pointer_typet &pointer_type_selector;
5959

jbmc/src/java_bytecode/code_with_references.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Author: Romain Brenguier, [email protected]
99
#include "code_with_references.h"
1010
#include "java_types.h"
1111

12-
#include <goto-programs/goto_instruction_code.h>
13-
1412
#include <util/arith_tools.h>
1513

1614
codet allocate_array(

jbmc/src/java_bytecode/create_array_with_type_intrinsic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Author: Diffblue Ltd.
1212
#ifndef CPROVER_JAVA_BYTECODE_CREATE_ARRAY_WITH_TYPE_INTRINSIC_H
1313
#define CPROVER_JAVA_BYTECODE_CREATE_ARRAY_WITH_TYPE_INTRINSIC_H
1414

15-
#include <util/std_code.h>
15+
#include <util/std_code_base.h>
1616

1717
class message_handlert;
1818
class symbol_table_baset;

jbmc/src/java_bytecode/java_bmc_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Module: Bounded Model Checking Utils for Java
44
55
Author: Daniel Kroening, Peter Schrammel
66
7-
\*******************************************************************/
7+
\*******************************************************************/
88

99
/// \file
1010
/// Bounded Model Checking Utils for Java

jbmc/src/java_bytecode/java_bmc_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Module: Bounded Model Checking Utils for Java
44
55
Author: Daniel Kroening, Peter Schrammel
66
7-
\*******************************************************************/
7+
\*******************************************************************/
88

99
/// \file
1010
/// Bounded Model Checking Utils for Java

0 commit comments

Comments
 (0)