Skip to content

Commit 8425bf4

Browse files
author
Daniel Kroening
authored
Merge pull request #970 from diffblue/pointers-with-width
Pointers get a width
2 parents 0423be7 + d3c0b57 commit 8425bf4

22 files changed

+71
-95
lines changed

regression/invariants/driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ Author: Chris Smowton, chris.smowton@diffblue.com
1111

1212
#include <string>
1313
#include <sstream>
14+
1415
#include <util/invariant.h>
1516
#include <util/invariant_utils.h>
1617
#include <util/std_types.h>
18+
#include <util/c_types.h>
1719

1820
/// An example of structured invariants-- this contains fields to
1921
/// describe the error to a catcher, and also produces a human-readable
@@ -86,7 +88,7 @@ int main(int argc, char** argv)
8688
else if(arg=="data-invariant-string")
8789
DATA_INVARIANT(false, "Test invariant failure");
8890
else if(arg=="irep")
89-
INVARIANT_WITH_IREP(false, "error with irep", pointer_typet(void_typet()));
91+
INVARIANT_WITH_IREP(false, "error with irep", pointer_type(void_typet()));
9092
else
9193
return 1;
9294
}

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ void ansi_c_convert_typet::read_rec(const typet &type)
216216
{
217217
c_storage_spec.alias=type.subtype().get(ID_value);
218218
}
219+
else if(type.id()==ID_pointer)
220+
{
221+
// pointers have a width, much like integers
222+
pointer_typet tmp=to_pointer_type(type);
223+
tmp.set_width(config.ansi_c.pointer_width);
224+
other.push_back(tmp);
225+
}
219226
else
220227
other.push_back(type);
221228
}

src/ansi-c/c_typecheck_type.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ void c_typecheck_baset::typecheck_type(typet &type)
7676
else if(type.id()==ID_array)
7777
typecheck_array_type(to_array_type(type));
7878
else if(type.id()==ID_pointer)
79+
{
7980
typecheck_type(type.subtype());
81+
INVARIANT(!type.get(ID_width).empty(), "pointers must have width");
82+
}
8083
else if(type.id()==ID_struct ||
8184
type.id()==ID_union)
8285
typecheck_compound_type(to_struct_union_type(type));

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ void cpp_typecheckt::default_cpctor(
223223
cpp_declaratort parameter_tor;
224224
parameter_tor.add(ID_value).make_nil();
225225
parameter_tor.set(ID_name, cpp_parameter);
226-
parameter_tor.type()=reference_typet();
227-
parameter_tor.type().subtype().make_nil();
226+
parameter_tor.type()=reference_type(nil_typet());
228227
parameter_tor.add_source_location()=source_location;
229228

230229
// Parameter declaration
@@ -388,9 +387,8 @@ void cpp_typecheckt::default_assignop(
388387
declarator_name.get_sub().push_back(irept("="));
389388

390389
declarator_type.id(ID_function_type);
391-
declarator_type.subtype()=reference_typet();
390+
declarator_type.subtype()=reference_type(nil_typet());
392391
declarator_type.subtype().add("#qualifier").make_nil();
393-
declarator_type.subtype().subtype().make_nil();
394392

395393
exprt &args=static_cast<exprt&>(declarator.type().add(ID_parameters));
396394
args.add_source_location()=source_location;

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,11 +1280,8 @@ bool cpp_typecheckt::reference_binding(
12801280
if(reference_compatible(expr, type, rank))
12811281
{
12821282
{
1283-
address_of_exprt tmp;
1283+
address_of_exprt tmp(expr, reference_type(expr.type()));
12841284
tmp.add_source_location()=expr.source_location();
1285-
tmp.object()=expr;
1286-
tmp.type()=pointer_type(tmp.op0().type());
1287-
tmp.type().set(ID_C_reference, true);
12881285
new_expr.swap(tmp);
12891286
}
12901287

@@ -1411,10 +1408,7 @@ bool cpp_typecheckt::reference_binding(
14111408

14121409
if(user_defined_conversion_sequence(arg_expr, type.subtype(), new_expr, rank))
14131410
{
1414-
address_of_exprt tmp;
1415-
tmp.type()=pointer_type(new_expr.type());
1416-
tmp.object()=new_expr;
1417-
tmp.type().set(ID_C_reference, true);
1411+
address_of_exprt tmp(new_expr, reference_type(new_expr.type()));
14181412
tmp.add_source_location()=new_expr.source_location();
14191413
new_expr.swap(tmp);
14201414
return true;

src/cpp/cpp_typecheck_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1414
#include <util/source_location.h>
1515
#include <util/simplify_expr.h>
1616
#include <util/c_types.h>
17+
#include <util/config.h>
1718

1819
#include <ansi-c/c_qualifiers.h>
1920

@@ -81,6 +82,9 @@ void cpp_typecheckt::typecheck_type(typet &type)
8182
// the pointer might have a qualifier, but do subtype first
8283
typecheck_type(type.subtype());
8384

85+
// we add a width, much like with integers
86+
to_pointer_type(type).set_width(config.ansi_c.pointer_width);
87+
8488
// Check if it is a pointer-to-member
8589
if(type.find("to-member").is_not_nil())
8690
{

src/cpp/parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3015,7 +3015,7 @@ bool Parser::optPtrOperator(typet &ptrs)
30153015

30163016
if(t=='*')
30173017
{
3018-
pointer_typet op;
3018+
typet op(ID_pointer);
30193019
cpp_tokent tk;
30203020
lex.get_token(tk);
30213021
set_location(op, tk);

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ void goto_symext::symex_malloc(
165165

166166
new_symbol_table.add(value_symbol);
167167

168-
address_of_exprt rhs;
168+
exprt rhs;
169169

170170
if(object_type.id()==ID_array)
171171
{
172-
rhs.type()=pointer_type(value_symbol.type.subtype());
173172
index_exprt index_expr(value_symbol.type.subtype());
174173
index_expr.array()=value_symbol.symbol_expr();
175174
index_expr.index()=from_integer(0, index_type());
176-
rhs.op0()=index_expr;
175+
rhs=address_of_exprt(
176+
index_expr, pointer_type(value_symbol.type.subtype()));
177177
}
178178
else
179179
{
180-
rhs.op0()=value_symbol.symbol_expr();
181-
rhs.type()=pointer_type(value_symbol.type);
180+
rhs=address_of_exprt(
181+
value_symbol.symbol_expr(), pointer_type(value_symbol.type));
182182
}
183183

184184
if(rhs.type()!=lhs.type())

src/goto-symex/symex_dead.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ void goto_symext::symex_dead(statet &state)
4545
exprt rhs;
4646

4747
if(failed.is_not_nil())
48-
{
49-
address_of_exprt address_of_expr;
50-
address_of_expr.object()=failed;
51-
address_of_expr.type()=code.op0().type();
52-
rhs=address_of_expr;
53-
}
48+
rhs=address_of_exprt(failed, to_pointer_type(code.op0().type()));
5449
else
5550
rhs=exprt(ID_invalid);
5651

src/goto-symex/symex_decl.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
6060
exprt rhs;
6161

6262
if(failed.is_not_nil())
63-
{
64-
address_of_exprt address_of_expr;
65-
address_of_expr.object()=failed;
66-
address_of_expr.type()=expr.type();
67-
rhs=address_of_expr;
68-
}
63+
rhs=address_of_exprt(failed, to_pointer_type(expr.type()));
6964
else
7065
rhs=exprt(ID_invalid);
7166

0 commit comments

Comments
 (0)