Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/FunctionPointer.h
Line
Count
Source (jump to first uncovered line)
1
//===--- FunctionPointer.h - Types for the constexpr VM ----------*- 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
9
#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
10
#define LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
11
12
#include "Function.h"
13
#include "Primitives.h"
14
#include "clang/AST/APValue.h"
15
16
namespace clang {
17
class ASTContext;
18
namespace interp {
19
20
class FunctionPointer final {
21
private:
22
  const Function *Func;
23
24
public:
25
30
  FunctionPointer() : Func(nullptr) {}
26
76
  FunctionPointer(const Function *Func) : Func(Func) { assert(Func); }
27
28
56
  const Function *getFunction() const { return Func; }
29
30
37
  APValue toAPValue() const {
31
37
    if (!Func)
32
6
      return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {},
33
6
                     /*OnePastTheEnd=*/false, /*IsNull=*/true);
34
35
31
    return APValue(Func->getDecl(), CharUnits::Zero(), {},
36
31
                   /*OnePastTheEnd=*/false, /*IsNull=*/false);
37
37
  }
38
39
0
  void print(llvm::raw_ostream &OS) const {
40
0
    OS << "FnPtr(";
41
0
    if (Func)
42
0
      OS << Func->getName();
43
0
    else
44
0
      OS << "nullptr";
45
0
    OS << ")";
46
0
  }
47
48
12
  std::string toDiagnosticString(const ASTContext &Ctx) const {
49
12
    if (!Func)
50
3
      return "nullptr";
51
52
9
    return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
53
12
  }
54
55
30
  ComparisonCategoryResult compare(const FunctionPointer &RHS) const {
56
30
    if (Func == RHS.Func)
57
12
      return ComparisonCategoryResult::Equal;
58
18
    return ComparisonCategoryResult::Unordered;
59
30
  }
60
};
61
62
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
63
0
                                     FunctionPointer FP) {
64
0
  FP.print(OS);
65
0
  return OS;
66
0
}
67
68
} // namespace interp
69
} // namespace clang
70
71
#endif