From: Zhongxing Xu Date: Sun, 21 Jun 2009 13:24:24 +0000 (+0000) Subject: Return UnknownVal for pointer arithmetic on struct fields. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5414a5c0add7a7a9343a1be0bda962ce8dc35449;p=clang Return UnknownVal for pointer arithmetic on struct fields. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73851 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 6f316c9c59..5f2b8f809d 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -773,8 +773,13 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); ER = MRMgr.getElementRegion(EleTy, ZeroIdx, AR, getContext()); } - else + else if (isa(MR)) { + // Not track pointer arithmetic on struct fields. + return UnknownVal(); + } + else { ER = cast(MR); + } SVal Idx = ER->getIndex(); diff --git a/test/Analysis/fields.c b/test/Analysis/fields.c index c012a9da7b..900a6d6869 100644 --- a/test/Analysis/fields.c +++ b/test/Analysis/fields.c @@ -8,3 +8,12 @@ void bar() { *(unsigned*)&y = foo(); y.x = 1; } + +struct s { + int n; +}; + +void f() { + struct s a; + int *p = &(a.n) + 1; +}