8000 Static analyzer cherrypicks 7 by haoNoQ · Pull Request #512 · swiftlang/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

Static analyzer cherrypicks 7 #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for Gi 8000 tHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[analysis] Re-discard type sugar when casting values retrieved from t…
…he Store.

Canonicalization was accidentally omitted in 6d3f43e.

(cherry picked from commit f0ced2d)
  • Loading branch information
haoNoQ committed Dec 20, 2019
commit 89dda46e584435287f583a46146131a8e7d44969
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/Store.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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