Skip to content

[ArrayRef] Provide constructors from any type with a data() member #145735

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
Jun 25, 2025

Conversation

d0k
Copy link
Member

@d0k d0k commented Jun 25, 2025

The assumption here is that if data() returns a pointer and size()
exists it's something representing contiguous storage.

Modeled after the behavior of C++20 std::span and enables two-way
conversion between std::span (or really any span-like type) and
ArrayRef. Add a unit test that verifies this if std::span is around.

This also means we can get rid of specific conversions for std::vector
and SmallVector.

The assumption here is that if data() returns a pointer and size()
exists this is something representing a contiguous storage.

This is modeled after the behavior of C++20 std::span and enables
two-way conversion between std::span (or really any span-like type)
and ArrayRef. Add a unit test that verifies this if std::span is around.

This also means we can get rid of specific conversions for std::vector
and SmallVector.
@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-llvm-adt

Author: Benjamin Kramer (d0k)

Changes

The assumption here is that if data() returns a pointer and size()
exists it's something representing contiguous storage.

Modeled after the behavior of C++20 std::span and enables two-way
conversion between std::span (or really any span-like type) and
ArrayRef. Add a unit test that verifies this if std::span is around.

This also means we can get rid of specific conversions for std::vector
and SmallVector.


Full diff: https://github.com/llvm/llvm-project/pull/145735.diff

2 Files Affected:

  • (modified) llvm/include/llvm/ADT/ArrayRef.h (+13-38)
  • (modified) llvm/unittests/ADT/ArrayRefTest.cpp (+18-1)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 4819c88471345..ddd2c7ce68c83 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -84,18 +84,19 @@ namespace llvm {
       assert(begin <= end);
     }
 
-    /// Construct an ArrayRef from a SmallVector. This is templated in order to
-    /// avoid instantiating SmallVectorTemplateCommon<T> whenever we
-    /// copy-construct an ArrayRef.
-    template<typename U>
-    /*implicit*/ ArrayRef(const SmallVectorTemplateCommon<T, U> &Vec)
-      : Data(Vec.data()), Length(Vec.size()) {
-    }
-
-    /// Construct an ArrayRef from a std::vector.
-    template<typename A>
-    /*implicit*/ ArrayRef(const std::vector<T, A> &Vec)
-      : Data(Vec.data()), Length(Vec.size()) {}
+    /// Construct an ArrayRef from a type that has a data() method that returns
+    /// a pointer convertible to const T *.
+    template <
+        typename C,
+        typename = std::enable_if_t<
+            std::conjunction_v<
+                std::is_convertible<
+                    decltype(std::declval<const C &>().data()) *,
+                    const T *const *>,
+                std::is_integral<decltype(std::declval<const C &>().size())>>,
+            void>>
+    /*implicit*/ constexpr ArrayRef(const C &V)
+        : Data(V.data()), Length(V.size()) {}
 
     /// Construct an ArrayRef from a std::array
     template <size_t N>
@@ -123,32 +124,6 @@ namespace llvm {
 #pragma GCC diagnostic pop
 #endif
 
-    /// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
-    /// ensure that only ArrayRefs of pointers can be converted.
-    template <typename U>
-    ArrayRef(const ArrayRef<U *> &A,
-             std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
-                 * = nullptr)
-        : Data(A.data()), Length(A.size()) {}
-
-    /// Construct an ArrayRef<const T*> from a SmallVector<T*>. This is
-    /// templated in order to avoid instantiating SmallVectorTemplateCommon<T>
-    /// whenever we copy-construct an ArrayRef.
-    template <typename U, typename DummyT>
-    /*implicit*/ ArrayRef(
-        const SmallVectorTemplateCommon<U *, DummyT> &Vec,
-        std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =
-            nullptr)
-        : Data(Vec.data()), Length(Vec.size()) {}
-
-    /// Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE
-    /// to ensure that only vectors of pointers can be converted.
-    template <typename U, typename A>
-    ArrayRef(const std::vector<U *, A> &Vec,
-             std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
-                 * = nullptr)
-        : Data(Vec.data()), Length(Vec.size()) {}
-
     /// Construct an ArrayRef<T> from iterator_range<U*>. This uses SFINAE
     /// to ensure that this is only used for iterator ranges over plain pointer
     /// iterators.
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index 39a4a9b6a178c..3858d9064f9ca 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -8,10 +8,16 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Allocator.h"
-#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include <limits>
 #include <vector>
+#if __has_include(<version>)
+#include <version>
+#endif
+#ifdef __cpp_lib_span
+#include <span>
+#endif
+
 using namespace llvm;
 
 // Check that the ArrayRef-of-pointer converting constructor only allows adding
@@ -406,4 +412,15 @@ TEST(ArrayRefTest, MutableArrayRefDeductionGuides) {
   }
 }
 
