Index: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp +++ lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp @@ -61,7 +61,7 @@ SmallString<256> sbuf; llvm::raw_svector_ostream OS(sbuf); const Expr *Ex = nullptr; - bool isLeft = true; + bool isLeft; if (state->getSVal(B->getLHS(), LCtx).isUndef()) { Ex = B->getLHS()->IgnoreParenCasts(); @@ -73,6 +73,24 @@ } if (Ex) { + if (isa(Ex)) { + SVal Loc = state->getSVal(Ex,LCtx); + if (Loc.isValid()) { + const MemRegion *MR = Loc.castAs().getRegion(); + if (const ElementRegion *ER = dyn_cast(MR)) { + DefinedOrUnknownSVal Idx = ER->getIndex().castAs(); + DefinedOrUnknownSVal NumElements + = C.getStoreManager().getSizeInElements(state, ER->getSuperRegion(), + ER->getValueType()); + ProgramStateRef StInBound = state->assumeInBound(Idx, NumElements, true); + ProgramStateRef StOutBound = state->assumeInBound(Idx, NumElements, false); + if (StOutBound && !StInBound) { + return; + } + } + } + } + OS << "The " << (isLeft ? "left" : "right") << " operand of '" << BinaryOperator::getOpcodeStr(B->getOpcode())