• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tudasc / TypeART / 13528988609

25 Feb 2025 07:06PM UTC coverage: 88.854% (-1.9%) from 90.735%
13528988609

Pull #163

github

web-flow
Merge e4a2d80f6 into d2e14acc5
Pull Request #163: LLVM 18 support

974 of 1122 new or added lines in 38 files covered. (86.81%)

30 existing lines in 6 files now uncovered.

4201 of 4728 relevant lines covered (88.85%)

190054.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.55
/lib/runtime/Runtime.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2025 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "Runtime.h"
14

15
#include "AccessCountPrinter.h"
16
#include "AccessCounter.h"
17
#include "RuntimeData.h"
18
#include "TypeIO.h"
19
#include "TypeInterface.h"
20
#include "support/ConfigurationBase.h"
21
#include "support/Logger.h"
22
// #include "llvm/Support/raw_ostream.h"
23

24
#include <cstdlib>
25
#include <iostream>
26
#include <set>
27
#include <sstream>
28
#include <unordered_map>
29
#include <vector>
30

31
namespace typeart {
32

33
namespace debug {
34

35
std::string toString(const void* memAddr, int typeId, size_t count, size_t typeSize, const void* calledFrom,
327,305✔
36
                     bool heap) {
37
  std::string buf;
327,305✔
38
  llvm::raw_string_ostream s(buf);
327,305✔
39
  const auto name = typeart::RuntimeSystem::get().typeResolution.db().getTypeName(typeId);
327,305✔
40
  if ((typeId == TYPEART_VOID) && heap) {
327,305✔
NEW
41
    count /= typeSize;
×
NEW
42
  }
×
43
  s << memAddr << " " << typeId << " " << name << " " << typeSize << " " << count << " (" << calledFrom << ")";
327,305✔
44
  return s.str();
327,305✔
45
}
327,335✔
46

47
std::string toString(const void* memAddr, int typeId, size_t count, const void* calledFrom, bool heap) {
327,306✔
48
  const auto typeSize = typeart::RuntimeSystem::get().typeResolution.db().getTypeSize(typeId);
327,306✔
49
  return toString(memAddr, typeId, count, typeSize, calledFrom, heap);
327,306✔
50
}
327,306✔
51

52
std::string toString(const void* addr, const PointerInfo& info, bool heap) {
156,026✔
53
  return toString(addr, info.typeId, info.count, info.debug, heap);
156,026✔
54
}
55

56
inline void printTraceStart() {
589✔
57
  LOG_TRACE("TypeART Runtime Trace");
995✔
58
  LOG_TRACE("*********************");
589✔
59
  LOG_TRACE("Operation  Address   Type   Size   Count   (CallAddr)   Stack/Heap/Global");
589✔
60
  LOG_TRACE("-------------------------------------------------------------------------");
995✔
61
}
589✔
62

63
}  // namespace debug
64

65
static constexpr const char* defaultTypeFileName = config::ConfigStdArgValues::types;
66

67
RuntimeSystem::RuntimeSystem() : rtScopeInit(), typeResolution(typeDB, recorder), allocTracker(typeDB, recorder) {
598✔
68
  debug::printTraceStart();
598✔
69

70
  auto loadTypes = [this](const std::string& file, std::error_code& ec) -> bool {
1,187✔
71
    auto loaded = io::load(&typeDB, file);
589✔
72
    ec          = loaded.getError();
589✔
73
    return !static_cast<bool>(ec);
589✔
74
  };
1,001✔
75

76
  std::error_code error;
598✔
77
  // Try to load types from specified file first.
78
  // Then look at default location.
79
  const char* type_file = std::getenv(config::EnvironmentStdArgs::types);
598✔
80
  if (type_file == nullptr) {
598✔
81
    // FIXME Deprecated name
82
    type_file = std::getenv("TYPEART_TYPE_FILE");
589✔
83
    if (type_file != nullptr) {
589✔
84
      LOG_WARNING("Use of deprecated env var TYPEART_TYPE_FILE.");
9✔
85
    }
9✔
86
  }
589✔
87
  if (type_file != nullptr) {
598✔
88
    if (!loadTypes(type_file, error)) {
18✔
89
      LOG_FATAL("Failed to load recorded types from " << config::EnvironmentStdArgs::types << "=" << type_file
18✔
90
                                                      << " .Reason: " << error.message());
UNCOV
91
      std::exit(EXIT_FAILURE);  // TODO: Error handling
×
92
    }
93
  } else {
×
94
    if (!loadTypes(defaultTypeFileName, error)) {
580✔
95
      LOG_WARNING(
18✔
96
          "No type file with default name \""
97
          << defaultTypeFileName
98
          << "\" in current directory. Using default built-in types only. To specify a different file, edit the "
99
             "TYPEART_TYPE_FILE environment variable. Reason: "
100
          << error.message());
101
    }
18✔
102
  }
103

104
  std::stringstream ss;
580✔
105
  const auto& typeList = typeDB.getStructList();
580✔
106
  for (const auto& structInfo : typeList) {
3,162✔
107
    ss << structInfo.name << ", ";
2,582✔
108
  }
2,582✔
109
  recorder.incUDefTypes(typeList.size());
580✔
110
  LOG_INFO("Recorded types: " << ss.str());
580✔
111
  rtScopeInit.reset();
580✔
112
}
424✔
113

114
RuntimeSystem::~RuntimeSystem() {
580✔
115
  rtScope = true;
580✔
116

117
  //  std::string stats;
118
  //  llvm::raw_string_ostream stream(stats);
119

120
  std::ostringstream stream;
580✔
121
  softcounter::serialize(recorder, stream);
580✔
122
  if (!stream.str().empty()) {
580✔
123
    // llvm::errs/LOG will crash with virtual call error
124
    std::cerr << stream.str();
580✔
125
  }
580✔
126
}
580✔
127

128
// This is initially set to true in order to prevent tracking anything before the runtime library is properly set up.
129
thread_local bool RuntimeSystem::rtScope = false;
130

131
}  // namespace typeart
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc