Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Analysis/EHPersonalities.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- EHPersonalities.cpp - Compute EH-related information ---------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/Analysis/EHPersonalities.h"
10
#include "llvm/ADT/StringSwitch.h"
11
#include "llvm/IR/CFG.h"
12
#include "llvm/IR/Constants.h"
13
#include "llvm/IR/Function.h"
14
#include "llvm/IR/Instructions.h"
15
#include "llvm/Support/Debug.h"
16
#include "llvm/Support/raw_ostream.h"
17
using namespace llvm;
18
19
/// See if the given exception handling personality function is one that we
20
/// understand.  If so, return a description of it; otherwise return Unknown.
21
1.74M
EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
22
1.74M
  const Function *F =
23
1.74M
      Pers ? 
dyn_cast<Function>(Pers->stripPointerCasts())422k
:
nullptr1.31M
;
24
1.74M
  if (!F)
25
1.31M
    return EHPersonality::Unknown;
26
422k
  return StringSwitch<EHPersonality>(F->getName())
27
422k
    .Case("__gnat_eh_personality",     EHPersonality::GNU_Ada)
28
422k
    .Case("__gxx_personality_v0",      EHPersonality::GNU_CXX)
29
422k
    .Case("__gxx_personality_seh0",    EHPersonality::GNU_CXX)
30
422k
    .Case("__gxx_personality_sj0",     EHPersonality::GNU_CXX_SjLj)
31
422k
    .Case("__gcc_personality_v0",      EHPersonality::GNU_C)
32
422k
    .Case("__gcc_personality_seh0",    EHPersonality::GNU_C)
33
422k
    .Case("__gcc_personality_sj0",     EHPersonality::GNU_C_SjLj)
34
422k
    .Case("__objc_personality_v0",     EHPersonality::GNU_ObjC)
35
422k
    .Case("_except_handler3",          EHPersonality::MSVC_X86SEH)
36
422k
    .Case("_except_handler4",          EHPersonality::MSVC_X86SEH)
37
422k
    .Case("__C_specific_handler",      EHPersonality::MSVC_Win64SEH)
38
422k
    .Case("__CxxFrameHandler3",        EHPersonality::MSVC_CXX)
39
422k
    .Case("ProcessCLRException",       EHPersonality::CoreCLR)
40
422k
    .Case("rust_eh_personality",       EHPersonality::Rust)
41
422k
    .Case("__gxx_wasm_personality_v0", EHPersonality::Wasm_CXX)
42
422k
    .Default(EHPersonality::Unknown);
