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

tudasc / TypeART / 12904858633

22 Jan 2025 09:11AM UTC coverage: 90.735% (+0.005%) from 90.73%
12904858633

Pull #149

github

web-flow
Merge f0a5eda87 into 37d7f8cb1
Pull Request #149: Replace llvm::Optional with std::optional

88 of 102 new or added lines in 23 files covered. (86.27%)

1 existing line in 1 file now uncovered.

3829 of 4220 relevant lines covered (90.73%)

117945.73 hits per line

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

66.67
/lib/passes/instrumentation/InstrumentationHelper.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 "InstrumentationHelper.h"
14

15
#include "support/Logger.h"
16

17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/SmallVector.h"
19
#include "llvm/IR/Constants.h"
20
#include "llvm/IR/DerivedTypes.h"
21
#include "llvm/IR/Module.h"
22
#include "llvm/IR/Type.h"
23
#include "llvm/IR/Value.h"
24
#include "llvm/Support/Casting.h"
25

26
#include <optional>
27

28
namespace typeart {
29

30
using namespace llvm;
31

32
InstrumentationHelper::InstrumentationHelper()  = default;
3,284✔
33
InstrumentationHelper::~InstrumentationHelper() = default;
1,624✔
34

35
llvm::SmallVector<llvm::Type*, 8> InstrumentationHelper::make_signature(const llvm::ArrayRef<llvm::Value*>& args) {
×
36
  llvm::SmallVector<llvm::Type*, 8> types;
×
37
  for (auto* val : args) {
×
38
    types.push_back(val->getType());
×
39
  }
40
  return types;
×
41
}
×
42

43
llvm::Type* InstrumentationHelper::getTypeFor(IType id) {
41,389✔
44
  auto& c = module->getContext();
41,389✔
45
  switch (id) {
41,389✔
46
    case IType::ptr:
47
      return Type::getInt8PtrTy(c);
9,030✔
48
    case IType::function_id:
49
      return Type::getInt32Ty(c);
×
50
    case IType::extent:
51
      return Type::getInt64Ty(c);
18,778✔
52
    case IType::type_id:
53
      [[fallthrough]];
54
    case IType::alloca_id:
55
      return Type::getInt32Ty(c);
9,416✔
56
    case IType::stack_count:
57
      return Type::getInt32Ty(c);
15,223✔
58
    default:
59
      LOG_WARNING("Unknown IType selected.");
×
60
      return nullptr;
×
61
  }
62
}
41,389✔
63

64
llvm::ConstantInt* InstrumentationHelper::getConstantFor(IType id, size_t value) {
21,811✔
65
  const auto make_int = [&]() -> std::optional<ConstantInt*> {
43,622✔
66
    auto itype = dyn_cast_or_null<IntegerType>(getTypeFor(id));
21,811✔
67
    if (itype == nullptr) {
21,811✔
68
      LOG_FATAL("Pointer for the constant type is null, need aborting...");
×
NEW
69
      return {};
×
70
    }
71
    return ConstantInt::get(itype, value);
21,811✔
72
  };
21,811✔
73
  return make_int().value();
21,811✔
74
}
75

76
void InstrumentationHelper::setModule(llvm::Module& m) {
1,624✔
77
  module = &m;
1,624✔
78
}
1,624✔
79

80
llvm::Module* InstrumentationHelper::getModule() const {
369✔
81
  return module;
369✔
82
}
83

84
}  // 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