Skip to content

Commit 05d8b5e

Browse files
[analyzer] Support PointerType in getCXXRecordDecl for ContainerModeling (#87787)
1 parent 8d468c1 commit 05d8b5e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ const CXXRecordDecl *getCXXRecordDecl(ProgramStateRef State,
770770
Type = RefT->getPointeeType();
771771
}
772772

773+
if (const auto *PtrT = Type->getAs<PointerType>()) {
774+
Type = PtrT->getPointeeType();
775+
}
776+
773777
return Type->getUnqualifiedDesugaredType()->getAsCXXRecordDecl();
774778
}
775779

clang/test/Analysis/invalidated-iterator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ struct cont_with_ptr_iterator {
130130
T* erase(T*);
131131
};
132132

133+
void invalidated_access_via_end_iterator_after_push_back() {
134+
cont_with_ptr_iterator<int> C;
135+
C.push_back(1);
136+
auto i = C.end();
137+
C.push_back(2);
138+
auto j = i[-1]; // expected-warning{{Invalidated iterator accessed}}
139+
}
140+
133141
void invalidated_dereference_end_ptr_iterator(cont_with_ptr_iterator<int> &C) {
134142
auto i = C.begin();
135143
C.erase(i);
@@ -196,4 +204,4 @@ void invalidated_subscript_end_ptr_iterator(cont_with_ptr_iterator<int> &C) {
196204
auto i = C.begin();
197205
C.erase(i);
198206
(void) i[1]; // expected-warning{{Invalidated iterator accessed}}
199-
}
207+
}

0 commit comments

Comments
 (0)