@@ -113,13 +113,6 @@ cl::opt<bool> ClCoverReplaceableNew("alloc-token-cover-replaceable-new",
113113 cl::desc (" Cover replaceable operator new" ),
114114 cl::Hidden, cl::init(true ));
115115
116- // strdup-family functions only operate on strings, covering them does not make
117- // sense in most cases.
118- cl::opt<bool >
119- ClCoverStrdup (" alloc-token-cover-strdup" ,
120- cl::desc (" Cover strdup-family allocation functions" ),
121- cl::Hidden, cl::init(false ));
122-
123116cl::opt<uint64_t > ClFallbackToken (
124117 " alloc-token-fallback" ,
125118 cl::desc (" The default fallback token where none could be determined" ),
@@ -128,7 +121,7 @@ cl::opt<uint64_t> ClFallbackToken(
128121// ===--- Statistics -------------------------------------------------------===//
129122
130123STATISTIC (NumFunctionsInstrumented, " Functions instrumented" );
131- STATISTIC (NumAllocations , " Allocations found " );
124+ STATISTIC (NumAllocationsInstrumented , " Allocations instrumented " );
132125
133126// ===----------------------------------------------------------------------===//
134127
@@ -194,12 +187,13 @@ class TypeHashMode : public ModeBase {
194187 MDString *S = cast<MDString>(N->getOperand (0 ));
195188 return boundedToken (xxHash64 (S->getString ()));
196189 }
197- remarkNoHint (CB, ORE);
190+ remarkNoMetadata (CB, ORE);
198191 return ClFallbackToken;
199192 }
200193
201194 // / Remark that there was no precise type information.
202- void remarkNoHint (const CallBase &CB, OptimizationRemarkEmitter &ORE) {
195+ static void remarkNoMetadata (const CallBase &CB,
196+ OptimizationRemarkEmitter &ORE) {
203197 ORE.emit ([&] {
204198 ore::NV FuncNV (" Function" , CB.getParent ()->getParent ());
205199 const Function *Callee = CB.getCalledFunction ();
@@ -212,12 +206,12 @@ class TypeHashMode : public ModeBase {
212206};
213207
214208// Apply opt overrides.
215- AllocTokenOptions && transformOptionsFromCl(AllocTokenOptions && Opts) {
209+ AllocTokenOptions transformOptionsFromCl (AllocTokenOptions Opts) {
216210 if (!Opts.MaxTokens .has_value ())
217211 Opts.MaxTokens = ClMaxTokens;
218212 Opts.FastABI |= ClFastABI;
219213 Opts.Extended |= ClExtended;
220- return std::move ( Opts) ;
214+ return Opts;
221215}
222216
223217class AllocToken {
@@ -252,7 +246,7 @@ class AllocToken {
252246
253247 // / Replace a call/invoke with a call/invoke to the allocation function
254248 // / with token ID.
255- void replaceAllocationCall (CallBase *CB, LibFunc Func,
249+ bool replaceAllocationCall (CallBase *CB, LibFunc Func,
256250 OptimizationRemarkEmitter &ORE,
257251 const TargetLibraryInfo &TLI);
258252
@@ -314,15 +308,13 @@ bool AllocToken::instrumentFunction(Function &F) {
314308 }
315309 }
316310
317- if (AllocCalls.empty ())
318- return false ;
319-
311+ bool Modified = false ;
320312 for (auto &[CB, Func] : AllocCalls)
321- replaceAllocationCall (CB, Func, ORE, TLI);
322- NumAllocations += AllocCalls.size ();
323- NumFunctionsInstrumented++;
313+ Modified |= replaceAllocationCall (CB, Func, ORE, TLI);
324314
325- return true ;
315+ if (Modified)
316+ NumFunctionsInstrumented++;
317+ return Modified;
326318}
327319
328320bool AllocToken::isInstrumentableLibFunc (LibFunc Func, const Value *V,
@@ -373,24 +365,26 @@ bool AllocToken::ignoreInstrumentableLibFunc(LibFunc Func) {
373365 case LibFunc_dunder_strdup:
374366 case LibFunc_strndup:
375367 case LibFunc_dunder_strndup:
376- return !ClCoverStrdup ;
368+ return true ;
377369 default :
378370 return false ;
379371 }
380372}
381373
382- void AllocToken::replaceAllocationCall (CallBase *CB, LibFunc Func,
374+ bool AllocToken::replaceAllocationCall (CallBase *CB, LibFunc Func,
383375 OptimizationRemarkEmitter &ORE,
384376 const TargetLibraryInfo &TLI) {
385377 uint64_t TokenID = getToken (*CB, ORE);
386378
387379 FunctionCallee TokenAlloc = getTokenAllocFunction (*CB, TokenID, Func);
388380 if (!TokenAlloc)
389- return ;
381+ return false ;
382+ NumAllocationsInstrumented++;
383+
390384 if (Options.FastABI ) {
391385 assert (TokenAlloc.getFunctionType ()->getNumParams () == CB->arg_size ());
392386 CB->setCalledFunction (TokenAlloc);
393- return ;
387+ return true ;
394388 }
395389
396390 IRBuilder<> IRB (CB);
@@ -416,6 +410,7 @@ void AllocToken::replaceAllocationCall(CallBase *CB, LibFunc Func,
416410 // Replace all uses and delete the old call.
417411 CB->replaceAllUsesWith (NewCall);
418412 CB->eraseFromParent ();
413+ return true ;
419414}
420415
421416FunctionCallee AllocToken::getTokenAllocFunction (const CallBase &CB,
0 commit comments