Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp =================================================================== --- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -911,8 +911,9 @@ elementType = elemReg->getElementType(); } else if (isa(region)) { + assert(op == BO_Add || op == BO_Sub); + index = (op == BO_Add) ? rhs : evalMinus(rhs); superR = region; - index = rhs; if (resultTy->isAnyPointerType()) elementType = resultTy->getPointeeType(); } Index: test/Analysis/ptr-arith.c =================================================================== --- test/Analysis/ptr-arith.c +++ test/Analysis/ptr-arith.c @@ -296,3 +296,16 @@ clang_analyzer_eval(&points[i].x < &points[i].y);// expected-warning{{TRUE}} } +void negativeIndex(char *str) { + char *ptr = str + 1; + *ptr = 'a'; + ptr = str - 1; + clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}} + ptr = str; + ptr -= 1; + clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}} + ptr = str; + --ptr; + clang_analyzer_eval(*ptr); // expected-warning{{UNKNOWN}} +} +