Skip to content

Commit ce86319

Browse files
Daniel Kroeningpeterschrammel
authored andcommitted
pointer types now have width
1 parent f72b7fc commit ce86319

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

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_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
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/util/c_types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ signedbv_typet pointer_diff_type()
296296

297297
pointer_typet pointer_type(const typet &subtype)
298298
{
299-
return pointer_typet(subtype);
299+
return pointer_typet(subtype, config.ansi_c.pointer_width);
300300
}
301301

302302
reference_typet reference_type(const typet &subtype)
303303
{
304-
return reference_typet(subtype);
304+
return reference_typet(subtype, config.ansi_c.pointer_width);
305305
}
306306

307307
typet void_type()

0 commit comments

Comments
 (0)