Skip to content

Commit 5a04db9

Browse files
author
Daniel Kroening
committed
replace assert(false) by UNREACHABLE
1 parent 90b1ed6 commit 5a04db9

File tree

90 files changed

+214
-202
lines changed

Some content is hidden

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

90 files changed

+214
-202
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void constant_propagator_domaint::assign_rec(
7979
cond = simplify_expr(cond,ns);
8080
}
8181
else
82-
assert(0);
82+
UNREACHABLE;
8383

8484
assign(values, to_symbol_expr(lhs), cond, ns);
8585
}

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void custom_bitvector_domaint::transform(
296296
else if(identifier=="__CPROVER_clear_may")
297297
mode=modet::CLEAR_MAY;
298298
else
299-
assert(false);
299+
UNREACHABLE;
300300

301301
exprt lhs=code_function_call.arguments()[0];
302302

@@ -411,7 +411,7 @@ void custom_bitvector_domaint::transform(
411411
else if(statement=="clear_may")
412412
mode=modet::CLEAR_MAY;
413413
else
414-
assert(false);
414+
UNREACHABLE;
415415

416416
exprt lhs=instruction.code.op0();
417417

src/analyses/goto_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ void goto_checkt::nan_check(
833833
equal_exprt(expr.op1(), minus_inf)));
834834
}
835835
else
836-
assert(false);
836+
UNREACHABLE;
837837

838838
isnan.make_not();
839839

src/analyses/goto_rw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void goto_rw(goto_programt::const_targett target,
713713
switch(target->type)
714714
{
715715
case NO_INSTRUCTION_TYPE:
716-
assert(false);
716+
UNREACHABLE;
717717
break;
718718

719719
case GOTO:

src/analyses/invariant_set.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void invariant_sett::strengthen_rec(const exprt &expr)
474474
}
475475
}
476476
else
477-
assert(false);
477+
UNREACHABLE;
478478
}
479479
else if(expr.id()==ID_equal)
480480
{
@@ -673,7 +673,7 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
673673
else if(expr.id()==ID_notequal)
674674
return is_ne(p);
675675
else
676-
assert(false);
676+
UNREACHABLE;
677677
}
678678

679679
return tvt::unknown();

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void ansi_c_convert_typet::write(typet &type)
460460
else
461461
type=unsigned_long_long_int_type();
462462
else
463-
assert(false);
463+
UNREACHABLE;
464464
}
465465
else if(gcc_int128_cnt)
466466
{

src/ansi-c/ansi_c_declaration.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <util/config.h>
1818
#include <util/std_types.h>
19+
#include <util/invariant.h>
1920

2021
void ansi_c_declaratort::build(irept &src)
2122
{
@@ -36,7 +37,7 @@ void ansi_c_declaratort::build(irept &src)
3637
else if(t.id().empty() ||
3738
t.is_nil())
3839
{
39-
assert(0);
40+
UNREACHABLE;
4041
}
4142
else if(t.id()==ID_abstract)
4243
{
@@ -108,7 +109,7 @@ typet ansi_c_declarationt::full_type(
108109
p=&(p->subtypes().back());
109110
}
110111
else
111-
assert(false);
112+
UNREACHABLE;
112113
}
113114

114115
*p=type();

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ bool ansi_c_entry_point(
305305
max=to_unsignedbv_type(envp_size_symbol.type).largest();
306306
}
307307
else
308-
assert(false);
308+
UNREACHABLE;
309309

310310
exprt max_minus_one=from_integer(max-1, envp_size_symbol.type);
311311

@@ -431,7 +431,7 @@ bool ansi_c_entry_point(
431431
}
432432
}
433433
else
434-
assert(false);
434+
UNREACHABLE;
435435
}
436436
else
437437
{

src/ansi-c/c_preprocess.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static std::string type_max(const typet &src)
106106
return integer2string(
107107
power(2, to_unsignedbv_type(src).get_width()-1)-1);
108108
else
109-
assert(false);
109+
UNREACHABLE;
110110
}
111111

112112
/// quote a string for bash and CMD
@@ -766,7 +766,7 @@ bool c_preprocess_gcc_clang(
766766
else if(config.ansi_c.wchar_t_width==config.ansi_c.char_width)
767767
command+=" -D__WCHAR_TYPE__=\""+sig+" char\"";
768768
else
769-
assert(false);
769+
UNREACHABLE;
770770
}
771771

772772
if(config.ansi_c.char_is_unsigned)
@@ -804,7 +804,7 @@ bool c_preprocess_gcc_clang(
804804
break;
805805

806806
default:
807-
assert(false);
807+
UNREACHABLE;
808808
}
809809

