@@ -273,21 +273,56 @@ static void collectKernelModuleMap(
273
273
274
274
// Go through function call graph searching for assert call.
275
275
static bool hasAssertInFunctionCallGraph (llvm::Function *Func) {
276
+ // Map holds the info about assertions in already examined functions:
277
+ // true - if there is an assertion in underlying functions,
278
+ // false - if there are definetely no assertions in underlying functions.
279
+ static std::map<llvm::Function *, bool > hasAssertionInCallGraphMap;
280
+ std::vector<llvm::Function *> FuncList;
281
+
276
282
std::vector<llvm::Function *> Workqueue;
277
283
Workqueue.push_back (Func);
278
284
279
285
while (!Workqueue.empty ()) {
280
286
Function *F = Workqueue.back ();
281
287
Workqueue.pop_back ();
288
+ if (F != Func)
289
+ FuncList.push_back (F);
290
+
291
+ bool IsVertex = true ;
282
292
for (auto &I : instructions (F)) {
283
293
if (CallBase *CB = dyn_cast<CallBase>(&I))
284
294
if (Function *CF = CB->getCalledFunction ()) {
285
- if (CF->getName ().startswith (" __devicelib_assert_fail" ))
295
+ // Return if we've already discovered if there are asserts in the
296
+ // function call graph.
297
+ if (hasAssertionInCallGraphMap.count (CF)) {
298
+ return hasAssertionInCallGraphMap[CF];
299
+ }
300
+
301
+ if (CF->getName ().startswith (" __devicelib_assert_fail" )) {
302
+ // Mark all the functions above in call graph as ones that can call
303
+ // assert.
304
+ for (auto *It : FuncList)
305
+ hasAssertionInCallGraphMap[It] = true ;
306
+
307
+ hasAssertionInCallGraphMap[Func] = true ;
308
+ hasAssertionInCallGraphMap[CF] = true ;
309
+
286
310
return true ;
287
- if (!CF->isDeclaration ())
311
+ }
312
+
313
+ if (!CF->isDeclaration ()) {
288
314
Workqueue.push_back (CF);
315
+ IsVertex = false ;
316
+ }
289
317
}
290
318
}
319
+
320
+ if (IsVertex) {
321
+ // Mark the above functions as ones that definetely do not call assert.
322
+ for (auto *It : FuncList)
323
+ hasAssertionInCallGraphMap[It] = false ;
324
+ FuncList.clear ();
325
+ }
291
326
}
292
327
return false ;
293
328
}
0 commit comments