Coverage Report

Created: 2022-07-16 07:03

/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
138k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
4.66k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::UsedDeclVisitor(clang::Sema&)
Line
Count
Source
28
134k
  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
29
30
397k
  Derived &asImpl() { return *static_cast<Derived *>(this); }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::asImpl()
Line
Count
Source
30
386k
  Derived &asImpl() { return *static_cast<Derived *>(this); }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::asImpl()
Line
Count
Source
30
10.7k
  Derived &asImpl() { return *static_cast<Derived *>(this); }
31
32
231k
  void VisitDeclRefExpr(DeclRefExpr *E) {
33
231k
    auto *D = E->getDecl();
34
231k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)213k
) {
35
231k
      asImpl().visitUsedDecl(E->getLocation(), D);
36
231k
    }
37
231k
  }
38
39
11.0k
  void VisitMemberExpr(MemberExpr *E) {
40
11.0k
    auto *D = E->getMemberDecl();
41
11.0k
    if (isa<FunctionDecl>(D) || 
isa<VarDecl>(D)5.83k
) {
42
5.20k
      asImpl().visitUsedDecl(E->getMemberLoc(), D);
43
5.20k
    }
44
11.0k
    asImpl().Visit(E->getBase());
45
11.0k
  }
46
47
61.1k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
61.1k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
61.1k
    Inherited::VisitCapturedStmt(Node);
50
61.1k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCapturedStmt(clang::CapturedStmt*)
Line
Count
Source
47
61.1k
  void VisitCapturedStmt(CapturedStmt *Node) {
48
61.1k
    asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
49
61.1k
    Inherited::VisitCapturedStmt(Node);
50
61.1k
  }
Unexecuted instantiation: SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCapturedStmt(clang::CapturedStmt*)
51
52
6.43k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
6.43k
    asImpl().visitUsedDecl(
54
6.43k
        E->getBeginLoc(),
55
6.43k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
6.43k
    asImpl().Visit(E->getSubExpr());
57
6.43k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
3.36k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
3.36k
    asImpl().visitUsedDecl(
54
3.36k
        E->getBeginLoc(),
55
3.36k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
3.36k
    asImpl().Visit(E->getSubExpr());
57
3.36k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXBindTemporaryExpr(clang::CXXBindTemporaryExpr*)
Line
Count
Source
52
3.07k
  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
53
3.07k
    asImpl().visitUsedDecl(
54
3.07k
        E->getBeginLoc(),
55
3.07k
        const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
56
3.07k
    asImpl().Visit(E->getSubExpr());
57
3.07k
  }
58
59
43
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
43
    if (E->getOperatorNew())
61
43
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
43
    if (E->getOperatorDelete())
63
3
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
43
    Inherited::VisitCXXNewExpr(E);
65
43
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXNewExpr(clang::CXXNewExpr*)
Line
Count
Source
59
37
  void VisitCXXNewExpr(CXXNewExpr *E) {
60
37
    if (E->getOperatorNew())
61
37
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
62
37
    if (E->getOperatorDelete())
63
2
      asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
64
37
    Inherited::VisitCXXNewExpr(E);
65
37
  }
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
        if (Record->getDefinition())
76
23
          asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
77
23
      }
78
23
    }
79
80
23
    Inherited::VisitCXXDeleteExpr(E);
81
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
        if (Record->getDefinition())
76
20
          asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
77
20
      }
78
20
    }
79
80
20
    Inherited::VisitCXXDeleteExpr(E);
81
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
        if (Record->getDefinition())
76
3
          asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
77
3
      }
78
3
    }
79
80
3
    Inherited::VisitCXXDeleteExpr(E);
81
3
  }
82
83
13.0k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
84
13.0k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
85
13.0k
    Inherited::VisitCXXConstructExpr(E);
86
13.0k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
83
8.65k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
84
8.65k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
85
8.65k
    Inherited::VisitCXXConstructExpr(E);
86
8.65k
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXConstructExpr(clang::CXXConstructExpr*)
Line
Count
Source
83
4.43k
  void VisitCXXConstructExpr(CXXConstructExpr *E) {
84
4.43k
    asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
85
4.43k
    Inherited::VisitCXXConstructExpr(E);
86
4.43k
  }
87
88
1.09k
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
89
1.09k
    asImpl().Visit(E->getExpr());
90
1.09k
  }
Sema.cpp:clang::UsedDeclVisitor<(anonymous namespace)::DeferredDiagnosticsEmitter>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
88
961
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
89
961
    asImpl().Visit(E->getExpr());
90
961
  }
SemaExpr.cpp:clang::UsedDeclVisitor<(anonymous namespace)::EvaluatedExprMarker>::VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr*)
Line
Count
Source
88
129
  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
89
129
    asImpl().Visit(E->getExpr());
90
129
  }
91
92
61.1k
  void visitUsedDecl(SourceLocation Loc, Decl *D) {
93
61.1k
    if (auto *CD = dyn_cast<CapturedDecl>(D)) {
94
61.1k
      if (auto *S = CD->getBody()) {
95
61.1k
        asImpl().Visit(S);
96
61.1k
      }
97
61.1k
    } else 
if (auto *0
CD0
= dyn_cast<BlockDecl>(D)) {
98
0
      if (auto *S = CD->getBody()) {
99
0
        asImpl().Visit(S);
100
0
      }
101
0
    }
102
61.1k
  }
103
};
104
} // end namespace clang
105
106
#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H