]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't try to inline if there's no region for a message receiver.
authorJordan Rose <jordan_rose@apple.com>
Tue, 31 Jul 2012 18:04:53 +0000 (18:04 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 31 Jul 2012 18:04:53 +0000 (18:04 +0000)
While usually we'd use a symbolic region rather than a straight-up Unknown,
we can still generate unknowns via array subscripts with symbolic indexes.
(And if this ever changes in the future, we still shouldn't crash.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161059 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/inlining/InlineObjCInstanceMethod.m

index 3b9e1e1979a4f6a70bb26e06d3a88e58644b04bd..fb00a226a2102874a3635d64cf68c558fe17d494 100644 (file)
@@ -681,6 +681,9 @@ const Decl *ObjCMethodCall::getRuntimeDefinition() const {
       ReceiverT = cast<ObjCObjectPointerType>(SupersType.getTypePtr());
     } else {
       const MemRegion *Receiver = getReceiverSVal().getAsRegion();
+      if (!Receiver)
+        return 0;
+
       DynamicTypeInfo TI = getState()->getDynamicTypeInfo(Receiver);
       ReceiverT = dyn_cast<ObjCObjectPointerType>(TI.getType().getTypePtr());
     }
index 682d02aa1545e5ceccaee2c5061b6a15625c7acd..8d8f28d923fec9bf36a04bab03f3166a17161d04 100644 (file)
 - (int) method2 {
   return 5/_attribute; // expected-warning {{Division by zero}}
 }
-@end
\ No newline at end of file
+@end
+
+
+// Don't crash if we don't know the receiver's region.
+void randomlyMessageAnObject(MyClass *arr[], int i) {
+  (void)[arr[i] getInt];
+}
\ No newline at end of file