@@ -277,51 +277,60 @@ static bool hasAssertInFunctionCallGraph(llvm::Function *Func) {
277
277
// true - if there is an assertion in underlying functions,
278
278
// false - if there are definetely no assertions in underlying functions.
279
279
static std::map<llvm::Function *, bool > hasAssertionInCallGraphMap;
280
- std::vector<llvm::Function *> FuncList ;
280
+ std::vector<llvm::Function *> FuncCallStack ;
281
281
282
- std::vector<llvm::Function *> Workqueue ;
283
- Workqueue .push_back (Func);
282
+ std::vector<llvm::Function *> Workstack ;
283
+ Workstack .push_back (Func);
284
284
285
- while (!Workqueue .empty ()) {
286
- Function *F = Workqueue .back ();
287
- Workqueue .pop_back ();
285
+ while (!Workstack .empty ()) {
286
+ Function *F = Workstack .back ();
287
+ Workstack .pop_back ();
288
288
if (F != Func)
289
- FuncList .push_back (F);
289
+ FuncCallStack .push_back (F);
290
290
291
- bool IsVertex = true ;
291
+ bool IsLeaf = true ;
292
292
for (auto &I : instructions (F)) {
293
- if (CallBase *CB = dyn_cast<CallBase>(&I))
294
- if (Function *CF = CB->getCalledFunction ()) {
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
- }
293
+ if (!isa<CallBase>(&I))
294
+ continue ;
295
+
296
+ Function *CF = cast<CallBase>(&I)->getCalledFunction ();
297
+ if (!CF)
298
+ continue ;
299
+
300
+ // Return if we've already discovered if there are asserts in the
301
+ // function call graph.
302
+ if (hasAssertionInCallGraphMap.count (CF)) {
303
+ // If we know, that this function does not contain assert, we still
304
+ // should investigate another instructions in the function.
305
+ if (!hasAssertionInCallGraphMap[CF])
306
+ continue ;
307
+
308
+ return true ;
309
+ }
300
310
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 ;
311
+ if (CF->getName ().startswith (" __devicelib_assert_fail" )) {
312
+ // Mark all the functions above in call graph as ones that can call
313
+ // assert.
314
+ for (auto *It : FuncCallStack )
315
+ hasAssertionInCallGraphMap[It] = true ;
306
316
307
- hasAssertionInCallGraphMap[Func] = true ;
308
- hasAssertionInCallGraphMap[CF] = true ;
317
+ hasAssertionInCallGraphMap[Func] = true ;
318
+ hasAssertionInCallGraphMap[CF] = true ;
309
319
310
- return true ;
311
- }
320
+ return true ;
321
+ }
312
322
313
- if (!CF->isDeclaration ()) {
314
- Workqueue.push_back (CF);
315
- IsVertex = false ;
316
- }
317
- }
323
+ if (!CF->isDeclaration ()) {
324
+ Workstack.push_back (CF);
325
+ IsLeaf = false ;
326
+ }
318
327
}
319
328
320
- if (IsVertex ) {
329
+ if (IsLeaf ) {
321
330
// Mark the above functions as ones that definetely do not call assert.
322
- for (auto *It : FuncList )
331
+ for (auto *It : FuncCallStack )
323
332
hasAssertionInCallGraphMap[It] = false ;
324
- FuncList .clear ();
333
+ FuncCallStack .clear ();
325
334
}
326
335
}
327
336
return false ;
0 commit comments