[clang] a27af1d - [analyzer] Fix assertion in SVals.h
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 30 09:01:02 PDT 2021
Author: Vince Bridgers
Date: 2021-04-30T11:00:43-05:00
New Revision: a27af1d8166cc8cebd6ecfed94042852922d8239
URL: https://github.com/llvm/llvm-project/commit/a27af1d8166cc8cebd6ecfed94042852922d8239
DIFF: https://github.com/llvm/llvm-project/commit/a27af1d8166cc8cebd6ecfed94042852922d8239.diff
LOG: [analyzer] Fix assertion in SVals.h
Fix assertion in SVals.h apparently caused by
https://reviews.llvm.org/D89055.
clang:clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:596:
clang::ento::loc::MemRegionVal::MemRegionVal(const clang::ento::MemRegion *):
Assertion `r' failed.
Backtrace:
...
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:597:3
clang::QualType, clang::QualType)
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:773:18
clang::QualType, clang::QualType)
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:612:12
clang::QualType) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:587:12
namespace)::RegionBindingsRef const&, clang::ento::Loc, clang::QualType)
clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1510:24
...
Reviewed By: ASDenysPetrov
Differential Revision: https://reviews.llvm.org/D101635
Added:
Modified:
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
clang/test/Analysis/casts.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index f376922754bf1..0003c27513994 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -761,8 +761,8 @@ SVal SValBuilder::evalCastSubKind(loc::MemRegionVal V, QualType CastTy,
// Next fixes pointer dereference using type
diff erent from its initial
// one. See PR37503 and PR49007 for details.
if (const auto *ER = dyn_cast<ElementRegion>(R)) {
- R = StateMgr.getStoreManager().castRegion(ER, CastTy);
- return loc::MemRegionVal(R);
+ if ((R = StateMgr.getStoreManager().castRegion(ER, CastTy)))
+ return loc::MemRegionVal(R);
}
return V;
diff --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c
index 702e53a82f2e2..1de7ef54b57fb 100644
--- a/clang/test/Analysis/casts.c
+++ b/clang/test/Analysis/casts.c
@@ -250,3 +250,19 @@ void no_crash_reinterpret_char_as_uchar(char ***a, int *b) {
if (**a == 0) // no-crash
;
}
+
+// See PR50179.
+// Just don't crash.
+typedef struct taskS {
+ void *pJob;
+} taskS;
+
+typedef struct workS {
+ taskS *pTaskList;
+} workS;
+
+void *getTaskJob(unsigned jobId, workS *pWork, unsigned taskId) {
+ const taskS *pTask = pWork->pTaskList + taskId;
+ taskS task = *pTask;
+ return task.pJob;
+}
More information about the cfe-commits
mailing list