Skip to content

Commit 0a3b99b

Browse files
smowtonthk123
authored and
thk123
committed
Java pointer casts: ensure type consistency, even when casting to a base type
This is necessary because a generic qualifier is recorded on the pointer, while the direct member has an unqualified type.
1 parent 3897b39 commit 0a3b99b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

jbmc/src/java_bytecode/java_pointer_casts.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ exprt make_clean_pointer_cast(
118118
return bare_ptr;
119119

120120
exprt superclass_ptr=bare_ptr;
121+
// Looking at base types discards generic qualifiers (because those are
122+
// recorded on the pointer, not the pointee), so it may still be necessary
123+
// to use a cast to reintroduce the qualifier (for example, the base might
124+
// be recorded as a List, when we're looking for a List<E>)
121125
if(find_superclass_with_type(superclass_ptr, target_base, ns))
122-
return superclass_ptr;
126+
return typecast_exprt::conditional_cast(superclass_ptr, target_type);
123127

124128
return typecast_exprt(bare_ptr, target_type);
125129
}

0 commit comments

Comments
 (0)