Coverage Report

Created: 2020-02-15 09:57

/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> T read() {
48
2
    T Value = ReadHelper<T>(Ptr);
49
2
    Ptr += sizeof(T);
50
2
    return Value;
51
2
  }
clang::interp::Opcode clang::interp::CodePtr::read<clang::interp::Opcode>()
Line
Count
Source
47
1
  template <typename T> T read() {
48
1
    T Value = ReadHelper<T>(Ptr);
49
1
    Ptr += sizeof(T);
50
1
    return Value;
51
1
  }
Unexecuted instantiation: bool clang::interp::CodePtr::read<bool>()
Unexecuted instantiation: short clang::interp::CodePtr::read<short>()
Unexecuted instantiation: int clang::interp::CodePtr::read<int>()
Unexecuted instantiation: long long clang::interp::CodePtr::read<long long>()
Unexecuted instantiation: signed char clang::interp::CodePtr::read<signed char>()
Unexecuted instantiation: unsigned short clang::interp::CodePtr::read<unsigned short>()
unsigned int clang::interp::CodePtr::read<unsigned int>()
Line
Count
Source
47
1
  template <typename T> T read() {
48
1
    T Value = ReadHelper<T>(Ptr);
49
1
    Ptr += sizeof(T);
50
1
    return Value;
51
1
  }
Unexecuted instantiation: unsigned long long clang::interp::CodePtr::read<unsigned long long>()
Unexecuted instantiation: unsigned char clang::interp::CodePtr::read<unsigned char>()
Unexecuted instantiation: clang::RecordDecl const* clang::interp::CodePtr::read<clang::RecordDecl const*>()
Unexecuted instantiation: clang::interp::Record::Field const* clang::interp::CodePtr::read<clang::interp::Record::Field const*>()
52
53
private:
54
  /// Constructor used by Function to generate pointers.
55
1
  CodePtr(const char *Ptr) : Ptr(Ptr) {}
56
57
  /// Helper to decode a value or a pointer.
58
  template <typename T>
59
  static std::enable_if_t<!std::is_pointer<T>::value, T>
60
2
  ReadHelper(const char *Ptr) {
61
2
    using namespace llvm::support;
62
2
    return endian::read<T, endianness::native, 1>(Ptr);
63
2
  }
std::__1::enable_if<!(std::is_pointer<clang::interp::Opcode>::value), clang::interp::Opcode>::type clang::interp::CodePtr::ReadHelper<clang::interp::Opcode>(char const*)
Line
Count
Source
60
1
  ReadHelper(const char *Ptr) {
61
1
    using namespace llvm::support;
62
1
    return endian::read<T, endianness::native, 1>(Ptr);
63
1
  }
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<bool>::value), bool>::type clang::interp::CodePtr::ReadHelper<bool>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<short>::value), short>::type clang::interp::CodePtr::ReadHelper<short>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<int>::value), int>::type clang::interp::CodePtr::ReadHelper<int>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<long long>::value), long long>::type clang::interp::CodePtr::ReadHelper<long long>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<signed char>::value), signed char>::type clang::interp::CodePtr::ReadHelper<signed char>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned short>::value), unsigned short>::type clang::interp::CodePtr::ReadHelper<unsigned short>(char const*)
std::__1::enable_if<!(std::is_pointer<unsigned int>::value), unsigned int>::type clang::interp::CodePtr::ReadHelper<unsigned int>(char const*)
Line
Count
Source
60
1
  ReadHelper(const char *Ptr) {
61
1
    using namespace llvm::support;
62
1
    return endian::read<T, endianness::native, 1>(Ptr);
63
1
  }
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned long long>::value), unsigned long long>::type clang::interp::CodePtr::ReadHelper<unsigned long long>(char const*)
Unexecuted instantiation: std::__1::enable_if<!(std::is_pointer<unsigned char>::value), unsigned char>::type clang::interp::CodePtr::ReadHelper<unsigned char>(char const*)
64
65
  template <typename T>
66
  static std::enable_if_t<std::is_pointer<T>::value, T>
67
0
  ReadHelper(const char *Ptr) {
68
0
    using namespace llvm::support;
69
0
    auto Punned = endian::read<uintptr_t, endianness::native, 1>(Ptr);
70
0
    return reinterpret_cast<T>(Punned);
71
0
  }
Unexecuted instantiation: std::__1::enable_if<std::is_pointer<clang::RecordDecl const*>::value, clang::RecordDecl const*>::type clang::interp::CodePtr::ReadHelper<clang::RecordDecl const*>(char const*)
Unexecuted instantiation: std::__1::enable_if<std::is_pointer<clang::interp::Record::Field const*>::value, clang::interp::Record::Field const*>::type clang::interp::CodePtr::ReadHelper<clang::interp::Record::Field const*>(char const*)
72
73
private:
74
  friend class Function;
75
76
  /// Pointer into the code owned by a function.
77
  const char *Ptr;
78
};
79
80
/// Describes the statement/declaration an opcode was generated from.
81
class SourceInfo {
82
public:
83
10
  SourceInfo() {}
84
11
  SourceInfo(const Stmt *E) : Source(E) {}
85
0
  SourceInfo(const Decl *D) : Source(D) {}
86
87
  SourceLocation getLoc() const;
88
89
0
  const Stmt *asStmt() const { return Source.dyn_cast<const Stmt *>(); }
90
0
  const Decl *asDecl() const { return Source.dyn_cast<const Decl *>(); }
91
  const Expr *asExpr() const;
92
93
14
  operator bool() const { return !Source.isNull(); }
94
95
private:
96
  llvm::PointerUnion<const Decl *, const Stmt *> Source;
97
};
98
99
using SourceMap = std::vector<std::pair<unsigned, SourceInfo>>;
100
101
/// Interface for classes which map locations to sources.
102
class SourceMapper {
103
public:
104
15
  virtual ~SourceMapper() {}
105
106
  /// Returns source information for a given PC in a function.
107
  virtual SourceInfo getSource(Function *F, CodePtr PC) const = 0;
108
109
  /// Returns the expression if an opcode belongs to one, null otherwise.
110
  const Expr *getExpr(Function *F, CodePtr PC) const;
111
  /// Returns the location from which an opcode originates.
112
  SourceLocation getLocation(Function *F, CodePtr PC) const;
113
};
114
115
} // namespace interp
116
} // namespace clang
117
118
#endif