43
422k
}
44
45
5
StringRef llvm::getEHPersonalityName(EHPersonality Pers) {
46
5
  switch (Pers) {
47
5
  
case EHPersonality::GNU_Ada: return "__gnat_eh_personality"0
;
48
5
  
case EHPersonality::GNU_CXX: return "__gxx_personality_v0"0
;
49
5
  
case EHPersonality::GNU_CXX_SjLj: return "__gxx_personality_sj0"0
;
50
5
  case EHPersonality::GNU_C:         return "__gcc_personality_v0";
51
5
  
case EHPersonality::GNU_C_SjLj: return "__gcc_personality_sj0"0
;
52
5
  
case EHPersonality::GNU_ObjC: return "__objc_personality_v0"0
;
53
5
  
case EHPersonality::MSVC_X86SEH: return "_except_handler3"0
;
54
5
  
case EHPersonality::MSVC_Win64SEH: return "__C_specific_handler"0
;
55
5
  
case EHPersonality::MSVC_CXX: return "__CxxFrameHandler3"0
;
56
5
  
case EHPersonality::CoreCLR: return "ProcessCLRException"0
;
57
5
  
case EHPersonality::Rust: return "rust_eh_personality"0
;
58
5
  
case EHPersonality::Wasm_CXX: return "__gxx_wasm_personality_v0"0
;
59
5
  
case EHPersonality::Unknown: 0
llvm_unreachable0
("Unknown EHPersonality!");
60
0
  }
61
0
62
0
  llvm_unreachable("Invalid EHPersonality!");
63
0
}
64
65
5
EHPersonality llvm::getDefaultEHPersonality(const Triple &T) {
66
5
  return EHPersonality::GNU_C;
67
5
}
68
69
8.25k
bool llvm::canSimplifyInvokeNoUnwind(const Function *F) {
70
8.25k
  EHPersonality Personality = classifyEHPersonality(F->getPersonalityFn());
71
8.25k
  // We can't simplify any invokes to nounwind functions if the personality
72
8.25k
  // function wants to catch asynch exceptions.  The nounwind attribute only
73
8.25k
  // implies that the function does not throw synchronous exceptions.
74
8.25k
  return !isAsynchronousEHPersonality(Personality);
75
8.25k
}
76
77
393
DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) {
78
393
  SmallVector<std::pair<BasicBlock *, BasicBlock *>, 16> Worklist;
79
393
  BasicBlock *EntryBlock = &F.getEntryBlock();
80
393
  DenseMap<BasicBlock *, ColorVector> BlockColors;
81
393
82
393
  // Build up the color map, which maps each block to its set of 'colors'.
83
393
  // For any block B the "colors" of B are the set of funclets F (possibly
84
393
  // including a root "funclet" representing the main function) such that
85
393
  // F will need to directly contain B or a copy of B (where the term "directly
86
393
  // contain" is used to distinguish from being "transitively contained" in
87
393
  // a nested funclet).
88
393
  //
89
393
  // Note: Despite not being a funclet in the truest sense, a catchswitch is
90
393
  // considered to belong to its own funclet for the purposes of coloring.
91
393
92
393
  DEBUG_WITH_TYPE("winehprepare-coloring", dbgs() << "\nColoring funclets for "
93
393
                                                  << F.getName() << "\n");
94
393
95
393
  Worklist.push_back({EntryBlock, EntryBlock});
96
393
97
3.30k
  while (!Worklist.empty()) {
98
2.91k
    BasicBlock *Visiting;
99
2.91k
    BasicBlock *Color;
100
2.91k
    std::tie(Visiting, Color) = Worklist.pop_back_val();
101
2.91k
    DEBUG_WITH_TYPE("winehprepare-coloring",
102
2.91k
                    dbgs() << "Visiting " << Visiting->getName() << ", "
103
2.91k
                           << Color->getName() << "\n");
104
2.91k
    Instruction *VisitingHead = Visiting->getFirstNonPHI();
105
2.91k
    if (VisitingHead->isEHPad()) {
106
1.16k
      // Mark this funclet head as a member of itself.
107
1.16k
      Color = Visiting;
108
1.16k
    }
109
2.91k
    // Note that this is a member of the given color.
110
2.91k
    ColorVector &Colors = BlockColors[Visiting];
111
2.91k
    if (!is_contained(Colors, Color))
112
2.33k
      Colors.push_back(Color);
113
577
    else
114
577
      continue;
115
2.33k
116
2.33k
    DEBUG_WITH_TYPE("winehprepare-coloring",
117
2.33k
                    dbgs() << "  Assigned color \'" << Color->getName()
118
2.33k
                           << "\' to block \'" << Visiting->getName()
119
2.33k
                           << "\'.\n");
120
2.33k
121
2.33k
    BasicBlock *SuccColor = Color;
122
2.33k
    Instruction *Terminator = Visiting->getTerminator();
123
2.33k
    if (auto *CatchRet = dyn_cast<CatchReturnInst>(Terminator)) {
124
379
      Value *ParentPad = CatchRet->getCatchSwitchParentPad();
125
379
      if (isa<ConstantTokenNone>(ParentPad))
126
355
        SuccColor = EntryBlock;
127
24
      else
128
24
        SuccColor = cast<Instruction>(ParentPad)->getParent();
129
379
    }
130
2.33k
131
2.33k
    for (BasicBlock *Succ : successors(Visiting))
132
2.52k
      Worklist.push_back({Succ, SuccColor});
133
2.33k
  }
134
393
  return BlockColors;
135
393
}