Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp =================================================================== --- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -364,6 +364,13 @@ rhs.castAs().getLoc(), resultTy); case nonloc::ConcreteIntKind: { + // Evaluate pointers treated as integers + // (for example, results of C-style casts (long)((void *)ptr)) + // in arithmetic expressions with integers. + if (!BinaryOperator::isComparisonOp(op)) + return makeSymExprValNN( + state, op, lhs.castAs(), + rhs.castAs(), resultTy); // Transform the integer into a location and compare. // FIXME: This only makes sense for comparisons. If we want to, say, // add 1 to a LocAsInteger, we'd better unpack the Loc and add to it, Index: test/Analysis/ptr-arith.cpp =================================================================== --- test/Analysis/ptr-arith.cpp +++ test/Analysis/ptr-arith.cpp @@ -105,3 +105,9 @@ return 0; return N; } + +// Bug 34309 +bool ptrAsIntegerSubtractionNoCrash(long x, char *p) { + long y = (long)p - 1; + return y == x; +}