+#ifdef __cpp_lib_span
+static_assert(std::is_constructible_v<ArrayRef<int>, std::span<const int>>,
+              "should be able to construct ArrayRef from const std::span");
+static_assert(std::is_constructible_v<std::span<const int>, ArrayRef<int>>,
+              "should be able to construct const std::span from ArrayRef");
+static_assert(std::is_constructible_v<ArrayRef<int>, std::span<int>>,
+              "should be able to construct ArrayRef from mutable std::span");
+static_assert(!std::is_constructible_v<std::span<int>, ArrayRef<int>>,
+              "cannot construct mutable std::span from ArrayRef");
+#endif
+
 } // end anonymous namespace

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is a great cleanup/generalization. Thanks!

@d0k d0k merged commit 0556a2a into llvm:main Jun 25, 2025
8 of 9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 25, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/18011

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/4/12 (3293 of 3302)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/5/12 (3294 of 3302)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/6/12 (3295 of 3302)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/7/12 (3296 of 3302)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/8/12 (3297 of 3302)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/9/12 (3298 of 3302)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/0/2 (3299 of 3302)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/1/2 (3300 of 3302)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests/8/35 (3301 of 3302)
TIMEOUT: lldb-api :: tools/lldb-dap/module/TestDAP_module.py (3302 of 3302)
******************** TEST 'lldb-api :: tools/lldb-dap/module/TestDAP_module.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --cmake-build-type Release /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/module -p TestDAP_module.py
--
Exit Code: -9
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee)
  clang revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee
  llvm revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee

