[clang] f0ced2d - [analysis] Re-discard type sugar when casting values retrieved from the Store.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 18 18:01:05 PST 2019
Author: Artem Dergachev
Date: 2019-12-18T18:00:57-08:00
New Revision: f0ced2ddb44e4bd970fec310591891a0cdb4462c
URL: https://github.com/llvm/llvm-project/commit/f0ced2ddb44e4bd970fec310591891a0cdb4462c
DIFF: https://github.com/llvm/llvm-project/commit/f0ced2ddb44e4bd970fec310591891a0cdb4462c.diff
LOG: [analysis] Re-discard type sugar when casting values retrieved from the Store.
Canonicalization was accidentally omitted in 6d3f43ec.
Added:
Modified:
clang/lib/StaticAnalyzer/Core/Store.cpp
clang/test/Analysis/uninit-val-const-likeness.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp
index 20660d1c2d67..b33129c88cea 100644
--- a/clang/lib/StaticAnalyzer/Core/Store.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -394,8 +394,8 @@ SVal StoreManager::attemptDownCast(SVal Base, QualType TargetType,
}
static bool hasSameUnqualifiedPointeeType(QualType ty1, QualType ty2) {
- return ty1->getPointeeType().getTypePtr() ==
- ty2->getPointeeType().getTypePtr();
+ return ty1->getPointeeType().getCanonicalType().getTypePtr() ==
+ ty2->getPointeeType().getCanonicalType().getTypePtr();
}
/// CastRetrievedVal - Used by subclasses of StoreManager to implement
@@ -427,7 +427,7 @@ SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
// correctly every time we need it.
if (castTy->isPointerType() && !castTy->isVoidPointerType())
if (const auto *SR = dyn_cast_or_null<SymbolicRegion>(V.getAsRegion())) {
- QualType sr = SR->getSymbol()->getType();
+ QualType sr = SR->getSymbol()->getType();
if (!hasSameUnqualifiedPointeeType(sr, castTy))
return loc::MemRegionVal(castRegion(SR, castTy));
}
diff --git a/clang/test/Analysis/uninit-val-const-likeness.c b/clang/test/Analysis/uninit-val-const-likeness.c
index 1ee1aefe8dba..013ab7882755 100644
--- a/clang/test/Analysis/uninit-val-const-likeness.c
+++ b/clang/test/Analysis/uninit-val-const-likeness.c
@@ -54,3 +54,21 @@ int work3(const Params * const params) {
sum += fooList[i]; // no-warning
return sum;
}
+
+typedef Params ParamsTypedef;
+typedef const ParamsTypedef *ConstParamsTypedef;
+
+static void create4(ConstParamsTypedef const params, int fooList[]) {
+ int tmpList[SIZE] = {0};
+ for (int i = 0; i < params->noOfSymbols; i++)
+ fooList[i] = tmpList[i];
+}
+
+int work4(Params * const params) {
+ int fooList[SIZE];
+ create4(params, fooList);
+ int sum = 0;
+ for (int i = 0; i < params->noOfSymbols; i++)
+ sum += fooList[i]; // no-warning
+ return sum;
+}
More information about the cfe-commits
mailing list