-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: None (ChiaHungDuan) ChangesFull diff: https://github.com/llvm/llvm-project/pull/118888.diff 4 Files Affected:
diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index dc700cec9becbf..3f9ae866a75533 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -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
diff --git a/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h b/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
index 5477236ac1f397..ea12a5b1447f69 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
@@ -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 {
diff --git a/compiler-rt/lib/scudo/standalone/list.h b/compiler-rt/lib/scudo/standalone/list.h
index c6bd32a8fa3251..5c34cbb049e602 100644
--- a/compiler-rt/lib/scudo/standalone/list.h
+++ b/compiler-rt/lib/scudo/standalone/list.h
@@ -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 {
diff --git a/compiler-rt/lib/scudo/standalone/type_traits.h b/compiler-rt/lib/scudo/standalone/type_traits.h
new file mode 100644
index 00000000000000..86aa0431df4347
--- /dev/null
+++ b/compiler-rt/lib/scudo/standalone/type_traits.h
@@ -0,0 +1,49 @@
+//===-- 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;
+};
+
+// 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;
+};
+
+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_
|
Pushed another dependent change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One very small comment nit.
using type = void; | ||
}; | ||
|
||
// This is used for detecting the case that defines the flag with wrong type and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a copy of the previous comment, but it is worded a bit awkwardly. Perhaps it could be something like:
Used for detecting cases that define the flag with the wrong type, which will lead to an undefined optional flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is moved to an independent file and I think the class name is self-explained so I just remove the comment and updated the description of static_assert to "Type mismatches" (it was "Flag type mismatches").
ee9a84f
to
d64b229
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It seems that I can't submit them separately. I'll push them one by one instead. |
d64b229
to
4b62583
Compare
The follow up change is here, #119323 |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/4031 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1690 Here is the relevant piece of the build log for the reference
|
No description provided.