@@ -345,13 +345,6 @@ void Lint::visitCallSite(CallSite CS) {
345
345
visitMemoryReference (I, CS.getArgument (0 ), MemoryLocation::UnknownSize, 0 ,
346
346
nullptr , MemRef::Read | MemRef::Write);
347
347
break ;
348
-
349
- case Intrinsic::eh_begincatch:
350
- visitEHBeginCatch (II);
351
- break ;
352
- case Intrinsic::eh_endcatch:
353
- visitEHEndCatch (II);
354
- break ;
355
348
}
356
349
}
357
350
@@ -511,187 +504,6 @@ void Lint::visitShl(BinaryOperator &I) {
511
504
" Undefined result: Shift count out of range" , &I);
512
505
}
513
506
514
- static bool
515
- allPredsCameFromLandingPad (BasicBlock *BB,
516
- SmallSet<BasicBlock *, 4 > &VisitedBlocks) {
517
- VisitedBlocks.insert (BB);
518
- if (BB->isLandingPad ())
519
- return true ;
520
- // If we find a block with no predecessors, the search failed.
521
- if (pred_empty (BB))
522
- return false ;
523
- for (BasicBlock *Pred : predecessors (BB)) {
524
- if (VisitedBlocks.count (Pred))
525
- continue ;
526
- if (!allPredsCameFromLandingPad (Pred, VisitedBlocks))
527
- return false ;
528
- }
529
- return true ;
530
- }
531
-
532
- static bool
533
- allSuccessorsReachEndCatch (BasicBlock *BB, BasicBlock::iterator InstBegin,
534
- IntrinsicInst **SecondBeginCatch,
535
- SmallSet<BasicBlock *, 4 > &VisitedBlocks) {
536
- VisitedBlocks.insert (BB);
537
- for (BasicBlock::iterator I = InstBegin, E = BB->end (); I != E; ++I) {
538
- IntrinsicInst *IC = dyn_cast<IntrinsicInst>(I);
539
- if (IC && IC->getIntrinsicID () == Intrinsic::eh_endcatch)
540
- return true ;
541
- // If we find another begincatch while looking for an endcatch,
542
- // that's also an error.
543
- if (IC && IC->getIntrinsicID () == Intrinsic::eh_begincatch) {
544
- *SecondBeginCatch = IC;
545
- return false ;
546
- }
547
- }
548
-
549
- // If we reach a block with no successors while searching, the
550
- // search has failed.
551
- if (succ_empty (BB))
552
- return false ;
553
- // Otherwise, search all of the successors.
554
- for (BasicBlock *Succ : successors (BB)) {
555
- if (VisitedBlocks.count (Succ))
556
- continue ;
557
- if (!allSuccessorsReachEndCatch (Succ, Succ->begin (), SecondBeginCatch,
558
- VisitedBlocks))
559
- return false ;
560
- }
561
- return true ;
562
- }
563
-
564
- void Lint::visitEHBeginCatch (IntrinsicInst *II) {
565
- // The checks in this function make a potentially dubious assumption about
566
- // the CFG, namely that any block involved in a catch is only used for the
567
- // catch. This will very likely be true of IR generated by a front end,
568
- // but it may cease to be true, for example, if the IR is run through a
569
- // pass which combines similar blocks.
570
- //
571
- // In general, if we encounter a block the isn't dominated by the catch
572
- // block while we are searching the catch block's successors for a call
573
- // to end catch intrinsic, then it is possible that it will be legal for
574
- // a path through this block to never reach a call to llvm.eh.endcatch.
575
- // An analogous statement could be made about our search for a landing
576
- // pad among the catch block's predecessors.
577
- //
578
- // What is actually required is that no path is possible at runtime that
579
- // reaches a call to llvm.eh.begincatch without having previously visited
580
- // a landingpad instruction and that no path is possible at runtime that
581
- // calls llvm.eh.begincatch and does not subsequently call llvm.eh.endcatch
582
- // (mentally adjusting for the fact that in reality these calls will be
583
- // removed before code generation).
584
- //
585
- // Because this is a lint check, we take a pessimistic approach and warn if
586
- // the control flow is potentially incorrect.
587
-
588
- SmallSet<BasicBlock *, 4 > VisitedBlocks;
589
- BasicBlock *CatchBB = II->getParent ();
590
-
591
- // The begin catch must occur in a landing pad block or all paths
592
- // to it must have come from a landing pad.
593
- Assert (allPredsCameFromLandingPad (CatchBB, VisitedBlocks),
594
- " llvm.eh.begincatch may be reachable without passing a landingpad" ,
595
- II);
596
-
597
- // Reset the visited block list.
598
- VisitedBlocks.clear ();
599
-
600
- IntrinsicInst *SecondBeginCatch = nullptr ;
601
-
602
- // This has to be called before it is asserted. Otherwise, the first assert
603
- // below can never be hit.
604
- bool EndCatchFound = allSuccessorsReachEndCatch (
605
- CatchBB, std::next (static_cast <BasicBlock::iterator>(II)),
606
- &SecondBeginCatch, VisitedBlocks);
607
- Assert (
608
- SecondBeginCatch == nullptr ,
609
- " llvm.eh.begincatch may be called a second time before llvm.eh.endcatch" ,
610
- II, SecondBeginCatch);
611
- Assert (EndCatchFound,
612
- " Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch" ,
613
- II);
614
- }
615
-
616
- static bool allPredCameFromBeginCatch (
617
- BasicBlock *BB, BasicBlock::reverse_iterator InstRbegin,
618
- IntrinsicInst **SecondEndCatch, SmallSet<BasicBlock *, 4 > &VisitedBlocks) {
619
- VisitedBlocks.insert (BB);
620
- // Look for a begincatch in this block.
621
- for (BasicBlock::reverse_iterator RI = InstRbegin, RE = BB->rend (); RI != RE;
622
- ++RI) {
623
- IntrinsicInst *IC = dyn_cast<IntrinsicInst>(&*RI);
624
- if (IC && IC->getIntrinsicID () == Intrinsic::eh_begincatch)
625
- return true ;
626
- // If we find another end catch before we find a begin catch, that's
627
- // an error.
628
- if (IC && IC->getIntrinsicID () == Intrinsic::eh_endcatch) {
629
- *SecondEndCatch = IC;
630
- return false ;
631
- }
632
- // If we encounter a landingpad instruction, the search failed.
633
- if (isa<LandingPadInst>(*RI))
634
- return false ;
635
- }
636
- // If while searching we find a block with no predeccesors,
637
- // the search failed.
638
- if (pred_empty (BB))
639
- return false ;
640
- // Search any predecessors we haven't seen before.
641
- for (BasicBlock *Pred : predecessors (BB)) {
642
- if (VisitedBlocks.count (Pred))
643
- continue ;
644
- if (!allPredCameFromBeginCatch (Pred, Pred->rbegin (), SecondEndCatch,
645
- VisitedBlocks))
646
- return false ;
647
- }
648
- return true ;
649
- }
650
-
651
- void Lint::visitEHEndCatch (IntrinsicInst *II) {
652
- // The check in this function makes a potentially dubious assumption about
653
- // the CFG, namely that any block involved in a catch is only used for the
654
- // catch. This will very likely be true of IR generated by a front end,
655
- // but it may cease to be true, for example, if the IR is run through a
656
- // pass which combines similar blocks.
657
- //
658
- // In general, if we encounter a block the isn't post-dominated by the
659
- // end catch block while we are searching the end catch block's predecessors
660
- // for a call to the begin catch intrinsic, then it is possible that it will
661
- // be legal for a path to reach the end catch block without ever having
662
- // called llvm.eh.begincatch.
663
- //
664
- // What is actually required is that no path is possible at runtime that
665
- // reaches a call to llvm.eh.endcatch without having previously visited
666
- // a call to llvm.eh.begincatch (mentally adjusting for the fact that in
667
- // reality these calls will be removed before code generation).
668
- //
669
- // Because this is a lint check, we take a pessimistic approach and warn if
670
- // the control flow is potentially incorrect.
671
-
672
- BasicBlock *EndCatchBB = II->getParent ();
673
-
674
- // Alls paths to the end catch call must pass through a begin catch call.
675
-
676
- // If llvm.eh.begincatch wasn't called in the current block, we'll use this
677
- // lambda to recursively look for it in predecessors.
678
- SmallSet<BasicBlock *, 4 > VisitedBlocks;
679
- IntrinsicInst *SecondEndCatch = nullptr ;
680
-
681
- // This has to be called before it is asserted. Otherwise, the first assert
682
- // below can never be hit.
683
- bool BeginCatchFound =
684
- allPredCameFromBeginCatch (EndCatchBB, BasicBlock::reverse_iterator (II),
685
- &SecondEndCatch, VisitedBlocks);
686
- Assert (
687
- SecondEndCatch == nullptr ,
688
- " llvm.eh.endcatch may be called a second time after llvm.eh.begincatch" ,
689
- II, SecondEndCatch);
690
- Assert (BeginCatchFound,
691
- " llvm.eh.endcatch may be reachable without passing llvm.eh.begincatch" ,
692
- II);
693
- }
694
-
695
507
static bool isZero (Value *V, const DataLayout &DL, DominatorTree *DT,
696
508
AssumptionCache *AC) {
697
509
// Assume undef could be zero.
0 commit comments