@@ -12,9 +12,10 @@ Author: Diffblue Ltd.
1212#include " does_remove_const.h"
1313
1414#include < goto-programs/goto_program.h>
15- #include < util/type.h>
16- #include < util/std_code.h>
15+
1716#include < util/base_type.h>
17+ #include < util/pointer_expr.h>
18+ #include < util/std_code.h>
1819
1920// / A naive analysis to look for casts that remove const-ness from pointers.
2021// / \param goto_program: the goto program to check
@@ -122,16 +123,20 @@ bool does_remove_constt::does_type_preserve_const_correctness(
122123{
123124 while (target_type->id ()==ID_pointer)
124125 {
125- bool direct_subtypes_at_least_as_const=
126- is_type_at_least_as_const_as (
127- target_type->subtype (), source_type->subtype ());
126+ PRECONDITION (source_type->id () == ID_pointer);
127+
128+ const auto &target_pointer_type = to_pointer_type (*target_type);
129+ const auto &source_pointer_type = to_pointer_type (*source_type);
130+
131+ bool direct_subtypes_at_least_as_const = is_type_at_least_as_const_as (
132+ target_pointer_type.base_type (), source_pointer_type.base_type ());
128133 // We have a pointer to something, but the thing it is pointing to can't be
129134 // modified normally, but can through this pointer
130135 if (!direct_subtypes_at_least_as_const)
131136 return false ;
132137 // Check the subtypes if they are pointers
133- target_type=&target_type-> subtype ();
134- source_type=&source_type-> subtype ();
138+ target_type = &target_pointer_type. base_type ();
139+ source_type = &source_pointer_type. base_type ();
135140 }
136141 return true ;
137142}
0 commit comments