@@ -57,9 +57,9 @@ class LocField final : public FieldNode {
57
57
}
58
58
};
59
59
60
- // / Represents a void* field that needs to be casted back to its dynamic type
61
- // / for a correct note message.
62
- class NeedsCastLocField final : public FieldNode {
60
+ // / Represents a nonloc::LocAsInteger or void* field, that point to objects, but
61
+ // / needs to be casted back to its dynamic type for a correct note message.
62
+ class NeedsCastLocField : public FieldNode {
63
63
QualType CastBackType;
64
64
65
65
public:
@@ -71,7 +71,13 @@ class NeedsCastLocField final : public FieldNode {
71
71
}
72
72
73
73
virtual void printPrefix (llvm::raw_ostream &Out) const override {
74
- Out << " static_cast" << ' <' << CastBackType.getAsString () << " >(" ;
74
+ // If this object is a nonloc::LocAsInteger.
75
+ if (getDecl ()->getType ()->isIntegerType ())
76
+ Out << " reinterpret_cast" ;
77
+ // If this pointer's dynamic type is different then it's static type.
78
+ else
79
+ Out << " static_cast" ;
80
+ Out << ' <' << CastBackType.getAsString () << " >(" ;
75
81
}
76
82
77
83
virtual void printNode (llvm::raw_ostream &Out) const override {
@@ -106,11 +112,12 @@ static llvm::Optional<DereferenceInfo> dereference(ProgramStateRef State,
106
112
bool FindUninitializedFields::isDereferencableUninit (
107
113
const FieldRegion *FR, FieldChainInfo LocalChain) {
108
114
109
- assert (isDereferencableType (FR->getDecl ()->getType ()) &&
110
- " This method only checks dereferencable objects!" );
111
-
112
115
SVal V = State->getSVal (FR);
113
116
117
+ assert ((isDereferencableType (FR->getDecl ()->getType ()) ||
118
+ V.getAs <nonloc::LocAsInteger>()) &&
119
+ " This method only checks dereferencable objects!" );
120
+
114
121
if (V.isUnknown () || V.getAs <loc::ConcreteInt>()) {
115
122
IsAnyFieldInitialized = true ;
116
123
return false ;
@@ -196,13 +203,15 @@ static llvm::Optional<DereferenceInfo> dereference(ProgramStateRef State,
196
203
197
204
llvm::SmallSet<const TypedValueRegion *, 5 > VisitedRegions;
198
205
199
- // If the static type of the field is a void pointer, we need to cast it back
200
- // to the dynamic type before dereferencing.
201
- bool NeedsCastBack = isVoidPointer (FR->getDecl ()->getType ());
202
-
203
206
SVal V = State->getSVal (FR);
204
207
assert (V.getAsRegion () && " V must have an underlying region!" );
205
208
209
+ // If the static type of the field is a void pointer, or it is a
210
+ // nonloc::LocAsInteger, we need to cast it back to the dynamic type before
211
+ // dereferencing.
212
+ bool NeedsCastBack = isVoidPointer (FR->getDecl ()->getType ()) ||
213
+ V.getAs <nonloc::LocAsInteger>();
214
+
206
215
// The region we'd like to acquire.
207
216
const auto *R = V.getAsRegion ()->getAs <TypedValueRegion>();
208
217
if (!R)
0 commit comments