--
Command Output (stderr):
--
========= DEBUG ADAPTER PROTOCOL LOGS =========
1750875041.538094282 (stdio) --> {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1}
1750875041.543262482 (stdio) <-- {"body":{"$__lldb_version":"lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee)\n  clang revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee\n  llvm revision 0556a2aa187b86c28a9441aec3e98b9780a2c9ee","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"description":"C++ Catch","filter":"cpp_catch","label":"C++ Catch","supportsCondition":true},{"description":"C++ Throw","filter":"cpp_throw","label":"C++ Throw","supportsCondition":true},{"description":"Objective-C Catch","filter":"objc_catch","label":"Objective-C Catch","supportsCondition":true},{"description":"Objective-C Throw","filter":"objc_throw","label":"Objective-C Throw","supportsCondition":true}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsSetVariable":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}
1750875041.545044661 (stdio) --> {"command":"launch","type":"request","arguments":{"program":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/module/TestDAP_module.test_compile_units/a.out","initCommands":["settings clear --all","settings set symbols.enable-external-lookup false","settings set target.inherit-tcc true","settings set target.disable-aslr false","settings set target.detach-on-error false","settings set target.auto-apply-fixits false","settings set plugin.process.gdb-remote.packet-timeout 60","settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"","settings set use-color false","settings set show-statusline false"],"disableASLR":false,"enableAutoVariableSummaries":false,"enableSyntheticChildDebugging":false,"displayExtendedBacktrace":false},"seq":2}
1750875041.545718670 (stdio) <-- {"body":{"category":"console","output":"Running initCommands:\n"},"event":"output","seq":0,"type":"event"}
1750875041.545783758 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings clear --all\n"},"event":"output","seq":0,"type":"event"}
1750875041.545799017 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set symbols.enable-external-lookup false\n"},"event":"output","seq":0,"type":"event"}
1750875041.545811653 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.inherit-tcc true\n"},"event":"output","seq":0,"type":"event"}
1750875041.545823336 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.disable-aslr false\n"},"event":"output","seq":0,"type":"event"}
1750875041.545835018 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.detach-on-error false\n"},"event":"output","seq":0,"type":"event"}
1750875041.545846462 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.auto-apply-fixits false\n"},"event":"output","seq":0,"type":"event"}
1750875041.545859098 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set plugin.process.gdb-remote.packet-timeout 60\n"},"event":"output","seq":0,"type":"event"}
1750875041.545893908 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"\n"},"event":"output","seq":0,"type":"event"}
1750875041.545907259 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set use-color false\n"},"event":"output","seq":0,"type":"event"}
1750875041.545919657 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set show-statusline false\n"},"event":"output","seq":0,"type":"event"}
1750875041.694500923 (stdio) <-- {"command":"launch","request_seq":2,"seq":0,"success":true,"type":"response"}
1750875041.694586277 (stdio) <-- {"body":{"module":{"addressRange":"0xf7f75000","debugInfoSize":"983.3KB","id":"0D794E6C-AF7E-D8CB-B9BA-E385B4F8753F-5A793D65","name":"ld-linux-armhf.so.3","path":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolFilePath":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":0,"type":"event"}
1750875041.694676399 (stdio) <-- {"event":"initialized","seq":0,"type":"event"}
1750875041.694900751 (stdio) <-- {"body":{"module":{"addressRange":"0x980000","debugInfoSize":"1.1KB","id":"F56A2349","name":"a.out","path":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/module/TestDAP_module.test_compile_units/a.out","symbolFilePath":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/module/TestDAP_module.test_compile_units/a.out","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":0,"type":"event"}
1750875041.695603609 (stdio) --> {"command":"setBreakpoints","type":"request","arguments":{"source":{"name":"main.cpp","path":"main.cpp"},"sourceModified":false,"lines":[5],"breakpoints":[{"line":5}]},"seq":3}
1750875041.708957195 (stdio) <-- {"body":{"breakpoints":[{"column":3,"id":1,"instructionReference":"0x99073C","line":5,"source":{"name":"main.cpp","path":"main.cpp"},"verified":true}]},"command":"setBreakpoints","request_seq":3,"seq":0,"success":true,"type":"response"}
1750875041.709481716 (stdio) --> {"command":"configurationDone","type":"request","arguments":{},"seq":4}

@d0k d0k deleted the arrayref branch June 25, 2025 18:40
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 26, 2025

LLVM Buildbot has detected a new failure on builder bolt-x86_64-ubuntu-nfc running on bolt-worker while building llvm at step 7 "build-bolt".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/92/builds/21259

Here is the relevant piece of the build log for the reference
Step 7 (build-bolt) failure: build (failure)
...
  512 |   DenseSet<uint64_t> DebugStrOffsetFinalized;
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
592.460 [134/18/1859] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStub.cpp.o
592.618 [133/18/1860] Linking CXX static library lib/libLLVMTextAPI.a
592.673 [132/18/1861] Building CXX object tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/FunctionLayout.cpp.o
593.720 [131/18/1862] Building CXX object lib/Target/RISCV/CMakeFiles/LLVMRISCVCodeGen.dir/GISel/RISCVInstructionSelector.cpp.o
594.017 [130/18/1863] Building CXX object lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLParser.cpp.o
594.144 [129/18/1864] Linking CXX static library lib/libLLVMAsmParser.a
594.276 [128/18/1865] Linking CXX static library lib/libLLVMIRReader.a
594.298 [127/18/1866] Building CXX object tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinarySection.cpp.o
FAILED: tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinarySection.cpp.o 
ccache /usr/bin/c++ -DCMAKE_INSTALL_FULL_LIBDIR=\"/usr/local/lib\" -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/build/tools/bolt/lib/Core -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/build/include -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/llvm/include -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include -I/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/build/tools/bolt/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinarySection.cpp.o -MF tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinarySection.cpp.o.d -o tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinarySection.cpp.o -c /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinarySection.cpp
In file included from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinarySection.cpp:13:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/DebugData.h:512:22: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  512 |   DenseSet<uint64_t> DebugStrOffsetFinalized;
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinarySection.cpp: In member function ‘void llvm::bolt::BinarySection::reorderContents(const std::vector<llvm::bolt::BinaryData*>&, bool)’:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinarySection.cpp:298:57: error: call of overloaded ‘copyByteArray(std::string&)’ is ambiguous
  298 |   auto *NewData = reinterpret_cast<char *>(copyByteArray(OS.str()));
      |                                            ~~~~~~~~~~~~~^~~~~~~~~~
In file included from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinarySection.cpp:13:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:526:17: note: candidate: ‘uint8_t* llvm::bolt::copyByteArray(llvm::StringRef)’
  526 | inline uint8_t *copyByteArray(StringRef Buffer) {
      |                 ^~~~~~~~~~~~~
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:531:17: note: candidate: ‘uint8_t* llvm::bolt::copyByteArray(llvm::ArrayRef<char>)’
  531 | inline uint8_t *copyByteArray(ArrayRef<char> Buffer) {
      |                 ^~~~~~~~~~~~~
594.552 [127/17/1867] Linking CXX static library lib/libLLVMObject.a
594.888 [127/16/1868] Building CXX object tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/AddressMap.cpp.o
In file included from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinaryContext.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/AddressMap.cpp:10:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/DebugData.h:512:22: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  512 |   DenseSet<uint64_t> DebugStrOffsetFinalized;
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
595.358 [127/15/1869] Building CXX object tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinaryBasicBlock.cpp.o
In file included from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinaryContext.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinaryBasicBlock.cpp:14:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/DebugData.h:512:22: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  512 |   DenseSet<uint64_t> DebugStrOffsetFinalized;
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
595.830 [127/14/1870] Building CXX object tools/bolt/lib/Core/CMakeFiles/LLVMBOLTCore.dir/BinaryFunctionProfile.cpp.o
In file included from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinarySection.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinaryContext.h:18,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/BinaryFunction.h:29,
                 from /home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/lib/Core/BinaryFunctionProfile.cpp:15:
/home/worker/bolt-worker2/bolt-x86_64-ubuntu-nfc/llvm-project/bolt/include/bolt/Core/DebugData.h:512:22: warning: ‘maybe_unused’ attribute ignored [-Wattributes]

anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…lvm#145735)

The assumption here is that if data() returns a pointer and size()
exists it's something representing contiguous storage.

Modeled after the behavior of C++20 std::span and enables two-way
conversion between std::span (or really any span-like type) and
ArrayRef. Add a unit test that verifies this if std::span is around.

This also means we can get rid of specific conversions for std::vector
and SmallVector.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…lvm#145735)

The assumption here is that if data() returns a pointer and size()
exists it's something representing contiguous storage.

Modeled after the behavior of C++20 std::span and enables two-way
conversion between std::span (or really any span-like type) and
ArrayRef. Add a unit test that verifies this if std::span is around.

This also means we can get rid of specific conversions for std::vector
and SmallVector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants