[clang] 05d8b5e - [analyzer] Support `PointerType` in `getCXXRecordDecl` for `ContainerModeling` (#87787)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 12 09:15:37 PDT 2024
Author: JOSTAR
Date: 2024-04-12T18:15:33+02:00
New Revision: 05d8b5e62d7a1cf2f94582346d6fd2d39667a26b
URL: https://github.com/llvm/llvm-project/commit/05d8b5e62d7a1cf2f94582346d6fd2d39667a26b
DIFF: https://github.com/llvm/llvm-project/commit/05d8b5e62d7a1cf2f94582346d6fd2d39667a26b.diff
LOG: [analyzer] Support `PointerType` in `getCXXRecordDecl` for `ContainerModeling` (#87787)
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
clang/test/Analysis/invalidated-iterator.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
index 65a2ec4076fdf6..009c0d3fb93686 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
@@ -770,6 +770,10 @@ const CXXRecordDecl *getCXXRecordDecl(ProgramStateRef State,
Type = RefT->getPointeeType();
}
+ if (const auto *PtrT = Type->getAs<PointerType>()) {
+ Type = PtrT->getPointeeType();
+ }
+
return Type->getUnqualifiedDesugaredType()->getAsCXXRecordDecl();
}
diff --git a/clang/test/Analysis/invalidated-iterator.cpp b/clang/test/Analysis/invalidated-iterator.cpp
index 778a8e01d99380..c940dbf7276d34 100644
--- a/clang/test/Analysis/invalidated-iterator.cpp
+++ b/clang/test/Analysis/invalidated-iterator.cpp
@@ -130,6 +130,14 @@ struct cont_with_ptr_iterator {
T* erase(T*);
};
+void invalidated_access_via_end_iterator_after_push_back() {
+ cont_with_ptr_iterator<int> C;
+ C.push_back(1);
+ auto i = C.end();
+ C.push_back(2);
+ auto j = i[-1]; // expected-warning{{Invalidated iterator accessed}}
+}
+
void invalidated_dereference_end_ptr_iterator(cont_with_ptr_iterator<int> &C) {
auto i = C.begin();
C.erase(i);
@@ -196,4 +204,4 @@ void invalidated_subscript_end_ptr_iterator(cont_with_ptr_iterator<int> &C) {
auto i = C.begin();
C.erase(i);
(void) i[1]; // expected-warning{{Invalidated iterator accessed}}
-}
+}
\ No newline at end of file
More information about the cfe-commits
mailing list