Skip to content

[scudo] Group type traits into a single header (NFC) #118888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler-rt/lib/scudo/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ set(SCUDO_HEADERS
tsd_exclusive.h
tsd_shared.h
tsd.h
type_traits.h
vector.h
wrappers_c_checks.h
wrappers_c.h
Expand Down
30 changes: 1 addition & 29 deletions compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,7 @@
#include "condition_variable.h"
#include "internal_defs.h"
#include "secondary.h"

namespace {

template <typename T> struct removeConst {
using type = T;
};
template <typename T> struct removeConst<const T> {
using type = T;
};

// This is only used for SFINAE when detecting if a type is defined.
template <typename T> struct voidAdaptor {
using type = void;
};

// This is used for detecting the case that defines the flag with wrong type and
// it'll be viewed as undefined optional flag.
template <typename L, typename R> struct assertSameType {
template <typename, typename> struct isSame {
static constexpr bool value = false;
};
template <typename T> struct isSame<T, T> {
static constexpr bool value = true;
};
static_assert(isSame<L, R>::value, "Flag type mismatches");
using type = R;
};

} // namespace
#include "type_traits.h"

namespace scudo {

Expand Down
12 changes: 1 addition & 11 deletions compiler-rt/lib/scudo/standalone/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@
#define SCUDO_LIST_H_

#include "internal_defs.h"

// TODO: Move the helpers to a header.
namespace {
template <typename T> struct isPointer {
static constexpr bool value = false;
};

template <typename T> struct isPointer<T *> {
static constexpr bool value = true;
};
} // namespace
#include "type_traits.h"

namespace scudo {

Expand Down
47 changes: 47 additions & 0 deletions compiler-rt/lib/scudo/standalone/type_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===-- type_traits.h -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef SCUDO_TYPE_TRAITS_H_
#define SCUDO_TYPE_TRAITS_H_

namespace scudo {

template <typename T> struct removeConst {
using type = T;
};
template <typename T> struct removeConst<const T> {
using type = T;
};

// This is only used for SFINAE when detecting if a type is defined.
template <typename T> struct voidAdaptor {
using type = void;
};

template <typename L, typename R> struct assertSameType {
template <typename, typename> struct isSame {
static constexpr bool value = false;
};
template <typename T> struct isSame<T, T> {
static constexpr bool value = true;
};
static_assert(isSame<L, R>::value, "Type mismatches");
using type = R;
};

template <typename T> struct isPointer {
static constexpr bool value = false;
};

template <typename T> struct isPointer<T *> {
static constexpr bool value = true;
};

} // namespace scudo

#endif // SCUDO_TYPE_TRAITS_H_
Loading