810810
// Standard Defines, ANSI9899 6.10.8

src/ansi-c/c_typecast.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ void c_typecastt::implicit_typecast_arithmetic(
378378
}
379379
return;
380380

381-
case BOOL: assert(false); // should always be promoted to int
382-
case CHAR: assert(false); // should always be promoted to int
383-
case UCHAR: assert(false); // should always be promoted to int
384-
case SHORT: assert(false); // should always be promoted to int
385-
case USHORT: assert(false); // should always be promoted to int
381+
case BOOL: UNREACHABLE; // should always be promoted to int
382+
case CHAR: UNREACHABLE; // should always be promoted to int
383+
case UCHAR: UNREACHABLE; // should always be promoted to int
384+
case SHORT: UNREACHABLE; // should always be promoted to int
385+
case USHORT: UNREACHABLE; // should always be promoted to int
386386
case INT: new_type=signed_int_type(); break;
387387
case UINT: new_type=unsigned_int_type(); break;
388388
case LONG: new_type=signed_long_int_type(); break;

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void c_typecheck_baset::add_rounding_mode(exprt &expr)
7777
else if(expr.id()==ID_minus)
7878
expr.id(ID_floatbv_minus);
7979
else
80-
assert(false);
80+
UNREACHABLE;
8181

8282
expr.op2()=from_integer(0, unsigned_int_type());
8383
}
@@ -875,7 +875,7 @@ void c_typecheck_baset::typecheck_side_effect_statement_expression(
875875
else if(last_statement==ID_function_call)
876876
{
877877
// this is suspected to be dead
878-
assert(false);
878+
UNREACHABLE;
879879

880880
// make the last statement an expression
881881

@@ -2852,7 +2852,7 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)
28522852
else if(expr.id()==ID_bitxor)
28532853
expr.id(ID_xor);
28542854
else
2855-
assert(false);
2855+
UNREACHABLE;
28562856
expr.type()=type0;
28572857
return;
28582858
}
@@ -3010,7 +3010,7 @@ void c_typecheck_baset::typecheck_expr_pointer_arithmetic(exprt &expr)
30103010
else
30113011
{
30123012
p_op=int_op=nullptr;
3013-
assert(false);
3013+
UNREACHABLE;
30143014
}
30153015

30163016
const typet &int_op_type=follow(int_op->type());

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void c_typecheck_baset::designator_enter(
344344
entry.subtype=vector_type.subtype();
345345
}
346346
else
347-
assert(false);
347+
UNREACHABLE;
348348

349349
designator.push_entry(entry);
350350
}
@@ -478,7 +478,7 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
478478
dest=&(dest->op0());
479479
}
480480
else
481-
assert(false);
481+
UNREACHABLE;
482482
}
483483

484484
// second phase: assign value

src/ansi-c/c_typecheck_type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void c_typecheck_baset::typecheck_custom_type(typet &type)
380380
type.set(ID_f, integer2string(f_int));
381381
}
382382
else
383-
assert(false);
383+
UNREACHABLE;
384384
}
385385

386386
void c_typecheck_baset::typecheck_code_type(code_typet &type)
@@ -759,7 +759,7 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
759759
else if(compound_symbol.type.id()==ID_union)
760760
compound_symbol.type.id(ID_incomplete_union);
761761
else
762-
assert(false);
762+
UNREACHABLE;
763763

764764
symbolt *new_symbol;
765765
move_symbol(compound_symbol, new_symbol);

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void expr2ct::get_shorthands(const exprt &expr)
114114
ns_collision[symbol->location.get_function()].insert(sh);
115115

116116
if(!shorthands.insert(std::make_pair(*it, sh)).second)
117-
assert(false);
117+
UNREACHABLE;
118118
}
119119

120120
for(find_symbols_sett::const_iterator

src/cbmc/all_properties_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class bmc_all_propertiest:
5656
}
5757

5858
// make some poor compilers happy
59-
assert(false);
59+
UNREACHABLE;
6060
return "";
6161
}
6262

src/cbmc/counterexample_beautification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ counterexample_beautificationt::get_failed_property(
7474
prop_conv.l_get(it->cond_literal).is_false())
7575
return it;
7676

77-
assert(false);
77+
UNREACHABLE;
7878
return equation.SSA_steps.end();
7979
}
8080

src/cbmc/fault_localization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fault_localizationt::get_failed_property()
7373
bmc.prop_conv.l_get(it->cond_literal).is_false())
7474
return it;
7575

76-
assert(false);
76+
UNREACHABLE;
7777
return bmc.equation.SSA_steps.end();
7878
}
7979

