Skip to content

Commit 20c9977

Browse files
committed
Consistently use void_type() in the C/C++ front-end
Should we ever choose to add any annotations consistent use of the generator function will ensure these are available.
1 parent e3232c7 commit 20c9977

6 files changed

+20
-18
lines changed

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ void record_function_outputs(
5454
code_blockt &init_code,
5555
symbol_tablet &symbol_table)
5656
{
57-
bool has_return_value=
58-
to_code_type(function.type).return_type()!=empty_typet();
57+
bool has_return_value =
58+
to_code_type(function.type).return_type() != void_type();
5959

6060
if(has_return_value)
6161
{
@@ -232,7 +232,7 @@ bool generate_ansi_c_start_function(
232232
call_main.add_source_location()=symbol.location;
233233
call_main.function().add_source_location()=symbol.location;
234234

235-
if(to_code_type(symbol.type).return_type()!=empty_typet())
235+
if(to_code_type(symbol.type).return_type() != void_type())
236236
{
237237
auxiliary_symbolt return_symbol;
238238
return_symbol.mode=ID_C;
@@ -515,7 +515,7 @@ bool generate_ansi_c_start_function(
515515
symbolt new_symbol;
516516

517517
new_symbol.name=goto_functionst::entry_point();
518-
new_symbol.type = code_typet({}, empty_typet());
518+
new_symbol.type = code_typet({}, void_type());
519519
new_symbol.value.swap(init_code);
520520
new_symbol.mode=symbol.mode;
521521

src/ansi-c/c_typecheck_base.cpp

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

1212
#include "c_typecheck_base.h"
1313

14+
#include <util/c_types.h>
15+
#include <util/config.h>
1416
#include <util/invariant.h>
15-
#include <util/std_types.h>
1617
#include <util/prefix.h>
17-
#include <util/config.h>
18+
#include <util/std_types.h>
1819

1920
#include "expr2c.h"
2021
#include "type2name.h"
@@ -740,7 +741,7 @@ void c_typecheck_baset::typecheck_declaration(
740741

741742
typecheck_spec_expr(static_cast<codet &>(contract), ID_C_spec_requires);
742743

743-
typet ret_type=empty_typet();
744+
typet ret_type = void_type();
744745
if(new_symbol.type.id()==ID_code)
745746
ret_type=to_code_type(new_symbol.type).return_type();
746747
assert(parameter_map.empty());

src/ansi-c/c_typecheck_code.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "c_typecheck_base.h"
1313

14+
#include <util/c_types.h>
1415
#include <util/config.h>
1516
#include <util/expr_initializer.h>
1617

@@ -575,7 +576,7 @@ void c_typecheck_baset::typecheck_gcc_computed_goto(codet &code)
575576
assert(dest.operands().size()==1);
576577

577578
typecheck_expr(dest.op0());
578-
dest.type()=empty_typet();
579+
dest.type() = void_type();
579580
}
580581

581582
void c_typecheck_baset::typecheck_ifthenelse(code_ifthenelset &code)

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ void c_typecheck_baset::typecheck_expr_trinary(if_exprt &expr)
16011601
{
16021602
// Make it void *.
16031603
// gcc and clang issue a warning for this.
1604-
expr.type()=pointer_type(empty_typet());
1604+
expr.type() = pointer_type(void_type());
16051605
implicit_typecast(operands[1], expr.type());
16061606
implicit_typecast(operands[2], expr.type());
16071607
}

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void cpp_typecheckt::typecheck_expr_trinary(if_exprt &expr)
219219
expr.type()=expr.op1().type();
220220
else if(expr.op1().type().id()==ID_empty &&
221221
expr.op2().type().id()==ID_empty)
222-
expr.type()=empty_typet();
222+
expr.type() = void_type();
223223
else
224224
{
225225
error().source_location=expr.find_source_location();
@@ -738,8 +738,7 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
738738

739739
void cpp_typecheckt::typecheck_expr_throw(exprt &expr)
740740
{
741-
// these are of type void
742-
expr.type()=empty_typet();
741+
expr.type() = void_type();
743742

744743
assert(expr.operands().size()==1 ||
745744
expr.operands().empty());
@@ -1514,7 +1513,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15141513
{code_typet::parametert(ptr_arg.type()),
15151514
code_typet::parametert(ptr_arg.type().subtype()),
15161515
code_typet::parametert(signed_int_type())},
1517-
empty_typet());
1516+
void_type());
15181517
symbol_exprt result(identifier, t);
15191518
result.add_source_location() = source_location;
15201519
expr.swap(result);
@@ -1588,7 +1587,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15881587
{code_typet::parametert(ptr_arg.type()),
15891588
code_typet::parametert(ptr_arg.type()),
15901589
code_typet::parametert(signed_int_type())},
1591-
empty_typet());
1590+
void_type());
15921591
symbol_exprt result(identifier, t);
15931592
result.add_source_location() = source_location;
15941593
expr.swap(result);
@@ -1636,7 +1635,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
16361635
code_typet::parametert(ptr_arg.type()),
16371636
code_typet::parametert(ptr_arg.type()),
16381637
code_typet::parametert(signed_int_type())},
1639-
empty_typet());
1638+
void_type());
16401639
symbol_exprt result(identifier, t);
16411640
result.add_source_location() = source_location;
16421641
expr.swap(result);

src/cpp/cpp_typecheck_function.cpp

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

1212
#include "cpp_typecheck.h"
1313

14+
#include <util/c_types.h>
15+
1416
#include <ansi-c/c_qualifiers.h>
1517

1618
#include "cpp_template_type.h"
@@ -139,9 +141,8 @@ void cpp_typecheckt::convert_function(symbolt &symbol)
139141
return_type=function_type.return_type();
140142

141143
// constructor, destructor?
142-
if(return_type.id()==ID_constructor ||
143-
return_type.id()==ID_destructor)
144-
return_type=empty_typet();
144+
if(return_type.id() == ID_constructor || return_type.id() == ID_destructor)
145+
return_type = void_type();
145146

146147
typecheck_code(to_code(symbol.value));
147148

0 commit comments

Comments
 (0)