Coverage Report

Created: 2018-07-22 10:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/Visibility.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Visibility.h - Visibility enumeration and utilities ----*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// Defines the clang::Visibility enumeration and various utility
12
/// functions.
13
///
14
//===----------------------------------------------------------------------===//
15
#ifndef LLVM_CLANG_BASIC_VISIBILITY_H
16
#define LLVM_CLANG_BASIC_VISIBILITY_H
17
18
#include "clang/Basic/Linkage.h"
19
#include <cassert>
20
#include <cstdint>
21
22
namespace clang {
23
24
/// Describes the different kinds of visibility that a declaration
25
/// may have.
26
///
27
/// Visibility determines how a declaration interacts with the dynamic
28
/// linker.  It may also affect whether the symbol can be found by runtime
29
/// symbol lookup APIs.
30
///
31
/// Visibility is not described in any language standard and
32
/// (nonetheless) sometimes has odd behavior.  Not all platforms
33
/// support all visibility kinds.
34
enum Visibility {
35
  /// Objects with "hidden" visibility are not seen by the dynamic
36
  /// linker.
37
  HiddenVisibility,
38
39
  /// Objects with "protected" visibility are seen by the dynamic
40
  /// linker but always dynamically resolve to an object within this
41
  /// shared object.
42
  ProtectedVisibility,
43
44
  /// Objects with "default" visibility are seen by the dynamic linker
45
  /// and act like normal objects.
46
  DefaultVisibility
47
};
48
49
inline Visibility minVisibility(Visibility L, Visibility R) {
50
  return L < R ? L : R;
51
}
52
53
class LinkageInfo {
54
  uint8_t linkage_    : 3;
55
  uint8_t visibility_ : 2;
56
  uint8_t explicit_   : 1;
57
58
3.26M
  void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
59
public:
60
  LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility),
61
21.6M
                  explicit_(false) {}
62
  LinkageInfo(Linkage L, Visibility V, bool E)
63
44.9M
    : linkage_(L), visibility_(V), explicit_(E) {
64
44.9M
    assert(getLinkage() == L && getVisibility() == V &&
65
44.9M
           isVisibilityExplicit() == E && "Enum truncated!");
66
44.9M
  }
67
68
6.94M
  static LinkageInfo external() {
69
6.94M
    return LinkageInfo();
70
6.94M
  }
71
1.04M
  static LinkageInfo internal() {
72
1.04M
    return LinkageInfo(InternalLinkage, DefaultVisibility, false);
73
1.04M
  }
74
2.16k
  static LinkageInfo uniqueExternal() {
75
2.16k
    return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false);
76
2.16k
  }
77
1.36M
  static LinkageInfo none() {
78
1.36M
    return LinkageInfo(NoLinkage, DefaultVisibility, false);
79
1.36M
  }
80
1
  static LinkageInfo visible_none() {
81
1
    return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false);
82
1
  }
83
84
80.3M
  Linkage getLinkage() const { return (Linkage)linkage_; }
85
15.3M
  Visibility getVisibility() const { return (Visibility)visibility_; }
86
12.0M
  bool isVisibilityExplicit() const { return explicit_; }
87
88
6.77M
  void setLinkage(Linkage L) { linkage_ = L; }
89
90
5.52M
  void mergeLinkage(Linkage L) {
91
5.52M
    setLinkage(minLinkage(getLinkage(), L));
92
5.52M
  }
93
5.52M
  void mergeLinkage(LinkageInfo other) {
94
5.52M
    mergeLinkage(other.getLinkage());
95
5.52M
  }
96
97
1.24M
  void mergeExternalVisibility(Linkage L) {
98
1.24M
    Linkage ThisL = getLinkage();
99
1.24M
    if (!isExternallyVisible(L)) {
100
2.14k
      if (ThisL == VisibleNoLinkage)
101
0
        ThisL = NoLinkage;
102
2.14k
      else if (ThisL == ExternalLinkage)
103
2.14k
        ThisL = UniqueExternalLinkage;
104
2.14k
    }
105
1.24M
    setLinkage(ThisL);
106
1.24M
  }
107
1.24M
  void mergeExternalVisibility(LinkageInfo Other) {
108
1.24M
    mergeExternalVisibility(Other.getLinkage());
109
1.24M
  }
110
111
  /// Merge in the visibility 'newVis'.
112
8.52M
  void mergeVisibility(Visibility newVis, bool newExplicit) {
113
8.52M
    Visibility oldVis = getVisibility();
114
8.52M
115
8.52M
    // Never increase visibility.
116
8.52M
    if (oldVis < newVis)
117
504k
      return;
118
8.02M
119
8.02M
    // If the new visibility is the same as the old and the new
120
8.02M
    // visibility isn't explicit, we have nothing to add.
121
8.02M
    if (oldVis == newVis && 
!newExplicit6.81M
)
122
4.75M
      return;
123
3.26M
124
3.26M
    // Otherwise, we're either decreasing visibility or making our
125
3.26M
    // existing visibility explicit.
126
3.26M
    setVisibility(newVis, newExplicit);
127
3.26M
  }
128
6.35M
  void mergeVisibility(LinkageInfo other) {
129
6.35M
    mergeVisibility(other.getVisibility(), other.isVisibilityExplicit());
130
6.35M
  }
131
132
  /// Merge both linkage and visibility.
133
2.20M
  void merge(LinkageInfo other) {
134
2.20M
    mergeLinkage(other);
135
2.20M
    mergeVisibility(other);
136
2.20M
  }
137
138
  /// Merge linkage and conditionally merge visibility.
139
3.31M
  void mergeMaybeWithVisibility(LinkageInfo other, bool withVis) {
140
3.31M
    mergeLinkage(other);
141
3.31M
    if (withVis) 
mergeVisibility(other)2.90M
;
142
3.31M
  }
143
};
144
}
145
146
#endif // LLVM_CLANG_BASIC_VISIBILITY_H