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

tudasc / TypeART / 25175874405

30 Apr 2026 04:03PM UTC coverage: 89.231% (-1.0%) from 90.246%
25175874405

Pull #188

github

web-flow
Merge 61645e210 into 278119205
Pull Request #188: GPU memory allocation support

210 of 297 new or added lines in 20 files covered. (70.71%)

4 existing lines in 3 files now uncovered.

5071 of 5683 relevant lines covered (89.23%)

33116.84 hits per line

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

96.0
/lib/passes/configuration/EnvironmentConfiguration.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2026 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 "EnvironmentConfiguration.h"
14

15
#include "Configuration.h"
16
#include "OptionsUtil.h"
17
#include "PassConfiguration.h"
18
#include "configuration/TypeARTOptions.h"
19
#include "instrumentation/TypeIDProvider.h"
20
#include "support/ConfigurationBase.h"
21
#include "support/Logger.h"
22
#include "support/Util.h"
23

24
#include "llvm/ADT/StringSwitch.h"
25

26
#include <charconv>
27
#include <string>
28
#include <string_view>
29
#include <type_traits>
30

31
using namespace llvm;
32

33
namespace typeart::config::env {
34
std::optional<std::string> get_env_flag(std::string_view flag) {
187,206✔
35
  const char* env_value = std::getenv(flag.data());
187,206✔
36
  const bool exists     = env_value != nullptr;
187,206✔
37
  if (exists) {
187,206✔
38
    LOG_DEBUG("Using env var " << flag << "=" << env_value)
39
    return std::string{env_value};
10,262✔
40
  }
41
  LOG_DEBUG("Not using env var " << flag << "=<unset>")
42
  return {};
176,944✔
43
}
187,206✔
44

45
}  // namespace typeart::config::env
46

47
namespace typeart::config::env {
48

49
struct EnvironmentStdArgsValues final {
50
#define TYPEART_CONFIG_OPTION(name, path, type, def_value, description, upper_path) \
51
  static constexpr char name[] = #def_value;
52
#include "support/ConfigurationBaseOptions.h"
53
#undef TYPEART_CONFIG_OPTION
54
};
55

56
struct EnvironmentStdOptionsArgsValues final {
57
  static constexpr char option[]       = "TYPEART_OPTIONS";
58
  static constexpr char option_stack[] = "TYPEART_OPTIONS_STACK";
59
  static constexpr char option_heap[]  = "TYPEART_OPTIONS_HEAP";
60
};
61

62
namespace detail {
63
template <typename ClType>
64
OptionValue make_opt(std::string_view cl_value) {
88,668✔
65
  // LOG_DEBUG("Parsing value " << cl_value)
66
  auto value = util::make_opt<ClType>(cl_value.data());
88,668✔
67
  if constexpr (std::is_enum_v<ClType>) {
68
    return OptionValue{static_cast<int>(value)};
14,778✔
69
  } else {
70
    return OptionValue{value};
73,890✔
71
  }
72
}
19,704✔
73

74
template <typename ClType>
75
std::pair<StringRef, typename OptionsMap::mapped_type> make_entry(std::string_view key, std::string_view cl_opt,
88,668✔
76
                                                                  const std::string& default_value) {
77
  const auto env_value = get_env_flag(cl_opt);
88,668✔
78
  return {key, detail::make_opt<ClType>(env_value.value_or(default_value))};
88,668✔
79
}
88,668✔
80

81
template <typename ClOpt>
82
std::pair<StringRef, typename OptOccurrenceMap::mapped_type> make_occurr_entry(std::string_view key, ClOpt&& cl_opt) {
88,668✔
83
  const bool occurred = (get_env_flag(cl_opt).has_value());
88,668✔
84
  return {key, occurred};
88,668✔
85
}
86

87
void merge_mapping_with_passconfig(OptionsMap& mapping_, OptOccurrenceMap& occurence_mapping_,
9,870✔
88
                                   const pass::PassConfig& result) {
89
  const auto typeart_options = helper::options_to_map(result.first.get());
9,870✔
90
  for (const auto& entry : result.second) {
10,122✔
91
    const auto key = entry.getKey();
252✔
92
    if (entry.second && !occurence_mapping_[key]) {  // single ENV priority over TYPEART_OPTIONS
252✔
93
      LOG_DEBUG("Replacing " << key)
94
      mapping_[key]           = typeart_options.lookup(key);
234✔
95
      occurence_mapping_[key] = true;
234✔
96
    }
234✔
97
  }
98
}
9,870✔
99
}  // namespace detail
100

101
EnvironmentFlagsOptions::EnvironmentFlagsOptions() {
4,926✔
102
  using namespace config;
103
  using namespace typeart::config::env::detail;
104

105
  LOG_DEBUG("Construct environment flag options")
106

107
  mapping_ = {
93,594✔
108
      make_entry<std::string>(ConfigStdArgs::types, config::EnvironmentStdArgs::types, ConfigStdArgValues::types),
4,926✔
109
      make_entry<ConfigStdArgTypes::stats_ty>(ConfigStdArgs::stats, EnvironmentStdArgs::stats,
4,926✔
110
                                              EnvironmentStdArgsValues::stats),
4,926✔
111
      make_entry<ConfigStdArgTypes::heap_ty>(ConfigStdArgs::heap, EnvironmentStdArgs::heap,
4,926✔
112
                                             EnvironmentStdArgsValues::heap),
4,926✔
113
      make_entry<ConfigStdArgTypes::gpu_ty>(ConfigStdArgs::gpu, EnvironmentStdArgs::gpu,
4,926✔
114
                                            EnvironmentStdArgsValues::gpu),
4,926✔
115
      make_entry<ConfigStdArgTypes::global_ty>(ConfigStdArgs::global, EnvironmentStdArgs::global,
4,926✔
116
                                               EnvironmentStdArgsValues::global),
4,926✔
117
      make_entry<ConfigStdArgTypes::stack_ty>(ConfigStdArgs::stack, EnvironmentStdArgs::stack,
4,926✔
118
                                              EnvironmentStdArgsValues::stack),
4,926✔
119
      make_entry<typeart::TypeSerializationImplementation>(ConfigStdArgs::type_serialization,
4,926✔
120
                                                           EnvironmentStdArgs::type_serialization,
4,926✔
121
                                                           EnvironmentStdArgsValues::type_serialization),
4,926✔
122
      make_entry<ConfigStdArgTypes::stack_lifetime_ty>(
4,926✔
123
          ConfigStdArgs::stack_lifetime, EnvironmentStdArgs::stack_lifetime, EnvironmentStdArgsValues::stack_lifetime),
4,926✔
124
      make_entry<typeart::TypegenImplementation>(ConfigStdArgs::typegen, EnvironmentStdArgs::typegen,
4,926✔
125
                                                 ConfigStdArgValues::typegen),
4,926✔
126
      make_entry<ConfigStdArgTypes::filter_ty>(ConfigStdArgs::filter, EnvironmentStdArgs::filter,
4,926✔
127
                                               EnvironmentStdArgsValues::filter),
4,926✔
128
      make_entry<typeart::analysis::FilterImplementation>(ConfigStdArgs::filter_impl, EnvironmentStdArgs::filter_impl,
4,926✔
129
                                                          ConfigStdArgValues::filter_impl),
4,926✔
130

131
      make_entry<ConfigStdArgTypes::filter_glob_ty>(ConfigStdArgs::filter_glob, EnvironmentStdArgs::filter_glob,
4,926✔
132
                                                    ConfigStdArgValues::filter_glob),
4,926✔
133
      make_entry<ConfigStdArgTypes::filter_glob_deep_ty>(
4,926✔
134
          ConfigStdArgs::filter_glob_deep, EnvironmentStdArgs::filter_glob_deep, ConfigStdArgValues::filter_glob_deep),
4,926✔
135
      make_entry<ConfigStdArgTypes::filter_cg_file_ty>(
4,926✔
136
          ConfigStdArgs::filter_cg_file, EnvironmentStdArgs::filter_cg_file, ConfigStdArgValues::filter_cg_file),
4,926✔
137
      make_entry<ConfigStdArgTypes::analysis_filter_global_ty>(ConfigStdArgs::analysis_filter_global,
4,926✔
138
                                                               EnvironmentStdArgs::analysis_filter_global,
4,926✔
139
                                                               EnvironmentStdArgsValues::analysis_filter_global),
4,926✔
140
      make_entry<ConfigStdArgTypes::analysis_filter_heap_alloc_ty>(
4,926✔
141
          ConfigStdArgs::analysis_filter_heap_alloc, EnvironmentStdArgs::analysis_filter_heap_alloc,
4,926✔
142
          EnvironmentStdArgsValues::analysis_filter_heap_alloc),
4,926✔
143
      make_entry<ConfigStdArgTypes::analysis_filter_pointer_alloc_ty>(
4,926✔
144
          ConfigStdArgs::analysis_filter_pointer_alloc, EnvironmentStdArgs::analysis_filter_pointer_alloc,
4,926✔
145
          EnvironmentStdArgsValues::analysis_filter_pointer_alloc),
4,926✔
146
      make_entry<ConfigStdArgTypes::analysis_filter_alloca_non_array_ty>(
4,926✔
147
          ConfigStdArgs::analysis_filter_alloca_non_array, EnvironmentStdArgs::analysis_filter_alloca_non_array,
4,926✔
148
          EnvironmentStdArgsValues::analysis_filter_alloca_non_array),
4,926✔
149
  };
150

151
  occurence_mapping_ = {
4,926✔
152
      make_occurr_entry(ConfigStdArgs::types, config::EnvironmentStdArgs::types),
4,926✔
153
      make_occurr_entry(ConfigStdArgs::stats, EnvironmentStdArgs::stats),
4,926✔
154
      make_occurr_entry(ConfigStdArgs::heap, EnvironmentStdArgs::heap),
4,926✔
155
      make_occurr_entry(ConfigStdArgs::gpu, EnvironmentStdArgs::gpu),
4,926✔
156
      make_occurr_entry(ConfigStdArgs::global, EnvironmentStdArgs::global),
4,926✔
157
      make_occurr_entry(ConfigStdArgs::stack, EnvironmentStdArgs::stack),
4,926✔
158
      make_occurr_entry(ConfigStdArgs::type_serialization, EnvironmentStdArgs::type_serialization),
4,926✔
159
      make_occurr_entry(ConfigStdArgs::stack_lifetime, EnvironmentStdArgs::stack_lifetime),
4,926✔
160
      make_occurr_entry(ConfigStdArgs::typegen, EnvironmentStdArgs::typegen),
4,926✔
161
      make_occurr_entry(ConfigStdArgs::filter, EnvironmentStdArgs::filter),
4,926✔
162
      make_occurr_entry(ConfigStdArgs::filter_impl, EnvironmentStdArgs::filter_impl),
4,926✔
163
      make_occurr_entry(ConfigStdArgs::filter_glob, EnvironmentStdArgs::filter_glob),
4,926✔
164
      make_occurr_entry(ConfigStdArgs::filter_glob_deep, EnvironmentStdArgs::filter_glob_deep),
4,926✔
165
      make_occurr_entry(ConfigStdArgs::filter_cg_file, EnvironmentStdArgs::filter_cg_file),
4,926✔
166
      make_occurr_entry(ConfigStdArgs::analysis_filter_global, EnvironmentStdArgs::analysis_filter_global),
4,926✔
167
      make_occurr_entry(ConfigStdArgs::analysis_filter_heap_alloc, EnvironmentStdArgs::analysis_filter_heap_alloc),
4,926✔
168
      make_occurr_entry(ConfigStdArgs::analysis_filter_pointer_alloc,
4,926✔
169
                        EnvironmentStdArgs::analysis_filter_pointer_alloc),
170
      make_occurr_entry(ConfigStdArgs::analysis_filter_alloca_non_array,
4,926✔
171
                        EnvironmentStdArgs::analysis_filter_alloca_non_array),
172
  };
173

174
  if (!occurence_mapping_.lookup(ConfigStdArgs::global) && occurence_mapping_.lookup(ConfigStdArgs::stack)) {
4,926✔
175
    const auto stack_value                    = mapping_.lookup(ConfigStdArgs::stack);
831✔
176
    mapping_[ConfigStdArgs::global]           = OptionValue{static_cast<bool>(stack_value)};
831✔
177
    occurence_mapping_[ConfigStdArgs::global] = true;
831✔
178
  }
831✔
179

180
  auto result =
181
      pass::parse_typeart_config_with_occurrence(get_env_flag(EnvironmentStdOptionsArgsValues::option).value_or(""));
4,926✔
182
  if (!result.first) {
4,926✔
183
    LOG_INFO("No parseable " << EnvironmentStdOptionsArgsValues::option << ": " << result.first.takeError())
×
UNCOV
184
  } else {
×
185
    LOG_DEBUG("Parsed " << EnvironmentStdOptionsArgsValues::option << "\n" << *result.first)
186
    merge_mapping_with_passconfig(mapping_, occurence_mapping_, result);
4,926✔
187
  }
188
}
4,926✔
189

190
void EnvironmentFlagsOptions::parsePhaseEnvFlags(const Phase& phase) {
4,926✔
191
  if (phase.heap) {
4,926✔
192
    auto result = pass::parse_typeart_config_with_occurrence(
3,395✔
193
        get_env_flag(EnvironmentStdOptionsArgsValues::option_heap).value_or(""));
3,395✔
194
    if (result.first) {
3,395✔
195
      LOG_DEBUG("Parsing " << EnvironmentStdOptionsArgsValues::option_heap)
196
      detail::merge_mapping_with_passconfig(mapping_, occurence_mapping_, result);
3,395✔
197
    }
3,395✔
198
  }
3,395✔
199

200
  if (phase.stack) {
4,926✔
201
    auto result = pass::parse_typeart_config_with_occurrence(
1,549✔
202
        get_env_flag(EnvironmentStdOptionsArgsValues::option_stack).value_or(""));
1,549✔
203
    if (result.first) {
1,549✔
204
      LOG_DEBUG("Parsing " << EnvironmentStdOptionsArgsValues::option_stack)
205
      detail::merge_mapping_with_passconfig(mapping_, occurence_mapping_, result);
1,549✔
206
    }
1,549✔
207
  }
1,549✔
208
}
4,926✔
209

210
std::optional<typeart::config::OptionValue> EnvironmentFlagsOptions::getValue(std::string_view opt_path) const {
381,472✔
211
  auto key = llvm::StringRef(opt_path.data());
381,472✔
212
  if (occurence_mapping_.lookup(key)) {  // only have value if it occurred
381,472✔
213
    return mapping_.lookup(key);
22,487✔
214
  }
215
  return {};
358,985✔
216
}
381,472✔
217

218
[[maybe_unused]] bool EnvironmentFlagsOptions::valueSpecified(std::string_view opt_path) const {
×
219
  auto key = llvm::StringRef(opt_path.data());
×
UNCOV
220
  return occurence_mapping_.lookup(key);
×
221
}
222

223
}  // namespace typeart::config::env
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