Skip to content

Commit

Permalink
[analysis] Re-discard type sugar when casting values retrieved from t…
Browse files Browse the repository at this point in the history
…he Store.

Canonicalization was accidentally omitted in 6d3f43e.
  • Loading branch information
haoNoQ committed Dec 19, 2019
1 parent 89a2bef commit f0ced2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/Store.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
Expand Down
18 changes: 18 additions & 0 deletions clang/test/Analysis/uninit-val-const-likeness.c
Expand Up @@ -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;
}

0 comments on commit f0ced2d

Please sign in to comment.