src/cbmc/symex_coverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void goto_program_coverage_recordt::compute_coverage_lines(
247247
branches_total+=2;
248248
if(!entry.first->second.conditions.insert(
249249
{it, coverage_conditiont()}).second)
250-
assert(false);
250+
UNREACHABLE;
251251
}
252252

253253
symex_coveraget::coveraget::const_iterator c_entry=

src/clobber/clobber_parse_options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ void clobber_parse_optionst::report_success()
433433
break;
434434

435435
default:
436-
assert(false);
436+
UNREACHABLE;
437437
}
438438
}
439439

@@ -458,7 +458,7 @@ void clobber_parse_optionst::show_counterexample(
458458
break;
459459

460460
default:
461-
assert(false);
461+
UNREACHABLE;
462462
}
463463
}
464464

@@ -481,7 +481,7 @@ void clobber_parse_optionst::report_failure()
481481
break;
482482

483483
default:
484-
assert(false);
484+
UNREACHABLE;
485485
}
486486
}
487487

src/cpp/cpp_constructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ codet cpp_typecheckt::cpp_constructor(
183183
}
184184
else if(tmp_type.id()==ID_union)
185185
{
186-
assert(0); // Todo: union
186+
UNREACHABLE; // Todo: union
187187
}
188188
else if(tmp_type.id()==ID_struct)
189189
{
@@ -301,7 +301,7 @@ codet cpp_typecheckt::cpp_constructor(
301301
}
302302
}
303303
else
304-
assert(false);
304+
UNREACHABLE;
305305

306306
codet nil;
307307
nil.make_nil();

src/cpp/cpp_convert_type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <cassert>
1515

16-
#include <util/config.h>
1716
#include <util/arith_tools.h>
18-
#include <util/std_types.h>
19-
2017
#include <util/c_types.h>
18+
#include <util/config.h>
19+
#include <util/invariant.h>
20+
#include <util/std_types.h>
2121

2222
#include "cpp_declaration.h"
2323
#include "cpp_name.h"
@@ -285,7 +285,7 @@ void cpp_convert_typet::read_function_type(const typet &type)
285285
throw "ellipsis only allowed as last parameter";
286286
}
287287
else
288-
assert(false);
288+
UNREACHABLE;
289289
}
290290

291291
// if we just have one parameter of type void, remove it

src/cpp/cpp_declarator_converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ symbolt &cpp_declarator_convertert::convert(
9191
// adjust template type
9292
if(final_type.id()==ID_template)
9393
{
94-
assert(0);
94+
UNREACHABLE;
9595
typet tmp;
9696
tmp.swap(final_type.subtype());
9797
final_type.swap(tmp);

src/cpp/cpp_scope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt kind)
2020
case cpp_scopet::QUALIFIED: return out << "QUALIFIED";
2121
case cpp_scopet::SCOPE_ONLY: return out << "SCOPE_ONLY";
2222
case cpp_scopet::RECURSIVE: return out << "RECURSIVE";
23-
default: assert(false);
23+
default: UNREACHABLE;
2424
}
2525

2626
return out;

src/cpp/cpp_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void cpp_typecheckt::do_not_typechecked()
250250
cont=true;
251251
}
252252
else
253-
assert(0); // Don't know what to do!
253+
UNREACHABLE; // Don't know what to do!
254254
}
255255
}
256256
}

src/cpp/cpp_typecheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ class cpp_typecheckt:public c_typecheck_baset
380380

381381
void put_compound_into_scope(const struct_union_typet::componentt &component);
382382
void typecheck_compound_body(symbolt &symbol);
383-
void typecheck_compound_body(struct_union_typet &type) { assert(false); }
383+
void typecheck_compound_body(struct_union_typet &type) { UNREACHABLE; }
384384
void typecheck_enum_body(symbolt &symbol);
385385
void typecheck_method_bodies(method_bodiest &);
386386
void typecheck_compound_bases(struct_typet &type);

src/cpp/cpp_typecheck_bases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void cpp_typecheckt::add_base_components(
209209
component.set_access(ID_private);
210210
}
211211
else
212-
assert(false);
212+
UNREACHABLE;
213213

214214
// put into scope
215215
}

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ bool cpp_typecheckt::dynamic_typecast(
17501750
{
17511751
if(!e.get_bool(ID_C_lvalue))
17521752
return false;
1753-
assert(0); // currently not supported
1753+
UNREACHABLE; // currently not supported
17541754
}
17551755
else if(follow(type.subtype()).id()==ID_struct)
17561756
{

0 commit comments

Comments
 (0)