@@ -486,9 +486,11 @@ void SplitGraph::Node::visitAllDependencies(
486
486
// / in \p Callees.
487
487
// /
488
488
// / \returns true if there was metadata and it was parsed correctly. false if
489
- // / there was no MD or if it contained unknown entries.
489
+ // / there was no MD or if it contained unknown entries and parsing failed.
490
+ // / If this returns false, \p Callees will contain incomplete information
491
+ // / and must not be used.
490
492
static bool handleCalleesMD (const Instruction &I,
491
- SmallVectorImpl <Function *> &Callees) {
493
+ SetVector <Function *> &Callees) {
492
494
auto *MD = I.getMetadata (LLVMContext::MD_callees);
493
495
if (!MD)
494
496
return false ;
@@ -497,7 +499,7 @@ static bool handleCalleesMD(const Instruction &I,
497
499
Function *Callee = mdconst::extract_or_null<Function>(Op);
498
500
if (!Callee)
499
501
return false ;
500
- Callees.push_back (Callee);
502
+ Callees.insert (Callee);
501
503
}
502
504
503
505
return true ;
@@ -540,7 +542,7 @@ void SplitGraph::buildGraph(CallGraph &CG) {
540
542
Fn.printAsOperand (dbgs ());
541
543
dbgs () << " - analyzing function\n " );
542
544
543
- SmallVector <Function *> KnownCallees;
545
+ SetVector <Function *> KnownCallees;
544
546
bool HasUnknownIndirectCall = false ;
545
547
for (const auto &Inst : instructions (Fn)) {
546
548
// look at all calls without a direct callee.
@@ -559,6 +561,9 @@ void SplitGraph::buildGraph(CallGraph &CG) {
559
561
560
562
if (handleCalleesMD (Inst, KnownCallees))
561
563
continue ;
564
+ // If we failed to parse any !callees MD, or some was missing,
565
+ // the entire KnownCallees list is now unreliable.
566
+ KnownCallees.clear ();
562
567
563
568
// Everything else is handled conservatively. If we fall into the
564
569
// conservative case don't bother analyzing further.
0 commit comments