Coverage Report

Created: 2026-10-09 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/arena.h
Line
Count
Source
1
// Copyright 2024 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef THIRD_PARTY_CEL_CPP_COMMON_ARENA_H_
16
#define THIRD_PARTY_CEL_CPP_COMMON_ARENA_H_
17
18
#include <type_traits>
19
#include <utility>
20
21
#include "absl/base/nullability.h"
22
#include "google/protobuf/arena.h"
23
24
namespace cel {
25
26
template <typename T = void>
27
struct ArenaTraits;
28
29
namespace common_internal {
30
31
template <typename T>
32
struct AssertArenaType : std::false_type {
33
  static_assert(!std::is_void_v<T>, "T must not be void");
34
  static_assert(!std::is_reference_v<T>, "T must not be a reference");
35
  static_assert(!std::is_volatile_v<T>, "T must not be volatile qualified");
36
  static_assert(!std::is_const_v<T>, "T must not be const qualified");
37
  static_assert(!std::is_array_v<T>, "T must not be an array");
38
};
39
40
template <typename, typename = void>
41
struct ArenaTraitsConstructible {
42
  using type = std::false_type;
43
};
44
45
template <typename T>
46
struct ArenaTraitsConstructible<
47
    T, std::void_t<decltype(ArenaTraits<T>::constructible)>> {
48
  using type = typename ArenaTraits<T>::constructible;
49
};
50
51
template <typename T>
52
std::enable_if_t<google::protobuf::Arena::is_arena_constructable<T>::value,
53
                 google::protobuf::Arena* absl_nullable>
54
GetArena(const T* absl_nullable ptr) {
55
  return ptr != nullptr ? ptr->GetArena() : nullptr;
56
}
57
58
template <typename T>
59
std::enable_if_t<!google::protobuf::Arena::is_arena_constructable<T>::value,
60
                 google::protobuf::Arena* absl_nullable>
61
GetArena([[maybe_unused]] const T* absl_nullable ptr) {
62
  return nullptr;
63
}
64
65
template <typename, typename = void>
66
struct HasArenaTraitsTriviallyDestructible : std::false_type {};
67
68
template <typename T>
69
struct HasArenaTraitsTriviallyDestructible<
70
    T, std::void_t<decltype(ArenaTraits<T>::trivially_destructible(
71
           std::declval<const T&>()))>> : std::true_type {};
72
73
}  // namespace common_internal
74
75
template <>
76
struct ArenaTraits<void> {
77
  template <typename U>
78
  using constructible = std::disjunction<
79
      typename common_internal::AssertArenaType<U>::type,
80
      typename common_internal::ArenaTraitsConstructible<U>::type>;
81
82
  template <typename U>
83
  using always_trivially_destructible =
84
      std::disjunction<typename common_internal::AssertArenaType<U>::type,
85
                       std::is_trivially_destructible<U>>;
86
87
  template <typename U>
88
20.2M
  static bool trivially_destructible(const U& obj) {
89
20.2M
    static_assert(!std::is_void_v<U>, "T must not be void");
90
20.2M
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
20.2M
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
20.2M
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
20.2M
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
20.2M
    if constexpr (always_trivially_destructible<U>()) {
96
10.1M
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
10.1M
                             U>::value) {
101
10.1M
      return ArenaTraits<U>::trivially_destructible(obj);
102
10.1M
    } else {
103
0
      return false;
104
0
    }
105
20.2M
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<std::__1::monostate>(std::__1::monostate const&)
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::ParsedMessageValue>(cel::ParsedMessageValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::NullValue>(cel::NullValue const&)
Line
Count
Source
88
1.92k
  static bool trivially_destructible(const U& obj) {
89
1.92k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
1.92k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
1.92k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
1.92k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
1.92k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
1.92k
    if constexpr (always_trivially_destructible<U>()) {
96
1.92k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
1.92k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::BoolValue>(cel::BoolValue const&)
Line
Count
Source
88
630k
  static bool trivially_destructible(const U& obj) {
89
630k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
630k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
630k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
630k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
630k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
630k
    if constexpr (always_trivially_destructible<U>()) {
96
630k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
630k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::IntValue>(cel::IntValue const&)
Line
Count
Source
88
8.32M
  static bool trivially_destructible(const U& obj) {
89
8.32M
    static_assert(!std::is_void_v<U>, "T must not be void");
90
8.32M
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
8.32M
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
8.32M
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
8.32M
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
8.32M
    if constexpr (always_trivially_destructible<U>()) {
96
8.32M
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
8.32M
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::UintValue>(cel::UintValue const&)
Line
Count
Source
88
254k
  static bool trivially_destructible(const U& obj) {
89
254k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
254k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
254k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
254k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
254k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
254k
    if constexpr (always_trivially_destructible<U>()) {
96
254k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
254k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::DoubleValue>(cel::DoubleValue const&)
Line
Count
Source
88
354k
  static bool trivially_destructible(const U& obj) {
89
354k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
354k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
354k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
354k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
354k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
354k
    if constexpr (always_trivially_destructible<U>()) {
96
354k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
354k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::DurationValue>(cel::DurationValue const&)
Line
Count
Source
88
27.7k
  static bool trivially_destructible(const U& obj) {
89
27.7k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
27.7k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
27.7k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
27.7k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
27.7k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
27.7k
    if constexpr (always_trivially_destructible<U>()) {
96
27.7k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
27.7k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::TimestampValue>(cel::TimestampValue const&)
Line
Count
Source
88
2.45k
  static bool trivially_destructible(const U& obj) {
89
2.45k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
2.45k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
2.45k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
2.45k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
2.45k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
2.45k
    if constexpr (always_trivially_destructible<U>()) {
96
2.45k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
2.45k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::TypeValue>(cel::TypeValue const&)
Line
Count
Source
88
4.49k
  static bool trivially_destructible(const U& obj) {
89
4.49k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
4.49k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
4.49k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
4.49k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
4.49k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
4.49k
    if constexpr (always_trivially_destructible<U>()) {
96
4.49k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
4.49k
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::common_internal::LegacyListValue>(cel::common_internal::LegacyListValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::ParsedJsonListValue>(cel::ParsedJsonListValue const&)
Line
Count
Source
88
2.64k
  static bool trivially_destructible(const U& obj) {
89
2.64k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
2.64k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
2.64k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
2.64k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
2.64k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
2.64k
    if constexpr (always_trivially_destructible<U>()) {
96
2.64k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
2.64k
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::ParsedRepeatedFieldValue>(cel::ParsedRepeatedFieldValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::CustomListValue>(cel::CustomListValue const&)
Line
Count
Source
88
57.2k
  static bool trivially_destructible(const U& obj) {
89
57.2k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
57.2k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
57.2k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
57.2k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
57.2k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
57.2k
    if constexpr (always_trivially_destructible<U>()) {
96
57.2k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
57.2k
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::common_internal::LegacyMapValue>(cel::common_internal::LegacyMapValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::ParsedJsonMapValue>(cel::ParsedJsonMapValue const&)
Line
Count
Source
88
535
  static bool trivially_destructible(const U& obj) {
89
535
    static_assert(!std::is_void_v<U>, "T must not be void");
90
535
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
535
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
535
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
535
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
535
    if constexpr (always_trivially_destructible<U>()) {
96
535
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
535
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::ParsedMapFieldValue>(cel::ParsedMapFieldValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::CustomMapValue>(cel::CustomMapValue const&)
Line
Count
Source
88
114k
  static bool trivially_destructible(const U& obj) {
89
114k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
114k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
114k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
114k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
114k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
114k
    if constexpr (always_trivially_destructible<U>()) {
96
114k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
114k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::common_internal::LegacyStructValue>(cel::common_internal::LegacyStructValue const&)
Line
Count
Source
88
29.3k
  static bool trivially_destructible(const U& obj) {
89
29.3k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
29.3k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
29.3k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
29.3k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
29.3k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
29.3k
    if constexpr (always_trivially_destructible<U>()) {
96
29.3k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
29.3k
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::CustomStructValue>(cel::CustomStructValue const&)
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::OpaqueValue>(cel::OpaqueValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::BytesValue>(cel::BytesValue const&)
Line
Count
Source
88
5.29k
  static bool trivially_destructible(const U& obj) {
89
5.29k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
5.29k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
5.29k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
5.29k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
5.29k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
5.29k
    if constexpr (always_trivially_destructible<U>()) {
96
5.29k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
5.29k
  }
bool cel::ArenaTraits<void>::trivially_destructible<cel::StringValue>(cel::StringValue const&)
Line
Count
Source
88
321k
  static bool trivially_destructible(const U& obj) {
89
321k
    static_assert(!std::is_void_v<U>, "T must not be void");
90
321k
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
321k
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
321k
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
321k
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
321k
    if constexpr (always_trivially_destructible<U>()) {
96
321k
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
                             U>::value) {
101
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
321k
  }
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::ErrorValue>(cel::ErrorValue const&)
Unexecuted instantiation: bool cel::ArenaTraits<void>::trivially_destructible<cel::UnknownValue>(cel::UnknownValue const&)
bool cel::ArenaTraits<void>::trivially_destructible<cel::Value>(cel::Value const&)
Line
Count
Source
88
10.1M
  static bool trivially_destructible(const U& obj) {
89
10.1M
    static_assert(!std::is_void_v<U>, "T must not be void");
90
10.1M
    static_assert(!std::is_reference_v<U>, "T must not be a reference");
91
10.1M
    static_assert(!std::is_volatile_v<U>, "T must not be volatile qualified");
92
10.1M
    static_assert(!std::is_const_v<U>, "T must not be const qualified");
93
10.1M
    static_assert(!std::is_array_v<U>, "T must not be an array");
94
95
    if constexpr (always_trivially_destructible<U>()) {
96
      return true;
97
    } else if constexpr (google::protobuf::Arena::is_destructor_skippable<U>::value) {
98
      return obj.GetArena() != nullptr;
99
    } else if constexpr (common_internal::HasArenaTraitsTriviallyDestructible<
100
10.1M
                             U>::value) {
101
10.1M
      return ArenaTraits<U>::trivially_destructible(obj);
102
    } else {
103
      return false;
104
    }
105
10.1M
  }
106
};
107
108
}  // namespace cel
109
110
#endif  // THIRD_PARTY_CEL_CPP_COMMON_ARENA_H_