diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-08-25 22:55:09 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-08-25 22:55:09 +0000 |
commit | d1d6066be8c4e84c6a5c52ac371306fc25d8f043 (patch) | |
tree | 992f3a03584d4c97c0ae5d8ae09e349a4899fbf6 | |
parent | 24ebdae1e1470cfaef2c25377561002ad28181c0 (diff) | |
download | bcm5719-llvm-d1d6066be8c4e84c6a5c52ac371306fc25d8f043.tar.gz bcm5719-llvm-d1d6066be8c4e84c6a5c52ac371306fc25d8f043.zip |
Handle pointer arithmetic in RegionStoreManager involving Objective-C pointers
when using the non-fragile Objective-C ABI. This fixes <rdar://problem/7168531>.
llvm-svn: 80047
-rw-r--r-- | clang/lib/Analysis/RegionStore.cpp | 10 | ||||
-rw-r--r-- | clang/test/Analysis/rdar-7168531.m | 19 |
2 files changed, 27 insertions, 2 deletions
diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index 9225bfbaae7..4c8610734e5 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/lib/Analysis/RegionStore.cpp @@ -750,8 +750,14 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, case MemRegion::SymbolicRegionKind: { const SymbolicRegion *SR = cast<SymbolicRegion>(MR); SymbolRef Sym = SR->getSymbol(); - QualType T = Sym->getType(getContext()); - QualType EleTy = T->getAs<PointerType>()->getPointeeType(); + QualType T = Sym->getType(getContext()); + QualType EleTy; + + if (const PointerType *PT = T->getAs<PointerType>()) + EleTy = PT->getPointeeType(); + else + EleTy = T->getAsObjCObjectPointerType()->getPointeeType(); + SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR, getContext()); break; diff --git a/clang/test/Analysis/rdar-7168531.m b/clang/test/Analysis/rdar-7168531.m new file mode 100644 index 00000000000..bdbd22d24e2 --- /dev/null +++ b/clang/test/Analysis/rdar-7168531.m @@ -0,0 +1,19 @@ +// RUN: clang-cc -analyze -checker-cfref -triple i386-apple-darwin10 -analyzer-store=region && +// RUN: clang-cc -analyze -checker-cfref -triple i386-apple-darwin10 -analyzer-store=basic + +// Note that the target triple is important for this test case. It specifies that we use the +// fragile Objective-C ABI. + +@interface Foo { + int x; +} +@end + +@implementation Foo +static Foo* bar(Foo *p) { + if (p->x) + return ++p; // This is only valid for the fragile ABI. + + return p; +} +@end |