diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index 6f316c9c5921..5f2b8f809de3 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/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/clang/test/Analysis/fields.c b/clang/test/Analysis/fields.c index c012a9da7b81..900a6d6869ac 100644 --- a/clang/test/Analysis/fields.c +++ b/clang/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; +}