Skip to content

Commit 636655d

Browse files
author
Daniel Kroening
committed
address_of now needs a pointer type
1 parent 13f3d5f commit 636655d

File tree

10 files changed

+65
-69
lines changed

10 files changed

+65
-69
lines changed

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,13 @@ bool ansi_c_entry_point(
327327
zero_string.type().set(ID_size, "infinity");
328328
exprt index(ID_index, char_type());
329329
index.copy_to_operands(zero_string, from_integer(0, uint_type()));
330-
exprt address_of("address_of", pointer_type(char_type()));
331-
address_of.copy_to_operands(index);
330+
exprt address_of=address_of_exprt(index, pointer_type(char_type()));
332331
333332
if(argv_symbol.type.subtype()!=address_of.type())
334333
address_of.make_typecast(argv_symbol.type.subtype());
335334
336335
// assign argv[*] to the address of a string-object
337-
exprt array_of("array_of", argv_symbol.type);
338-
array_of.copy_to_operands(address_of);
336+
array_of_exprt array_of(address_of, argv_symbol.type);
339337
340338
init_code.copy_to_operands(
341339
code_assignt(argv_symbol.symbol_expr(), array_of));
@@ -399,17 +397,18 @@ bool ansi_c_entry_point(
399397

400398
{
401399
const exprt &arg1=parameters[1];
400+
const pointer_typet &pointer_type=
401+
to_pointer_type(arg1.type());
402402

403-
exprt index_expr(ID_index, arg1.type().subtype());
404-
index_expr.copy_to_operands(
403+
index_exprt index_expr(
405404
argv_symbol.symbol_expr(),
406-
from_integer(0, index_type()));
405+
from_integer(0, index_type()),
406+
pointer_type.subtype());
407407

408408
// disable bounds check on that one
409409
index_expr.set("bounds_check", false);
410410

411-
op1=exprt(ID_address_of, arg1.type());
412-
op1.move_to_operands(index_expr);
411+
op1=address_of_exprt(index_expr, pointer_type);
413412
}
414413

415414
// do we need envp?
@@ -419,13 +418,15 @@ bool ansi_c_entry_point(
419418
exprt &op2=operands[2];
420419

421420
const exprt &arg2=parameters[2];
421+
const pointer_typet &pointer_type=
422+
to_pointer_type(arg2.type());
422423

423-
exprt index_expr(ID_index, arg2.type().subtype());
424-
index_expr.copy_to_operands(
425-
envp_symbol.symbol_expr(), from_integer(0, index_type()));
424+
index_exprt index_expr(
425+
envp_symbol.symbol_expr(),
426+
from_integer(0, index_type()),
427+
pointer_type.subtype());
426428

427-
op2=exprt(ID_address_of, arg2.type());
428-
op2.move_to_operands(index_expr);
429+
op2=address_of_exprt(index_expr, pointer_type);
429430
}
430431
}
431432
}

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,10 @@ void c_typecheck_baset::typecheck_expr_symbol(exprt &expr)
834834

