Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/Source.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Source.h - Source location provider for the 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
// Defines a program which organises and links multiple bytecode functions.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_INTERP_SOURCE_H
14
#define LLVM_CLANG_AST_INTERP_SOURCE_H
15
16
#include "clang/AST/Decl.h"
17
#include "clang/AST/Stmt.h"
18
#include "llvm/Support/Endian.h"
19
20
namespace clang {
21
namespace interp {
22
class Function;
23
24
/// Pointer into the code segment.
25
class CodePtr {
26
public:
27
15
  CodePtr() : Ptr(nullptr) {}
28
29
0
  CodePtr &operator+=(int32_t Offset) {
30
0
    Ptr += Offset;
31
0
    return *this;
32
0
  }
33
34
0
  int32_t operator-(const CodePtr &RHS) const {
35
0
    assert(Ptr != nullptr && RHS.Ptr != nullptr && "Invalid code pointer");
36
0
    return Ptr - RHS.Ptr;
37
0
  }
38
39
0
  CodePtr operator-(size_t RHS) const {
40
0
    assert(Ptr != nullptr && "Invalid code pointer");
41
0
    return CodePtr(Ptr - RHS);
42
0
  }
43
44
0
  bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
45
46
  /// Reads data and advances the pointer.
47
2
  template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
48
2
    using namespace llvm::support;
49
2
    T Value = endian::read<T, endianness::native, 1>(Ptr);
50
2
    Ptr += sizeof(T);
51
2
    return Value;
52
2
  }
std::__1::enable_if<!(std::is_pointer<clang::interp::Opcode>::value), clang::interp::Opcode>::type clang::interp::CodePtr::read<clang::interp::Opcode>()
Line
Count
Source
47
1
  template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
48
1
    using namespace llvm::support;
49
1
    T Value = endian::read<T, endianness::native, 1>(Ptr);
50
1
    Ptr += sizeof(T);
51
1
    return Value;
52
1
  }
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<bool>::value), bool>::type clang::interp::CodePtr::read<bool>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<short>::value), short>::type clang::interp::CodePtr::read<short>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<int>::value), int>::type clang::interp::CodePtr::read<int>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<long long>::value), long long>::type clang::interp::CodePtr::read<long long>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<signed char>::value), signed char>::type clang::interp::CodePtr::read<signed char>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned short>::value), unsigned short>::type clang::interp::CodePtr::read<unsigned short>()
std::__1::enable_if<!(std::is_pointer<unsigned int>::value), unsigned int>::type clang::interp::CodePtr::read<unsigned int>()
Line
Count
Source
47
1
  template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
48
1
    using namespace llvm::support;
49
1
    T Value = endian::read<T, endianness::native, 1>(Ptr);
50
1
    Ptr += sizeof(T);
51
1
    return Value;
52
1
  }
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned long long>::value), unsigned long long>::type clang::interp::CodePtr::read<unsigned long long>()
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned char>::value), unsigned char>::type clang::interp::CodePtr::read<unsigned char>()
53
54
private:
55
  /// Constructor used by Function to generate pointers.
56
1
  CodePtr(const char *Ptr) : Ptr(Ptr) {}
57
58
private:
59
  friend class Function;
60
61
  /// Pointer into the code owned by a function.
62
  const char *Ptr;
63
};
64
65
/// Describes the statement/declaration an opcode was generated from.
66
class SourceInfo {
67
public:
68
10
  SourceInfo() {}
69
11
  SourceInfo(const Stmt *E) : Source(E) {}
70
0
  SourceInfo(const Decl *D) : Source(D) {}
71
72
  SourceLocation getLoc() const;
73
74
0
  const Stmt *asStmt() const { return Source.dyn_cast<const Stmt *>(); }
75
0
  const Decl *asDecl() const { return Source.dyn_cast<const Decl *>(); }
76
  const Expr *asExpr() const;
77
78
14
  operator bool() const { return !Source.isNull(); }
79
80
private:
81
  llvm::PointerUnion<const Decl *, const Stmt *> Source;
82
};
83
84
using SourceMap = std::vector<std::pair<unsigned, SourceInfo>>;
85
86
/// Interface for classes which map locations to sources.
87
class SourceMapper {
88
public:
89
15
  virtual ~SourceMapper() {}
90
91
  /// Returns source information for a given PC in a function.
92
  virtual SourceInfo getSource(Function *F, CodePtr PC) const = 0;
93
94
  /// Returns the expression if an opcode belongs to one, null otherwise.
95
  const Expr *getExpr(Function *F, CodePtr PC) const;
96
  /// Returns the location from which an opcode originates.
97
  SourceLocation getLocation(Function *F, CodePtr PC) const;
98
};
99
100
} // namespace interp
101
} // namespace clang
102
103
#endif