[compiler-rt] 0518135 - [NFC][sanitizer] Move ArrayRef into own header

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 12 15:24:49 PDT 2023


Author: Vitaly Buka
Date: 2023-06-12T15:24:35-07:00
New Revision: 05181357ac951cebac374111d9faae56b9b8e20f

URL: https://github.com/llvm/llvm-project/commit/05181357ac951cebac374111d9faae56b9b8e20f
DIFF: https://github.com/llvm/llvm-project/commit/05181357ac951cebac374111d9faae56b9b8e20f.diff

LOG: [NFC][sanitizer] Move ArrayRef into own header

Added: 
    compiler-rt/lib/sanitizer_common/sanitizer_array_ref.h

Modified: 
    compiler-rt/lib/hwasan/hwasan_globals.cpp
    compiler-rt/lib/hwasan/hwasan_globals.h
    compiler-rt/lib/hwasan/hwasan_report.cpp
    compiler-rt/lib/memprof/memprof_allocator.cpp
    compiler-rt/lib/memprof/memprof_rawprofile.cpp
    compiler-rt/lib/memprof/memprof_rawprofile.h
    compiler-rt/lib/memprof/tests/rawprofile.cpp
    compiler-rt/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/lib/sanitizer_common/sanitizer_common_range.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_common_range.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_globals.cpp b/compiler-rt/lib/hwasan/hwasan_globals.cpp
index d71bcd792e1f9..7e0f3df20dd05 100644
--- a/compiler-rt/lib/hwasan/hwasan_globals.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_globals.cpp
@@ -13,6 +13,8 @@
 
 #include "hwasan_globals.h"
 
