зеркало из https://github.com/microsoft/clang-1.git
[analyzer] Teach UndefOrNullArgVisitor to track parent regions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163748 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
1a7bcc41ef
Коммит
522fc21f3a
|
@ -140,6 +140,9 @@ public:
|
|||
|
||||
const MemRegion *getBaseRegion() const;
|
||||
|
||||
/// Check if the region is a subregion of the given region.
|
||||
bool isSubRegionOf(const MemRegion *PR) const;
|
||||
|
||||
const MemRegion *StripCasts(bool StripBaseCasts = true) const;
|
||||
|
||||
bool hasGlobalsOrParametersStorage() const;
|
||||
|
|
|
@ -517,6 +517,8 @@ void bugreporter::trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S,
|
|||
// However, if the rvalue is a symbolic region, we should track it as well.
|
||||
SVal RVal = state->getSVal(L->getRegion());
|
||||
const MemRegion *RegionRVal = RVal.getAsRegion();
|
||||
report.addVisitor(new UndefOrNullArgVisitor(L->getRegion()));
|
||||
|
||||
|
||||
if (RegionRVal && isa<SymbolicRegion>(RegionRVal)) {
|
||||
report.markInteresting(RegionRVal);
|
||||
|
@ -985,8 +987,8 @@ UndefOrNullArgVisitor::VisitNode(const ExplodedNode *N,
|
|||
E = Call->param_end(); I != E; ++I, ++Idx) {
|
||||
const MemRegion *ArgReg = Call->getArgSVal(Idx).getAsRegion();
|
||||
|
||||
// Are we tracking the argument?
|
||||
if ( !ArgReg || ArgReg != R)
|
||||
// Are we tracking the argument or its subregion?
|
||||
if ( !ArgReg || (ArgReg != R && !R->isSubRegionOf(ArgReg->StripCasts())))
|
||||
continue;
|
||||
|
||||
// Check the function parameter type.
|
||||
|
@ -1006,7 +1008,7 @@ UndefOrNullArgVisitor::VisitNode(const ExplodedNode *N,
|
|||
|
||||
// Mark the call site (LocationContext) as interesting if the value of the
|
||||
// argument is undefined or '0'/'NULL'.
|
||||
SVal BoundVal = State->getSVal(ArgReg);
|
||||
SVal BoundVal = State->getSVal(R);
|
||||
if (BoundVal.isUndef() || BoundVal.isZeroConstant()) {
|
||||
BR.markInteresting(CEnter->getCalleeContext());
|
||||
return 0;
|
||||
|
|
|
@ -990,6 +990,26 @@ const MemRegion *MemRegion::getBaseRegion() const {
|
|||
return R;
|
||||
}
|
||||
|
||||
bool MemRegion::isSubRegionOf(const MemRegion *PR) const {
|
||||
const MemRegion *R = this;
|
||||
while (true) {
|
||||
switch (R->getKind()) {
|
||||
case MemRegion::ElementRegionKind:
|
||||
case MemRegion::FieldRegionKind:
|
||||
case MemRegion::ObjCIvarRegionKind:
|
||||
case MemRegion::CXXBaseObjectRegionKind:
|
||||
R = cast<SubRegion>(R)->getSuperRegion();
|
||||
if (R == PR)
|
||||
return true;
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// View handling.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче