Coverage Report

Created: 2021-08-24 07:12

/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
132k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
9.02k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
123k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
29
30
1.37M
  Derived &asImpl() { return *static_cast<Derived *>(this); }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::asImpl()
Line
Count
Source
30
1.36M
  Derived &asImpl() { return *static_cast<Derived *>(this); }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::asImpl()
Line
Count
Source
30
10.6k
  Derived &asImpl() { return *static_cast<Derived *>(this); }
31
32
762k
  void VisitDeclRefExpr(DeclRefExpr *E) {
33
762k
    auto *D = E->getDecl();
34
762k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)680k
) {
35
762k
      asImpl().visitUsedDecl(E->getLocation(), D);
36
762k
    }
37
762k
  }
38
39
15.9k
  void VisitMemberExpr(MemberExpr *E) {
40
15.9k
    auto *D = E->getMemberDecl();
41
15.9k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)10.5k
) {
42
5.42k
      asImpl().visitUsedDecl(E->getMemberLoc(), D);
43
5.42k
    }
44
15.9k
    asImpl().Visit(E->getBase());
45
15.9k
  }
46
47
275k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
275k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
275k
    Inherited::VisitCapturedStmt(Node);
50
275k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCapturedStmt(clang::CapturedStmt*)
Line
Count
Source
47
275k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
275k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
275k
    Inherited::VisitCapturedStmt(Node);
50
275k
  }
Unexecuted instantiation: SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCapturedStmt(clang::CapturedStmt*)
51
52
7.49k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
7.49k
    asImpl().visitUsedDecl(
54
7.49k
        E->getBeginLoc(),
55
7.49k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
7.49k
    asImpl().Visit(E->getSubExpr());
57
7.49k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
4.42k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
4.42k
    asImpl().visitUsedDecl(
54
4.42k
        E->getBeginLoc(),
55
4.42k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
4.42k
    asImpl().Visit(E->getSubExpr());
57
4.42k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
3.06k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
3.06k
    asImpl().visitUsedDecl(
54
3.06k
        E->getBeginLoc(),
55
3.06k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
3.06k
    asImpl().Visit(E->getSubExpr());
57
3.06k
  }
58
59
47
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
47
    if (E->getOperatorNew())
61
47
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
47
    if (E->getOperatorDelete())
63
1
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
47
    Inherited::VisitCXXNewExpr(E);
65
47
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXNewExpr(clang::CXXNewExpr*)
Line
Count
Source
59
41
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
41
    if (E->getOperatorNew())
61
41
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
41
    if (E->getOperatorDelete())
63
0
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
41
    Inherited::VisitCXXNewExpr(E);
65
41
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXNewExpr(clang::CXXNewExpr*)
Line
Count
Source
59
6
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
6
    if (E->getOperatorNew())
61
6
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
6
    if (E->getOperatorDelete())
63
1
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
6
    Inherited::VisitCXXNewExpr(E);
65
6
  }
66
67
23
  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
68
23
    if (E->getOperatorDelete())
69
23
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
70
23
    QualType DestroyedOrNull = E->getDestroyedType();
71
23
    if (!DestroyedOrNull.isNull()) {
72
23
      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
73
23
      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
74
23
        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
75
23
        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
76
23
      }
77
23
    }
78
79
23
    Inherited::VisitCXXDeleteExpr(E);
80
23
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXDeleteExpr(clang::CXXDeleteExpr*)
Line
Count
Source
67
20
  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
68
20
    if (E->getOperatorDelete())
69
20
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
70
20
    QualType DestroyedOrNull = E->getDestroyedType();
71
20
    if (!DestroyedOrNull.isNull()) {
72
20
      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
73
20
      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
74
20
        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
75
20
        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
76
20
      }
77
20
    }
78
79
20
    Inherited::VisitCXXDeleteExpr(E);
80
20
  }
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.7k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
25.7k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
25.7k
    Inherited::VisitCXXConstructExpr(E);
85
25.7k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
82
21.4k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
21.4k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
21.4k
    Inherited::VisitCXXConstructExpr(E);
85
21.4k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
82
4.30k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
83
4.30k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
84
4.30k
    Inherited::VisitCXXConstructExpr(E);
85
4.30k
  }
86
87
2.00k
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
2.00k
    asImpl().Visit(E->getExpr());
89
2.00k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
87
1.79k
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
1.79k
    asImpl().Visit(E->getExpr());
89
1.79k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
87
204
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
88
204
    asImpl().Visit(E->getExpr());
89
204
  }
90
91
275k
  void visitUsedDecl(SourceLocation Loc, Decl *D) {
92
275k
    if (auto *CD = dyn_cast<CapturedDecl>(D)) {
93
275k
      if (auto *S = CD->getBody()) {
94
275k
        asImpl().Visit(S);
95
275k
      }
96
275k
    } else 
if (auto *0
CD0
= dyn_cast<BlockDecl>(D)) {
97
0
      if (auto *S = CD->getBody()) {
98
0
        asImpl().Visit(S);
99
0
      }
100
0
    }
101
275k
  }
102
};
103
} // end namespace clang
104
105
#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H