835835
if(expr.type().id()==ID_code) // function designator
836836
{ // special case: this is sugar for &f
837-
exprt tmp(ID_address_of, pointer_type(expr.type()));
837+
address_of_exprt tmp(expr, pointer_type(expr.type()));
838838
tmp.set("#implicit", true);
839839
tmp.add_source_location()=expr.source_location();
840-
tmp.move_to_operands(expr);
841-
expr.swap(tmp);
840+
expr=tmp;
842841
}
843842
}
844843
}
@@ -1778,11 +1777,10 @@ void c_typecheck_baset::typecheck_expr_function_identifier(exprt &expr)
17781777
{
17791778
if(expr.type().id()==ID_code)
17801779
{
1781-
exprt tmp(ID_address_of, pointer_type(expr.type()));
1780+
address_of_exprt tmp(expr, pointer_type(expr.type()));
17821781
tmp.set(ID_C_implicit, true);
17831782
tmp.add_source_location()=expr.source_location();
1784-
tmp.move_to_operands(expr);
1785-
expr.swap(tmp);
1783+
expr=tmp;
17861784
}
17871785
}
17881786

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ codet cpp_typecheckt::cpp_constructor(
289289
assert(tmp_this.id()==ID_address_of
290290
&& tmp_this.op0().id()=="new_object");
291291

292-
exprt address_of=
293-
address_of_exprt(object_tc, pointer_type(object_tc.type()));
294-
tmp_this.swap(address_of);
292+
tmp_this=address_of_exprt(object_tc);
295293

296294
if(block.operands().empty())
297295
return to_code(initializer);

src/cpp/cpp_destructor.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ codet cpp_typecheckt::cpp_destructor(
142142
assert(tmp_this.id()==ID_address_of
143143
&& tmp_this.op0().id()=="new_object");
144144

145-
exprt address_of=
146-
address_of_exprt(object, pointer_type(object.type()));
147-
148-
tmp_this.swap(address_of);
145+
tmp_this=address_of_exprt(object, pointer_type(object.type()));
149146

150147
new_code.swap(initializer);
151148
}

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,11 @@ bool cpp_typecheckt::standard_conversion_array_to_pointer(
7575

7676
index_exprt index(
7777
expr,
78-
from_integer(0, index_type()),
79-
expr.type().subtype());
78+
from_integer(0, index_type()));
8079

8180
index.set(ID_C_lvalue, true);
8281

83-
pointer_typet pointer=
84-
pointer_type(expr.type().subtype());
85-
86-
new_expr=address_of_exprt(index, pointer);
82+
new_expr=address_of_exprt(index);
8783

8884
return true;
8985
}
@@ -98,14 +94,10 @@ bool cpp_typecheckt::standard_conversion_array_to_pointer(
9894
bool cpp_typecheckt::standard_conversion_function_to_pointer(
9995
const exprt &expr, exprt &new_expr) const
10096
{
101-
const code_typet &func_type=to_code_type(expr.type());
102-
10397
if(!expr.get_bool(ID_C_lvalue))
10498
return false;
10599

106-
pointer_typet pointer=pointer_type(func_type);
107-
108-
new_expr=address_of_exprt(expr, pointer);
100+
new_expr=address_of_exprt(expr);
109101

110102
return true;
111103
}
@@ -886,7 +878,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
886878

887879
if(subtype_typecast(from_struct, to_struct))
888880
{
889-
exprt address=address_of_exprt(expr, pointer_type(expr.type()));
881+
exprt address=address_of_exprt(expr);
890882

891883
// simplify address
892884
if(expr.id()==ID_dereference)
@@ -1016,9 +1008,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
10161008
else if(from_struct.is_not_nil() && arg1_struct.is_not_nil())
10171009
{
10181010
// try derived-to-base conversion
1019-
exprt expr_pfrom=
1020-
address_of_exprt(expr, pointer_type(expr.type()));
1021-
1011+
address_of_exprt expr_pfrom(expr, pointer_type(expr.type()));
10221012
pointer_typet pto=pointer_type(arg1_type);
10231013

10241014
exprt expr_ptmp;
@@ -1441,12 +1431,11 @@ bool cpp_typecheckt::reference_binding(
14411431
new_expr.swap(tmp);
14421432
}
14431433

1444-
exprt tmp=
1445-
address_of_exprt(new_expr, pointer_type(new_expr.type()));
1434+
address_of_exprt tmp(new_expr, pointer_type(new_expr.type()));
14461435
tmp.type().set(ID_C_reference, true);
14471436
tmp.add_source_location()=new_expr.source_location();
14481437

1449-
new_expr.swap(tmp);
1438+
new_expr=tmp;
14501439
return true;
14511440
}
14521441

@@ -1707,10 +1696,9 @@ bool cpp_typecheckt::const_typecast(
17071696
if(new_expr.type()!=type.subtype())
17081697
return false;
17091698

1710-
exprt address_of(ID_address_of, type);
1711-
address_of.copy_to_operands(expr);
1699+
exprt address_of=address_of_exprt(expr, to_pointer_type(type));
17121700
add_implicit_dereference(address_of);
1713-
new_expr.swap(address_of);
1701+
new_expr=address_of;
17141702
return true;
17151703
}
17161704
else if(type.id()==ID_pointer)
@@ -1872,7 +1860,7 @@ bool cpp_typecheckt::reinterpret_typecast(
18721860

18731861
if(is_reference(type) && e.get_bool(ID_C_lvalue))
18741862
{
1875-
exprt tmp=address_of_exprt(e, pointer_type(e.type()));
1863+
exprt tmp=address_of_exprt(e);
18761864
tmp.make_typecast(type);
18771865
new_expr.swap(tmp);
18781866
return true;
@@ -1936,7 +1924,7 @@ bool cpp_typecheckt::static_typecast(
19361924
return true;
19371925
}
19381926

1939-
exprt address_of=address_of_exprt(e, pointer_type(e.type()));
1927+
exprt address_of=address_of_exprt(e);
19401928
make_ptr_typecast(address_of, type);
19411929
new_expr.swap(address_of);
19421930
return true;

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,9 +2252,9 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
22522252
if(operand.type().id()!=ID_pointer &&
22532253
operand.type()==argument.type().subtype())
22542254
{
2255-
exprt tmp=address_of_exprt(operand, pointer_type(operand.type()));
2255+
address_of_exprt tmp(operand, pointer_type(operand.type()));
22562256
tmp.add_source_location()=operand.source_location();
2257-
operand.swap(tmp);
2257+
operand=tmp;
22582258
}
22592259
}
22602260
}
@@ -2666,9 +2666,7 @@ void cpp_typecheckt::convert_pmop(exprt &expr)
26662666
else
26672667
{
26682668
assert(expr.op0().get_bool(ID_C_lvalue));
2669-
exprt address_of=
2670-
address_of_exprt(expr.op0(), pointer_type(expr.op0().type()));
2671-
expr.op0().swap(address_of);
2669+
expr.op0()=address_of_exprt(expr.op0());
26722670
}
26732671
}
26742672

src/goto-programs/string_instrumentation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,12 +825,12 @@ void string_instrumentationt::do_strerror(
825825
}
826826

827827
// return a pointer to some magic buffer
828-
exprt index=exprt(ID_index, char_type());
829-
index.copy_to_operands(
828+
index_exprt index(
830829
symbol_buf.symbol_expr(),
831-
from_integer(0, index_type()));
830+
from_integer(0, index_type()),
831+
char_type());
832832

833-
exprt ptr=address_of_exprt(index, pointer_type(char_type()));
833+
address_of_exprt ptr(index);
834834

835835
// make that zero-terminated
836836
{

src/goto-symex/auto_objects.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ void goto_symext::initialize_auto_object(
6666
{
6767
// could be NULL nondeterministically
6868

69-
address_of_exprt address_of_expr=
70-
address_of_exprt(make_auto_object(type.subtype()));
69+
address_of_exprt address_of_expr(
70+
make_auto_object(type.subtype()),
71+
pointer_type);
7172

7273
if_exprt rhs(
7374
side_effect_expr_nondett(bool_typet()),

src/util/std_expr.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ Author: Daniel Kroening, [email protected]
1313
#include "arith_tools.h"
1414
#include "byte_operators.h"
1515
#include "c_types.h"
16-
#include "config.h"
1716
#include "namespace.h"
1817
#include "pointer_offset_size.h"
19-
2018
#include "std_types.h"
2119

2220
bool constant_exprt::value_is_zero_string() const
@@ -171,3 +169,20 @@ extractbits_exprt::extractbits_exprt(
171169
upper()=constant_exprt::integer_constant(_upper);
172170
lower()=constant_exprt::integer_constant(_lower);
173171
}
172+
173+
/*******************************************************************\
174+
175+
Function: address_of_exprt::address_of_exprt
176+
177+
Inputs:
178+
179+
Outputs:
180+
181+
Purpose:
182+
183+
\*******************************************************************/
184+
185+
address_of_exprt::address_of_exprt(const exprt &_op):
186+
unary_exprt(ID_address_of, _op, pointer_type(_op.type()))
187+
{
188+
}

src/util/std_expr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,19 +2590,19 @@ inline extractbits_exprt &to_extractbits_expr(exprt &expr)
25902590

25912591
/*! \brief Operator to return the address of an object
25922592
*/
2593-
class address_of_exprt:public exprt
2593+
class address_of_exprt:public unary_exprt
25942594
{
25952595
public:
2596-
explicit address_of_exprt(const exprt &op):
2597-
exprt(ID_address_of, pointer_typet(op.type()))
2596+
explicit address_of_exprt(const exprt &op);
2597+
2598+
address_of_exprt(const exprt &op, const pointer_typet &_type):
2599+
unary_exprt(ID_address_of, op, _type)
25982600
{
2599-
copy_to_operands(op);
26002601
}
26012602

26022603
address_of_exprt():
2603-
exprt(ID_address_of, pointer_typet())
2604+
unary_exprt(ID_address_of, pointer_typet())
26042605
{
2605-
operands().resize(1);
26062606
}
26072607

26082608
exprt &object()

0 commit comments

Comments
 (0)