[analyzer] Replace isIntegerType() with isIntegerOrEnumerationType().
Previously, the analyzer used isIntegerType() everywhere, which uses the C definition of "integer". The C++ predicate with the same behavior is isIntegerOrUnscopedEnumerationType(). However, the analyzer is /really/ using this to ask if it's some sort of "integrally representable" type, i.e. it should include C++11 scoped enumerations as well. hasIntegerRepresentation() sounds like the right predicate, but that includes vectors, which the analyzer represents by its elements. This commit audits all uses of isIntegerType() and replaces them with the general isIntegerOrEnumerationType(), except in some specific cases where it makes sense to exclude scoped enumerations, or any enumerations. These cases now use isIntegerOrUnscopedEnumerationType() and getAs<BuiltinType>() plus BuiltinType::isInteger(). isIntegerType() is hereby banned in the analyzer - lib/StaticAnalysis and include/clang/StaticAnalysis. :-) Fixes real assertion failures. PR15703 / <rdar://problem/12350701> llvm-svn: 179081
This commit is contained in:
@@ -106,7 +106,8 @@ ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) {
|
||||
|
||||
const ParmVarDecl *PD = FD->getParamDecl(0);
|
||||
QualType T = PD->getType();
|
||||
if (!T->isIntegerType())
|
||||
const BuiltinType *BT = dyn_cast<BuiltinType>(T);
|
||||
if (!BT || !BT->isInteger())
|
||||
break;
|
||||
|
||||
const MemRegion *R = state->getRegion(PD, InitLoc);
|
||||
@@ -1235,7 +1236,7 @@ static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr,
|
||||
while (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) {
|
||||
QualType T = CE->getType();
|
||||
|
||||
if (!T->isIntegerType())
|
||||
if (!T->isIntegralOrEnumerationType())
|
||||
return UnknownVal();
|
||||
|
||||
uint64_t newBits = Ctx.getTypeSize(T);
|
||||
@@ -1250,7 +1251,8 @@ static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr,
|
||||
// We reached a non-cast. Is it a symbolic value?
|
||||
QualType T = Ex->getType();
|
||||
|
||||
if (!bitsInit || !T->isIntegerType() || Ctx.getTypeSize(T) > bits)
|
||||
if (!bitsInit || !T->isIntegralOrEnumerationType() ||
|
||||
Ctx.getTypeSize(T) > bits)
|
||||
return UnknownVal();
|
||||
|
||||
return state->getSVal(Ex, LCtx);
|
||||
@@ -1342,7 +1344,7 @@ void ExprEngine::processBranch(const Stmt *Condition, const Stmt *Term,
|
||||
if (X.isUnknownOrUndef()) {
|
||||
// Give it a chance to recover from unknown.
|
||||
if (const Expr *Ex = dyn_cast<Expr>(Condition)) {
|
||||
if (Ex->getType()->isIntegerType()) {
|
||||
if (Ex->getType()->isIntegralOrEnumerationType()) {
|
||||
// Try to recover some path-sensitivity. Right now casts of symbolic
|
||||
// integers that promote their values are currently not tracked well.
|
||||
// If 'Condition' is such an expression, try and recover the
|
||||
|
||||
Reference in New Issue
Block a user