Skip to content

[ArrayRef] Add constructor from iterator_range<U*> (NFC). #137796

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 7 commits into from
Apr 30, 2025

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Apr 29, 2025

Add a new constructor to ArrayRef that takes an iterator_range with a random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types where an ArrayRef can already be constructed. I will share a follow-up soon.

@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2025

@llvm/pr-subscribers-llvm-adt

Author: Florian Hahn (fhahn)

Changes

Add a new constructor to ArrayRef that takes an iterator_range with a random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types where an ArrayRef can already be constructed. I will share a follow-up soon.


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

2 Files Affected:

  • (modified) llvm/include/llvm/ADT/ArrayRef.h (+13)
  • (modified) llvm/unittests/ADT/ArrayRefTest.cpp (+20)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index a1317423cdd1a..f2fc7b636a8f5 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -149,6 +149,19 @@ namespace llvm {
                  * = 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 of random access
+    /// iterators that can be converted.
+    template <typename U>
+    ArrayRef(const iterator_range<U *> &Range,
+             std::enable_if_t<std::is_base_of<std::random_access_iterator_tag,
+                                              typename std::iterator_traits<
+                                                  decltype(Range.begin())>::
+                                                  iterator_category>::value &&
+                                  std::is_convertible<U *, T const *>::value,
+                              void> * = nullptr)
+        : Data(Range.begin()), Length(llvm::size(Range)) {}
+
     /// @}
     /// @name Simple Operations
     /// @{
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index fb25ee19c0b20..128efbea813d2 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -255,6 +255,26 @@ TEST(ArrayRefTest, ArrayRefFromStdArray) {
   }
 }
 
+TEST(ArrayRefTest, ArrayRefFromIteratorRange) {
+  std::array<int, 5> A1{{42, -5, 0, 1000000, -1000000}};
+  ArrayRef<int> A2 = make_range(A1.begin(), A1.end());
+
+  EXPECT_EQ(A1.size(), A2.size());
+  for (std::size_t i = 0; i < A1.size(); ++i) {
+    EXPECT_EQ(A1[i], A2[i]);
+  }
+}
+
+TEST(ArrayRefTest, ArrayRefFromIteratorConstRange) {
+  std::array<const int, 5> A1{{42, -5, 0, 1000000, -1000000}};
+  ArrayRef<const int> A2 = make_range(A1.begin(), A1.end());
+
+  EXPECT_EQ(A1.size(), A2.size());
+  for (std::size_t i = 0; i < A1.size(); ++i) {
+    EXPECT_EQ(A1[i], A2[i]);
+  }
+}
+
 static_assert(std::is_trivially_copyable_v<ArrayRef<int>>,
               "trivially copyable");
 

fhahn added a commit to fhahn/llvm-project that referenced this pull request Apr 29, 2025
Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.
Copy link
Contributor Author

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

Use is #137798

