Skip to content

Commit f0ced2d

Browse files
committed
[analysis] Re-discard type sugar when casting values retrieved from the Store.
Canonicalization was accidentally omitted in 6d3f43e.
1 parent 89a2bef commit f0ced2d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

clang/lib/StaticAnalyzer/Core/Store.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ SVal StoreManager::attemptDownCast(SVal Base, QualType TargetType,
394394
}
395395

396396
static bool hasSameUnqualifiedPointeeType(QualType ty1, QualType ty2) {
397-
return ty1->getPointeeType().getTypePtr() ==
398-
ty2->getPointeeType().getTypePtr();
397+
return ty1->getPointeeType().getCanonicalType().getTypePtr() ==
398+
ty2->getPointeeType().getCanonicalType().getTypePtr();
399399
}
400400

401401
/// CastRetrievedVal - Used by subclasses of StoreManager to implement
@@ -427,7 +427,7 @@ SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
427427
// correctly every time we need it.
428428
if (castTy->isPointerType() && !castTy->isVoidPointerType())
429429
if (const auto *SR = dyn_cast_or_null<SymbolicRegion>(V.getAsRegion())) {
430-
QualType sr = SR->getSymbol()->getType();
430+
QualType sr = SR->getSymbol()->getType();
431431
if (!hasSameUnqualifiedPointeeType(sr, castTy))
432432
return loc::MemRegionVal(castRegion(SR, castTy));
433433
}

clang/test/Analysis/uninit-val-const-likeness.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,21 @@ int work3(const Params * const params) {
5454
sum += fooList[i]; // no-warning
5555
return sum;
5656
}
57+
58+
typedef Params ParamsTypedef;
59+
typedef const ParamsTypedef *ConstParamsTypedef;
60+
61+
static void create4(ConstParamsTypedef const params, int fooList[]) {
62+
int tmpList[SIZE] = {0};
63+
for (int i = 0; i < params->noOfSymbols; i++)
64+
fooList[i] = tmpList[i];
65+
}
66+
67+
int work4(Params * const params) {
68+
int fooList[SIZE];
69+
create4(params, fooList);
70+
int sum = 0;
71+
for (int i = 0; i < params->noOfSymbols; i++)
72+
sum += fooList[i]; // no-warning
73+
return sum;
74+
}

0 commit comments

Comments
 (0)