@@ -233,12 +233,20 @@ static void findPtrToConstParams(llvm::SmallSet<unsigned, 4> &PreserveArgs,
233233
234234ProgramStateRef CallEvent::invalidateRegions (unsigned BlockCount,
235235 ProgramStateRef Orig) const {
236+ const FunctionSummary *Summary = nullptr ;
236237 ProgramStateRef Result = (Orig ? Orig : getState ());
237238
238- // Don't invalidate anything if the callee is marked pure/const.
239- if (const Decl *callee = getDecl ())
239+ if (const Decl *callee = getDecl ()) {
240+ const SummaryContext *SummaryCtx =
241+ State->getStateManager ().getOwningEngine ().getSummaryCtx ();
242+ const FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(callee);
243+ if (SummaryCtx && FD)
244+ Summary = SummaryCtx->GetSummary (FD);
245+
246+ // Don't invalidate anything if the callee is marked pure/const.
240247 if (callee->hasAttr <PureAttr>() || callee->hasAttr <ConstAttr>())
241248 return Result;
249+ }
242250
243251 SmallVector<SVal, 8 > ValuesToInvalidate;
244252 RegionAndSymbolInvalidationTraits ETraits;
@@ -251,6 +259,9 @@ ProgramStateRef CallEvent::invalidateRegions(unsigned BlockCount,
251259 findPtrToConstParams (PreserveArgs, *this );
252260
253261 for (unsigned Idx = 0 , Count = getNumArgs (); Idx != Count; ++Idx) {
262+ if (Summary && Summary->hasAttribute <NoWritePtrParameterAttr>())
263+ continue ;
264+
254265 // Mark this region for invalidation. We batch invalidate regions
255266 // below for efficiency.
256267 if (PreserveArgs.count (Idx))
@@ -277,15 +288,7 @@ ProgramStateRef CallEvent::invalidateRegions(unsigned BlockCount,
277288 ValuesToInvalidate.push_back (loc::MemRegionVal (TVR));
278289 }
279290
280- bool ShouldPreserveGlobals = false ;
281- const SummaryContext *SummaryCtx =
282- State->getStateManager ().getOwningEngine ().getSummaryCtx ();
283- const FunctionDecl *FD = llvm::dyn_cast_or_null<FunctionDecl>(getDecl ());
284- if (SummaryCtx && FD) {
285- const auto *Summary = SummaryCtx->GetSummary (FD);
286- ShouldPreserveGlobals =
287- Summary && Summary->hasAttribute <NoWriteGlobalAttr>();
288- }
291+ bool ShouldPreserveGlobals = Summary && Summary->hasAttribute <NoWriteGlobalAttr>();
289292
290293 // Invalidate designated regions using the batch invalidation API.
291294 // NOTE: Even if RegionsToInvalidate is empty, we may still invalidate
0 commit comments