Coverage Report

Created: 2020-10-24 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Sema/UsedDeclVisitor.h
Line
Count
Source (jump to first uncovered line)
1
//===- UsedDeclVisitor.h - ODR-used declarations visitor --------*- C++ -*-===//
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
//  This file defines UsedDeclVisitor, a CRTP class which visits all the
9
//  declarations that are ODR-used by an expression or statement.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
14
#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
15
16
#include "clang/AST/EvaluatedExprVisitor.h"
17
#include "clang/Sema/SemaInternal.h"
18
19
namespace clang {
20
template <class Derived>
21
class UsedDeclVisitor : public EvaluatedExprVisitor<Derived> {
22
protected:
23
  Sema &S;
24
25
public:
26
  typedef EvaluatedExprVisitor<Derived> Inherited;
27
28
127k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
8.68k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
119k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
29
30
1.34M
  Derived &asImpl() { return *static_cast<Derived *>(this); }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::asImpl()
Line
Count
Source
30
1.33M
  Derived &asImpl() { return *static_cast<Derived *>(this); }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::asImpl()
Line
Count
Source
30
10.5k
  Derived &asImpl() { return *static_cast<Derived *>(this); }
31
32
740k
  void VisitDeclRefExpr(DeclRefExpr *E) {
33
740k
    auto *D = E->getDecl();
34
740k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)664k
) {
35
740k
      asImpl().visitUsedDecl(E->getLocation(), D);
36
740k
    }
37
740k
  }
38
39
15.3k
  void VisitMemberExpr(MemberExpr *E) {
40
15.3k
    auto *D = E->getMemberDecl();
41
15.3k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)10.0k
) {
42
5.28k
      asImpl().visitUsedDecl(E->getMemberLoc(), D);
43
5.28k
    }
44
15.3k
    asImpl().Visit(E->getBase());
45
15.3k
  }
46
47
271k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
271k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
271k
    Inherited::VisitCapturedStmt(Node);
50
271k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCapturedStmt(clang::CapturedStmt*)
Line
Count
Source
47
271k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
271k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
271k
    Inherited::VisitCapturedStmt(Node);
50
271k
  }
Unexecuted instantiation: SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCapturedStmt(clang::CapturedStmt*)
51
52
7.47k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
7.47k
    asImpl().visitUsedDecl(
54
7.47k
        E->getBeginLoc(),
55
7.47k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
7.47k
    asImpl().Visit(E->getSubExpr());
57
7.47k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
4.41k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
4.41k
    asImpl().visitUsedDecl(
54
4.41k
        E->getBeginLoc(),
55
4.41k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
4.41k
    asImpl().Visit(E->getSubExpr());
57
4.41k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
3.05k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
3.05k
    asImpl().visitUsedDecl(
54
3.05k
        E->getBeginLoc(),
55
3.05k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
3.05k
    asImpl().Visit(E->getSubExpr());
57
3.05k
  }
58
59
45
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
45
    if (E->getOperatorNew())
61
45
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
45
    if (E->getOperatorDelete())
63
1
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
45
    Inherited::VisitCXXNewExpr(E);
65
45
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXNewExpr(clang::CXXNewExpr*)
Line
Count
Source
59
40
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
40
    if (E->getOperatorNew())
61
40
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
40
    if (E->getOperatorDelete())
63
0
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
40
    Inherited::VisitCXXNewExpr(E);
65
40
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXNewExpr(clang::CXXNewExpr*)
Line
Count
Source
59
5
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
5
    if (E->getOperatorNew())
61
5
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
5
    if (E->getOperatorDelete())
63
1
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
5
    Inherited::VisitCXXNewExpr(E);
65
5
  }
66
67
5
  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
68
5
    if (E->getOperatorDelete())
69
5
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
70
5
    QualType DestroyedOrNull = E->getDestroyedType();
71
5
    if (!DestroyedOrNull.isNull()) {
72
5
      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
73
5
      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
74
5
        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
75
5
        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
76
5
      }
77
5
    }
78
79
5
    Inherited::VisitCXXDeleteExpr(E);
80
5
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXDeleteExpr(clang::CXXDeleteExpr*)
Line
Count
Source
67
2
  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
68
2
    if (E->getOperatorDelete())
69
2
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
70
2
    QualType DestroyedOrNull = E->getDestroyedType();
71
2
    if (!DestroyedOrNull.isNull()) {
72
2
      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
73
2
      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
74
2
        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
75
2
        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
76
2
      }
77
2
    }
78
79
2
    Inherited::VisitCXXDeleteExpr(E);
80
2
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXDeleteExpr(clang::CXXDeleteExpr*)
Line
Count
Source
67
3
  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
68
3
    if (E->getOperatorDelete())
69
3
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
70
3
    QualType DestroyedOrNull = E->getDestroyedType();
71
3
    if (!DestroyedOrNull.isNull()) {
72
3
      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
73
3
      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
74
3
        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
75
3
        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
76
3
      }
77
3
    }
78
79
3
    Inherited::VisitCXXDeleteExpr(E);
80
3
  }
81
82
25.1k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
25.1k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
25.1k
    Inherited::VisitCXXConstructExpr(E);
85
25.1k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
82
20.9k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
20.9k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
20.9k
    Inherited::VisitCXXConstructExpr(E);
85
20.9k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
82
4.25k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
4.25k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
4.25k
    Inherited::VisitCXXConstructExpr(E);
85
4.25k
  }
86
87
1.96k
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
1.96k
    asImpl().Visit(E->getExpr());
89
1.96k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
87
1.78k
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
1.78k
    asImpl().Visit(E->getExpr());
89
1.78k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
87
176
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
176
    asImpl().Visit(E->getExpr());
89
176
  }
90
91
271k
  void visitUsedDecl(SourceLocation Loc, Decl *D) {
92
271k
    if (auto *CD = dyn_cast<CapturedDecl>(D)) {
93
271k
      if (auto *S = CD->getBody()) {
94
271k
        asImpl().Visit(S);
95
271k
      }
96
0
    } else if (auto *CD = dyn_cast<BlockDecl>(D)) {
97
0
      if (auto *S = CD->getBody()) {
98
0
        asImpl().Visit(S);
99
0
      }
100
0
    }
101
271k
  }
102
};
103
} // end namespace clang
104
105
#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H