/// iterators that can be converted.
template <typename U>
ArrayRef(const iterator_range<U *> &Range,
std::enable_if_t<std::is_base_of<std::random_access_iterator_tag,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use enable_if instead of enable_if_it, and put it as a template parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 158 to 160
typename std::iterator_traits<
decltype(Range.begin())>::
iterator_category>::value &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this also a template parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

move to template<> is that what you had in mind?

typename std::iterator_traits<
decltype(Range.begin())>::
iterator_category>::value &&
std::is_convertible<U *, T const *>::value,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a is_convertible_v?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ,thanks

@fhahn fhahn force-pushed the arrayref-from-iterator-range branch from 5f88e72 to 2dcafd4 Compare April 29, 2025 16:41
/// to ensure that this is only used for iterator ranges of random access
/// iterators that can be converted.
template <typename U,
typename = std::enable_if<
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably still worth using std::enable_if_t here, but without explicitly specifying a type parameter (the default is void, so that's fine) - if you are using std::enable_if then I think you have to add the ::type at the end (that's where the SFINAE is - std::enable_if<false> has no nested type member, but std::enable_if<true> does)

Speaking of which - perhaps you could use some static_asserts to check that this SFINAE is rejecting the relevant cases in this condition?

Also - perhaps you could explain more how this condition works? It's not clear to me it does what we want/can detect contiguous sequences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can drop the typename =.

I tried but it complained.

Probably still worth using std::enable_if_t here, but without explicitly specifying a type parameter (the default is void, so that's fine) - if you are using std::enable_if then I think you have to add the ::type at the end (that's where the SFINAE is - std::enable_if has no nested type member, but std::enable_if does)

thanks, switched back to std::enable_if_t. The original checks were more complex and maybe too lax than needed; I think we are only guaranteed to iterate over a continous range, if the iterator is a plain pointer (e.g. int * as in the test case or something like int **.

The new check just enforces that the iterator is same as T *. I think that should be sufficient?

I also added some static_assert to check some invalid combinations.

/// iterators that can be converted.
template <typename U,
typename = std::enable_if<
std::is_base_of<
Copy link
Contributor

Choose a reason for hiding this comment

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

is_base_of_v?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now gone

/// to ensure that this is only used for iterator ranges of random access
/// iterators that can be converted.
template <typename U,
typename = std::enable_if<
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can drop the typename =.

Comment on lines 159 to 161
typename std::iterator_traits<
decltype(std::declval<const iterator_range<U *> &>()
.begin())>::iterator_category>::value &&
Copy link
Contributor

Choose a reason for hiding this comment

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

So what I meant is that we can factor this typename into a new template parameter, say IT, and then use IT here to keep this template parameter readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now gone

Comment on lines 160 to 161
decltype(std::declval<const iterator_range<U *> &>()
.begin())>::iterator_category>::value &&
Copy link
Contributor

@artagnon artagnon Apr 29, 2025

Choose a reason for hiding this comment

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

I don't think we need this declval, but I could be wrong: does iterator_traits<iterator<U *>>::iterator_category not work? Why use iterator_range::begin(), when we already know what the type of the begin is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now gone.

We now just need the type of the iterator, which we can get from the template argument already, thanks

@fhahn fhahn force-pushed the arrayref-from-iterator-range branch from bdb3080 to 0e21ecb Compare April 29, 2025 18:19
fhahn added a commit to fhahn/llvm-project that referenced this pull request Apr 29, 2025
Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.
@dwblaikie
Copy link
Collaborator

(seems about right to me, I'll leave it to @artagnon for the final approval, unless something contentious comes up (if so, do tag me/reach out, happy to weigh in/help resolve))

Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

};

static_assert(
!std::is_constructible<ArrayRef<int>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is_constructible_v.

/// 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.
template <typename U, typename = std::enable_if_t<std::is_same_v<U *, T *>>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about the thinko, but why is template parameter U needed if std::is_same_iv<U *, T *>? Doesn't that imply that U = T?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this should use is_convertible I think, to support creating ArrayRef<const X> from iterator_range<X *>, also added a test

Copy link
Contributor

Choose a reason for hiding this comment

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

Not 100% sure if is_convertible is the best thing to do here: maybe is_same_v<U, remove_const_t<T>> is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

is_convertible will also allow creating a type of base class from a derived class, and I think we want to forbid such things in the construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately is_same_v<U, remove_const_t<T>> isn't sufficient to support pointer cases with different const-ness directly .

I updated the is_convertible_v check to add another level of indirection, which should forbids construction a ArrayRef for a non-pointer base from an iterator of derived*, the only case that was previously allowed. This is similar to how std::vector and SmallVectorImpl are handled above. Added a few more static asserts to the test

fhahn added 5 commits April 30, 2025 09:41
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. I will share a follow-up
soon.
@fhahn fhahn force-pushed the arrayref-from-iterator-range branch from 0e21ecb to d6e3f8d Compare April 30, 2025 09:12
Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

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

Thanks for being extra-rigorous in this patch!

@fhahn fhahn merged commit 101fd87 into llvm:main Apr 30, 2025
9 of 11 checks passed
@fhahn fhahn deleted the arrayref-from-iterator-range branch April 30, 2025 12:00
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-win-fast running on as-builder-3 while building llvm at step 7 "test-build-unified-tree-check-llvm-unit".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-llvm-unit) failure: test (failure)
...
[66/745] Building RC object unittests\ADT\CMakeFiles\ADTTests.dir\__\__\resources\windows_version_resource.rc.res
[67/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\TypeSwitchTest.cpp.obj
[68/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\StringSwitchTest.cpp.obj
[69/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\StringMapTest.cpp.obj
[70/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\StringSetTest.cpp.obj
[71/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\StringTableTest.cpp.obj
[72/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\TypeTraitsTest.cpp.obj
[73/745] Building CXX object lib\Testing\Annotations\CMakeFiles\LLVMTestingAnnotations.dir\Annotations.cpp.obj
[74/745] Linking CXX static library lib\LLVMTestingAnnotations.lib
[75/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ArrayRefTest.cpp.obj
FAILED: unittests/ADT/CMakeFiles/ADTTests.dir/ArrayRefTest.cpp.obj 
C:\ninja\ccache.exe C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1438~1.331\bin\Hostx64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\unittests\ADT -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\include -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\include -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\third-party\unittest\googletest\include -IC:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\third-party\unittest\googlemock\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2 /DNDEBUG -MD  /EHs-c- /GR- -std:c++17 /showIncludes /Founittests\ADT\CMakeFiles\ADTTests.dir\ArrayRefTest.cpp.obj /Fdunittests\ADT\CMakeFiles\ADTTests.dir\ /FS -c C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(295): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<int>'
        with
        [
            _Ty=int
        ]
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(295): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(301): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<const int>'
        with
        [
            _Ty=int
        ]
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(301): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(309): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<const int>'
        with
        [
            _Ty=const int
        ]
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(309): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
[76/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\EditDistanceTest.cpp.obj
[77/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FoldingSet.cpp.obj
[78/745] Building CXX object unittests\MC\CMakeFiles\MCTests.dir\TargetRegistry.cpp.obj
[79/745] Building CXX object lib\Testing\Support\CMakeFiles\LLVMTestingSupport.dir\SupportHelpers.cpp.obj
[80/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\PackedVectorTest.cpp.obj
[81/745] Building CXX object unittests\MC\CMakeFiles\MCTests.dir\MCDisassemblerTest.cpp.obj
[82/745] Building CXX object unittests\Object\CMakeFiles\ObjectTests.dir\COFFObjectFileTest.cpp.obj
[83/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\DirectedGraphTest.cpp.obj
[84/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ImmutableMapTest.cpp.obj
[85/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ConcurrentHashtableTest.cpp.obj
[86/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\APFixedPointTest.cpp.obj
[87/745] Building CXX object lib\Testing\Support\CMakeFiles\LLVMTestingSupport.dir\Error.cpp.obj
[88/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\LazyAtomicPointerTest.cpp.obj
[89/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\TrieRawHashMapTest.cpp.obj
[90/745] Building CXX object unittests\Analysis\CMakeFiles\AnalysisTests.dir\ConstraintSystemTest.cpp.obj
[91/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ImmutableListTest.cpp.obj
[92/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\CombinationGeneratorTest.cpp.obj
[93/745] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ImmutableSetTest.cpp.obj
[94/745] Building CXX object unittests\Object\CMakeFiles\ObjectTests.dir\ArchiveTest.cpp.obj

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-win running on sie-win-worker while building llvm at step 7 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
...
[343/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\EnumeratedArrayTest.cpp.obj
[344/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\EquivalenceClassesTest.cpp.obj
[345/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Frontend\CodeGenActionTest.cpp.obj
[346/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FloatingPointMode.cpp.obj
[347/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Sema\CodeCompleteTest.cpp.obj
[348/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FunctionExtrasTest.cpp.obj
[349/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FunctionRefTest.cpp.obj
[350/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Rewrite\RewriterTest.cpp.obj
[351/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\IListBaseTest.cpp.obj
[352/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ArrayRefTest.cpp.obj
FAILED: unittests/ADT/CMakeFiles/ADTTests.dir/ArrayRefTest.cpp.obj 
C:\bin\ccache.exe C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iunittests\ADT -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT -Iinclude -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\include -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\third-party\unittest\googletest\include -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\third-party\unittest\googlemock\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Founittests\ADT\CMakeFiles\ADTTests.dir\ArrayRefTest.cpp.obj /Fdunittests\ADT\CMakeFiles\ADTTests.dir\ /FS -c Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(295): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<int>'
        with
        [
            _Ty=int
        ]
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(295): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(301): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<const int>'
        with
        [
            _Ty=int
        ]
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(301): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(309): error C2440: 'initializing': cannot convert from 'llvm::iterator_range<std::_Array_iterator<_Ty,5>>' to 'llvm::ArrayRef<const int>'
        with
        [
            _Ty=const int
        ]
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\ADT\ArrayRefTest.cpp(309): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
[353/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\IListIteratorTest.cpp.obj
[354/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Sema\SemaLookupTest.cpp.obj
[355/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\CodeGen\TBAAMetadataTest.cpp.obj
[356/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Format\TokenAnnotatorTest.cpp.obj
[357/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\CodeGen\BufferSourceTest.cpp.obj
[358/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FoldingSet.cpp.obj
[359/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\ConcurrentHashtableTest.cpp.obj
[360/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\FallibleIteratorTest.cpp.obj
[361/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\HashingTest.cpp.obj
[362/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Serialization\ModuleCacheTest.cpp.obj
[363/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\CodeGen\CodeGenExternalTest.cpp.obj
[364/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\CombinationGeneratorTest.cpp.obj
[365/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Sema\GslOwnerPointerInference.cpp.obj
[366/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\BitVectorTest.cpp.obj
[367/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\EditDistanceTest.cpp.obj
[368/1112] Building CXX object unittests\ADT\CMakeFiles\ADTTests.dir\DirectedGraphTest.cpp.obj
[369/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Index\IndexTests.cpp.obj
[370/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Sema\HeuristicResolverTest.cpp.obj
[371/1112] Building CXX object tools\clang\unittests\CMakeFiles\AllClangUnitTests.dir\Sema\SemaNoloadLookupTest.cpp.obj

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang-Unit :: ./AllClangUnitTests/36/51' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests-Clang-Unit-38382-36-51.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=51 GTEST_SHARD_INDEX=36 /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests
--

Script:
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests --gtest_filter=TimeProfilerTest.ConstantEvaluationCxx20
--
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/unittests/Support/TimeProfilerTest.cpp:238: Failure
Expected equality of these values:
  R"(
Frontend (test.cc)
| ParseDeclarationOrFunctionDefinition (test.cc:2:1)
| ParseDeclarationOrFunctionDefinition (test.cc:6:1)
| | ParseFunctionDefinition (slow_func)
| | | EvaluateAsRValue (<test.cc:8:21>)
| | | EvaluateForOverflow (<test.cc:8:21, col:25>)
| | | EvaluateForOverflow (<test.cc:8:30, col:32>)
| | | EvaluateAsRValue (<test.cc:9:14>)
| | | EvaluateForOverflow (<test.cc:9:9, col:14>)
| | | isPotentialConstantExpr (slow_namespace::slow_func)
| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)
| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)
| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)
| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)
| ParseDeclarationOrFunctionDefinition (test.cc:16:1)
| | ParseFunctionDefinition (slow_test)
| | | EvaluateAsInitializer (slow_value)
| | | EvaluateAsConstantExpr (<test.cc:17:33, col:59>)
| | | EvaluateAsConstantExpr (<test.cc:18:11, col:37>)
| ParseDeclarationOrFunctionDefinition (test.cc:22:1)
| | EvaluateAsConstantExpr (<test.cc:23:31, col:57>)
| | EvaluateAsRValue (<test.cc:22:14, line:23:58>)
| ParseDeclarationOrFunctionDefinition (test.cc:25:1)
| | EvaluateAsInitializer (slow_init_list)
| PerformPendingInstantiations
)"
    Which is: "\nFrontend (test.cc)\n| ParseDeclarationOrFunctionDefinition (test.cc:2:1)\n| ParseDeclarationOrFunctionDefinition (test.cc:6:1)\n| | ParseFunctionDefinition (slow_func)\n| | | EvaluateAsRValue (<test.cc:8:21>)\n| | | EvaluateForOverflow (<test.cc:8:21, col:25>)\n| | | EvaluateForOverflow (<test.cc:8:30, col:32>)\n| | | EvaluateAsRValue (<test.cc:9:14>)\n| | | EvaluateForOverflow (<test.cc:9:9, col:14>)\n| | | isPotentialConstantExpr (slow_namespace::slow_func)\n| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)\n| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)\n| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)\n| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)\n| ParseDeclarationOrFunctionDefinition (test.cc:16:1)\n| | ParseFunctionDefinition (slow_test)\n| | | EvaluateAsInitializer (slow_value)\n| | | EvaluateAsConstantExpr (<test.cc:17:33, col:59>)\n| | | EvaluateAsConstantExpr (<test.cc:18:11, col:37>)\n| ParseDeclarationOrFunctionDefinition (test.cc:22:1)\n| | EvaluateAsConstantExpr (<test.cc:23:31, col:57>)\n| | EvaluateAsRValue (<test.cc:22:14, line:23:58>)\n| ParseDeclarationOrFunctionDefinition (test.cc:25:1)\n| | EvaluateAsInitializer (slow_init_list)\n| PerformPendingInstantiations\n"
  buildTraceGraph(Json)
    Which is: "\nFrontend (test.cc)\n| ParseDeclarationOrFunctionDefinition (test.cc:2:1)\n| ParseDeclarationOrFunctionDefinition (test.cc:6:1)\n| | ParseFunctionDefinition (slow_func)\n| | | EvaluateAsRValue (<test.cc:8:21>)\n| | | EvaluateForOverflow (<test.cc:8:21, col:25>)\n| | | EvaluateForOverflow (<test.cc:8:30, col:32>)\n| | | EvaluateAsRValue (<test.cc:9:14>)\n| | | EvaluateForOverflow (<test.cc:9:9, col:14>)\n| | | isPotentialConstantExpr (slow_namespace::slow_func)\n| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)\n| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)\n| | | EvaluateAsBooleanCondition (<test.cc:8:21, col:25>)\n| | | | EvaluateAsRValue (<test.cc:8:21, col:25>)\n| ParseDeclarationOrFunctionDefinition (test.cc:16:1)\n| | ParseFunctionDefinition (slow_test)\n| | | EvaluateAsInitializer (slow_value)\n| | | EvaluateAsConstantExpr (<test.cc:17:33, col:59>)\n| | | EvaluateAsConstantExpr (<test.cc:18:11, col:37>)\n| ParseDeclarationOrFunctionDefinition (test.cc:22:1)\n| | EvaluateAsConstantExpr (<test.cc:23:31, col:57>)\n| | EvaluateAsRValue (<test.cc:22:14, line:23:58>)\n| ParseDeclarationOrFunctionDefinition (test.cc:25:1)\n| | EvaluateAsInitializer (slow_init_list)\n| | PerformPendingInstantiations\n"
With diff:
@@ -24,3 +24,3 @@
 | ParseDeclarationOrFunctionDefinition (test.cc:25:1)
 | | EvaluateAsInitializer (slow_init_list)
-| PerformPendingInstantiations\n
+| | PerformPendingInstantiations\n


...

@fhahn
Copy link
Contributor Author

fhahn commented Apr 30, 2025

Windows failure to build unit tests looks related to std::array, should be fixed in 0d6c9f3

fhahn added a commit that referenced this pull request May 1, 2025
…FC) (#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on #137796.

PR: #137798
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm#137798.


PR: llvm#137796
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…FC) (llvm#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.

PR: llvm#137798
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm#137798.


PR: llvm#137796
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…FC) (llvm#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.

PR: llvm#137798
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm#137798.


PR: llvm#137796
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…FC) (llvm#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.

PR: llvm#137798
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 6, 2025
…(#137796)

Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm/llvm-project#137798.

PR: llvm/llvm-project#137796
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 6, 2025
…in ctors (NFC) (#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm/llvm-project#137796.

PR: llvm/llvm-project#137798
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm#137798.


PR: llvm#137796
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…FC) (llvm#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.

PR: llvm#137798
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
Add a new constructor to ArrayRef that takes an iterator_range with a
random access iterator that can be converted.

This can help to avoid creating unnecessary iterator_ranges for types
where an ArrayRef can already be constructed. To be used in
llvm#137798.


PR: llvm#137796
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
…FC) (llvm#137798)

Now that there is an ArrayRef constructor taking iterator_ranges, use it
consistently to slightly simplify code.

Depends on llvm#137796.

PR: llvm#137798
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.

6 participants