Skip to content

Commit ff85b54

Browse files
committed
Build with numeric conversion warnings enabled
1 parent 2f3ed10 commit ff85b54

18 files changed

+32
-33
lines changed

Diff for: CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7777
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
7878
# Enable lots of warnings
7979
set(CMAKE_CXX_FLAGS
80-
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum \
80+
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum -Wconversion \
8181
-Wno-deprecated-declarations -Wno-maybe-uninitialized")
8282
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
8383
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
@@ -86,7 +86,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
8686
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
8787
# Enable lots of warnings
8888
set(CMAKE_CXX_FLAGS
89-
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum -Wno-deprecated-declarations")
89+
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum -Wconversion -Wno-deprecated-declarations")
9090
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
9191
# This would be the place to enable warnings for Windows builds, although
9292
# config.inc doesn't seem to do that currently

Diff for: src/goto-checker/symex_bmc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool symex_bmct::should_stop_unwind(
163163

164164
bool symex_bmct::get_unwind_recursion(
165165
const irep_idt &id,
166-
unsigned thread_nr,
166+
std::size_t thread_nr,
167167
std::size_t unwind)
168168
{
169169
tvt abort_unwind_decision;

Diff for: src/goto-checker/symex_bmc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class symex_bmct : public goto_symext
110110

111111
bool get_unwind_recursion(
112112
const irep_idt &identifier,
113-
unsigned thread_nr,
113+
std::size_t thread_nr,
114114
std::size_t unwind) override;
115115

116116
symex_coveraget symex_coverage;

Diff for: src/goto-instrument/unwindset.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ void unwindsett::parse_unwindset_one_loop(
3333
if(val.empty())
3434
return;
3535

36-
std::optional<unsigned> thread_nr;
36+
std::optional<std::size_t> thread_nr;
3737
if(isdigit(val[0]))
3838
{
3939
auto c_pos = val.find(':');
4040
if(c_pos != std::string::npos)
4141
{
4242
std::string nr = val.substr(0, c_pos);
43-
thread_nr = unsafe_string2unsigned(nr);
43+
thread_nr = unsafe_string2size_t(nr);
4444
val.erase(0, nr.size() + 1);
4545
}
4646
}
@@ -170,7 +170,7 @@ void unwindsett::parse_unwindset_one_loop(
170170

171171
if(thread_nr.has_value())
172172
{
173-
thread_loop_map[std::pair<irep_idt, unsigned>(id, *thread_nr)] = uw;
173+
thread_loop_map[std::pair<irep_idt, std::size_t>(id, *thread_nr)] = uw;
174174
}
175175
else
176176
{
@@ -188,13 +188,13 @@ void unwindsett::parse_unwindset(
188188
}
189189

190190
std::optional<unsigned>
191-
unwindsett::get_limit(const irep_idt &loop_id, unsigned thread_nr) const
191+
unwindsett::get_limit(const irep_idt &loop_id, std::size_t thread_nr) const
192192
{
193193
// We use the most specific limit we have
194194

195195
// thread x loop
196196
auto tl_it =
197-
thread_loop_map.find(std::pair<irep_idt, unsigned>(loop_id, thread_nr));
197+
thread_loop_map.find(std::pair<irep_idt, std::size_t>(loop_id, thread_nr));
198198

199199
if(tl_it != thread_loop_map.end())
200200
return tl_it->second;

Diff for: src/goto-instrument/unwindset.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class unwindsett
4444

4545
// queries
4646
std::optional<unsigned>
47-
get_limit(const irep_idt &loop, unsigned thread_id) const;
47+
get_limit(const irep_idt &loop, std::size_t thread_id) const;
4848

4949
// read unwindset directives from a file
5050
void parse_unwindset_file(
@@ -63,7 +63,7 @@ class unwindsett
6363

6464
// separate limits per thread
6565
using thread_loop_mapt =
66-
std::map<std::pair<irep_idt, unsigned>, std::optional<unsigned>>;
66+
std::map<std::pair<irep_idt, std::size_t>, std::optional<unsigned>>;
6767
thread_loop_mapt thread_loop_map;
6868

6969
void parse_unwindset_one_loop(

Diff for: src/goto-programs/goto_trace.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class goto_trace_stept
112112
goto_programt::const_targett pc;
113113

114114
// this transition done by given thread number
115-
unsigned thread_nr;
115+
std::size_t thread_nr;
116116

117117
// for assume, assert, goto
118118
bool cond_value;

Diff for: src/goto-symex/complexity_limiter.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Author: John Dumbell
1212

1313
#include "goto_symex_state.h"
1414

15-
#include <cmath>
16-
1715
complexity_limitert::complexity_limitert(
1816
message_handlert &message_handler,
1917
const optionst &options)
@@ -28,7 +26,7 @@ complexity_limitert::complexity_limitert(
2826

2927
const std::size_t failed_child_loops_limit = options.get_signed_int_option(
3028
"symex-complexity-failed-child-loops-limit");
31-
const std::size_t unwind = options.get_signed_int_option("unwind");
29+
const int unwind = options.get_signed_int_option("unwind");
3230

3331
// If we have complexity enabled, try to work out a failed_children_limit.
3432
// In order of priority:
@@ -38,7 +36,7 @@ complexity_limitert::complexity_limitert(
3836
if(failed_child_loops_limit > 0)
3937
max_loops_complexity = failed_child_loops_limit;
4038
else if(unwind > 0)
41-
max_loops_complexity = std::max(static_cast<int>(floor(unwind / 3)), 1);
39+
max_loops_complexity = std::max(unwind / 3, 1);
4240
else
4341
max_loops_complexity = limit;
4442
}

Diff for: src/goto-symex/goto_symex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class goto_symext
505505

506506
virtual bool get_unwind_recursion(
507507
const irep_idt &identifier,
508-
unsigned thread_nr,
508+
std::size_t thread_nr,
509509
std::size_t unwind);
510510

511511
/// Iterates over \p arguments and assigns them to the parameters, which are

Diff for: src/goto-symex/goto_symex_state.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class goto_symex_statet final : public goto_statet
176176
void print_backtrace(std::ostream &) const;
177177

178178
// threads
179-
typedef std::pair<unsigned, std::list<guardt> > a_s_r_entryt;
179+
typedef std::pair<std::size_t, std::list<guardt> > a_s_r_entryt;
180180
typedef std::list<guardt> a_s_w_entryt;
181181
std::unordered_map<ssa_exprt, a_s_r_entryt, irep_hash> read_in_atomic_section;
182182
std::unordered_map<ssa_exprt, a_s_w_entryt, irep_hash>

Diff for: src/goto-symex/memory_model.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class memory_model_baset : public partial_order_concurrencyt
5757
symex_target_equationt &equation);
5858

5959
// maps thread numbers to an event list
60-
typedef std::map<unsigned, event_listt> per_thread_mapt;
60+
typedef std::map<std::size_t, event_listt> per_thread_mapt;
6161
};
6262

6363
#endif // CPROVER_GOTO_SYMEX_MEMORY_MODEL_H

Diff for: src/goto-symex/partial_order_concurrency.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void partial_order_concurrencyt::build_event_lists(
7878
add_init_writes(equation);
7979

8080
// a per-thread counter
81-
std::map<unsigned, unsigned> counter;
81+
std::map<std::size_t, unsigned> counter;
8282

8383
for(eventst::const_iterator
8484
e_it=equation.SSA_steps.begin();
@@ -89,7 +89,7 @@ void partial_order_concurrencyt::build_event_lists(
8989
e_it->is_shared_write() ||
9090
e_it->is_spawn())
9191
{
92-
unsigned thread_nr=e_it->source.thread_nr;
92+
std::size_t thread_nr=e_it->source.thread_nr;
9393

9494
if(!e_it->is_spawn())
9595
{

Diff for: src/goto-symex/renaming_level.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void symex_level1t::restore_from(const symex_level1t &other)
128128
}
129129
}
130130

131-
unsigned symex_level2t::latest_index(const irep_idt &identifier) const
131+
std::size_t symex_level2t::latest_index(const irep_idt &identifier) const
132132
{
133133
const auto r_opt = current_names.find(identifier);
134134
return !r_opt ? 0 : r_opt->get().second;

Diff for: src/goto-symex/renaming_level.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct symex_level2t
7474
renamedt<ssa_exprt, L2> operator()(renamedt<ssa_exprt, L1> l1_expr) const;
7575

7676
/// Counter corresponding to an identifier
77-
unsigned latest_index(const irep_idt &identifier) const;
77+
std::size_t latest_index(const irep_idt &identifier) const;
7878

7979
/// Allocates a fresh L2 name for the given L1 identifier, and makes it the
8080
/// latest generation on this path.

Diff for: src/goto-symex/symex_function_call.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Author: Daniel Kroening, [email protected]
2424
#include "path_storage.h"
2525
#include "symex_assign.h"
2626

27-
bool goto_symext::get_unwind_recursion(const irep_idt &, unsigned, std::size_t)
27+
bool goto_symext::get_unwind_recursion(const irep_idt &, std::size_t, std::size_t)
2828
{
2929
return false;
3030
}

Diff for: src/goto-symex/symex_goto.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ static void merge_names(
742742
symex_target_equationt &target,
743743
const incremental_dirtyt &dirty,
744744
const ssa_exprt &ssa,
745-
const unsigned goto_count,
746-
const unsigned dest_count)
745+
const std::size_t goto_count,
746+
const std::size_t dest_count)
747747
{
748748
const irep_idt l1_identifier = ssa.get_identifier();
749749
const irep_idt &obj_identifier = ssa.get_object_name();
@@ -876,8 +876,8 @@ void goto_symext::phi_function(
876876
for(const auto &delta_item : delta_view)
877877
{
878878
const ssa_exprt &ssa = delta_item.m.first;
879-
unsigned goto_count = delta_item.m.second;
880-
unsigned dest_count = !delta_item.is_in_both_maps()
879+
std::size_t goto_count = delta_item.m.second;
880+
std::size_t dest_count = !delta_item.is_in_both_maps()
881881
? 0
882882
: delta_item.get_other_map_value().second;
883883

@@ -905,8 +905,8 @@ void goto_symext::phi_function(
905905
continue;
906906

907907
const ssa_exprt &ssa = delta_item.m.first;
908-
unsigned goto_count = 0;
909-
unsigned dest_count = delta_item.m.second;
908+
std::size_t goto_count = 0;
909+
std::size_t dest_count = delta_item.m.second;
910910

911911
merge_names(
912912
goto_state,

Diff for: src/goto-symex/symex_main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void goto_symext::rewrite_quantifiers(exprt &expr, statet &state)
276276
}
277277

278278
static void
279-
switch_to_thread(goto_symex_statet &state, const unsigned int thread_nb)
279+
switch_to_thread(goto_symex_statet &state, const std::size_t thread_nb)
280280
{
281281
PRECONDITION(state.source.thread_nr < state.threads.size());
282282
PRECONDITION(thread_nb < state.threads.size());
@@ -311,7 +311,7 @@ void goto_symext::symex_threaded_step(
311311
if(state.call_stack().empty() &&
312312
state.source.thread_nr+1<state.threads.size())
313313
{
314-
unsigned t=state.source.thread_nr+1;
314+
std::size_t t=state.source.thread_nr+1;
315315
#if 0
316316
std::cout << "********* Now executing thread " << t << '\n';
317317
#endif

Diff for: src/goto-symex/symex_target.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class symex_targett
3535
/// first instruction of the input GOTO program.
3636
struct sourcet
3737
{
38-
unsigned thread_nr;
38+
std::size_t thread_nr;
3939
irep_idt function_id;
4040
// The program counter is an iterator which indicates where the execution
4141
// is in its program sequence

Diff for: src/solvers/floatbv/float_bv.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ void float_bvt::normalization_shift(
956956
PRECONDITION(fraction_bits != 0);
957957

958958
std::size_t depth = address_bits(fraction_bits - 1);
959+
CHECK_RETURN(depth > 0);
959960

960961
exponent = typecast_exprt(
961962
exponent, signedbv_typet(std::max(depth, exponent_bits + 1)));

0 commit comments

Comments
 (0)