+#include "sanitizer_common/sanitizer_array_ref.h"
+
 namespace __hwasan {
 
 enum { NT_LLVM_HWASAN_GLOBALS = 3 };

diff  --git a/compiler-rt/lib/hwasan/hwasan_globals.h b/compiler-rt/lib/hwasan/hwasan_globals.h
index fd7adf7a05880..94cd53e1888cd 100644
--- a/compiler-rt/lib/hwasan/hwasan_globals.h
+++ b/compiler-rt/lib/hwasan/hwasan_globals.h
@@ -16,6 +16,7 @@
 
 #include <link.h>
 
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_internal_defs.h"
 

diff  --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 935bae3e7bf79..efe6f57704919 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -22,6 +22,7 @@
 #include "hwasan_thread.h"
 #include "hwasan_thread_list.h"
 #include "sanitizer_common/sanitizer_allocator_internal.h"
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_mutex.h"

diff  --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index 4b68f21272844..5fbc27283f4bc 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -23,6 +23,7 @@
 #include "sanitizer_common/sanitizer_allocator_checks.h"
 #include "sanitizer_common/sanitizer_allocator_interface.h"
 #include "sanitizer_common/sanitizer_allocator_report.h"
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_errno.h"
 #include "sanitizer_common/sanitizer_file.h"

diff  --git a/compiler-rt/lib/memprof/memprof_rawprofile.cpp b/compiler-rt/lib/memprof/memprof_rawprofile.cpp
index 1a65fbbf6b1e2..fa92fa0e4b53e 100644
--- a/compiler-rt/lib/memprof/memprof_rawprofile.cpp
+++ b/compiler-rt/lib/memprof/memprof_rawprofile.cpp
@@ -5,6 +5,7 @@
 #include "memprof_rawprofile.h"
 #include "profile/MemProfData.inc"
 #include "sanitizer_common/sanitizer_allocator_internal.h"
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_linux.h"
 #include "sanitizer_common/sanitizer_procmaps.h"

diff  --git a/compiler-rt/lib/memprof/memprof_rawprofile.h b/compiler-rt/lib/memprof/memprof_rawprofile.h
index a4e9fd4232b5d..e2494175f165e 100644
--- a/compiler-rt/lib/memprof/memprof_rawprofile.h
+++ b/compiler-rt/lib/memprof/memprof_rawprofile.h
@@ -2,6 +2,7 @@
 #define MEMPROF_RAWPROFILE_H_
 
 #include "memprof_mibmap.h"
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 
 namespace __memprof {

diff  --git a/compiler-rt/lib/memprof/tests/rawprofile.cpp b/compiler-rt/lib/memprof/tests/rawprofile.cpp
index 0637ed914058d..c5dfdca890be9 100644
--- a/compiler-rt/lib/memprof/tests/rawprofile.cpp
+++ b/compiler-rt/lib/memprof/tests/rawprofile.cpp
@@ -4,6 +4,7 @@
 #include <memory>
 
 #include "profile/MemProfData.inc"
+#include "sanitizer_common/sanitizer_array_ref.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_procmaps.h"
 #include "sanitizer_common/sanitizer_stackdepot.h"

diff  --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
index c14c66a8cf343..9002106b8b07a 100644
--- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -114,6 +114,7 @@ set(SANITIZER_IMPL_HEADERS
   sanitizer_allocator_secondary.h
   sanitizer_allocator_size_class_map.h
   sanitizer_allocator_stats.h
+  sanitizer_array_ref.h
   sanitizer_asm.h
   sanitizer_atomic.h
   sanitizer_atomic_clang.h

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_array_ref.h b/compiler-rt/lib/sanitizer_common/sanitizer_array_ref.h
new file mode 100644
index 0000000000000..d19c46d031525
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_array_ref.h
@@ -0,0 +1,50 @@
+//===-- sanitizer_array_ref.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 SANITIZER_ARRAY_REF_H
+#define SANITIZER_ARRAY_REF_H
+
+#include "sanitizer_internal_defs.h"
+
+namespace __sanitizer {
+
+/// ArrayRef - Represent a constant reference to an array (0 or more elements
+/// consecutively in memory), i.e. a start pointer and a length.  It allows
+/// various APIs to take consecutive elements easily and conveniently.
+///
+/// This class does not own the underlying data, it is expected to be used in
+/// situations where the data resides in some other buffer, whose lifetime
+/// extends past that of the ArrayRef. For this reason, it is not in general
+/// safe to store an ArrayRef.
+///
+/// This is intended to be trivially copyable, so it should be passed by
+/// value.
+template <typename T>
+class ArrayRef {
+ public:
+  ArrayRef() {}
+  ArrayRef(const T *begin, const T *end) : begin_(begin), end_(end) {}
+
+  template <typename C>
+  ArrayRef(const C &src) : ArrayRef(src.data(), src.data() + src.size()) {}
+
+  const T *begin() const { return begin_; }
+  const T *end() const { return end_; }
+
+  bool empty() const { return begin_ == end_; }
+
+  uptr size() const { return end_ - begin_; }
+
+ private:
+  const T *begin_ = nullptr;
+  const T *end_ = nullptr;
+};
+
+}  // namespace __sanitizer
+
+#endif  // SANITIZER_ARRAY_REF_H

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index b2755833263dd..7c2564487c5d2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -1083,27 +1083,6 @@ inline u32 GetNumberOfCPUsCached() {
   return NumberOfCPUsCached;
 }
 
-template <typename T>
-class ArrayRef {
- public:
-  ArrayRef() {}
-  ArrayRef(const T *begin, const T *end) : begin_(begin), end_(end) {}
-
-  template <typename C>
-  ArrayRef(const C &src) : ArrayRef(src.data(), src.data() + src.size()) {}
-
-  const T *begin() const { return begin_; }
-  const T *end() const { return end_; }
-
-  bool empty() const { return begin_ == end_; }
-
-  uptr size() const { return end_ - begin_; }
-
- private:
-  const T *begin_ = nullptr;
-  const T *end_ = nullptr;
-};
-
 }  // namespace __sanitizer
 
 inline void *operator new(__sanitizer::operator_new_size_type size,

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_range.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_range.cpp
index fcdb928a33b4c..f500928eace96 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_range.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_range.cpp
@@ -8,6 +8,8 @@
 
 #include "sanitizer_common_range.h"
 
+#include "sanitizer_common/sanitizer_array_ref.h"
+
 namespace __sanitizer {
 
 void Intersect(ArrayRef<Range> a, ArrayRef<Range> b,

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_range.h b/compiler-rt/lib/sanitizer_common/sanitizer_common_range.h
index 76e3d04b2cebb..e43c6d1c85712 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_range.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_range.h
@@ -14,6 +14,7 @@
 #define SANITIZER_COMMON_REGION_H
 
 #include "sanitizer_common.h"
+#include "sanitizer_common/sanitizer_array_ref.h"
 
 namespace __sanitizer {
 


        


More information about the llvm-commits mailing list