This is an archive of the discontinued LLVM Phabricator instance.

[SmallVector] Add an explicit SmallVector(size_t Size) constructor.
ClosedPublic

Authored by craig.topper on Apr 2 2023, 11:55 PM.

Details

Summary

Previously we use the SmallVector(size_t Size, const T& Value) constructor
with a default constructed Value. This will copy construct every element
in the vector, but not all types can be copy constructed.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 2 2023, 11:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 11:55 PM
craig.topper requested review of this revision.Apr 2 2023, 11:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 11:55 PM
dblaikie accepted this revision.Apr 3 2023, 10:35 AM

Sounds good - I probably wouldn't mind slightly more in the test, like a check for size or something, but yeah, that'd be of minimal value.

This revision is now accepted and ready to land.Apr 3 2023, 10:35 AM
This revision was landed with ongoing or failed builds.Apr 3 2023, 1:22 PM
This revision was automatically updated to reflect the committed changes.
thurston added inline comments.
llvm/unittests/ADT/SmallVectorTest.cpp
174–177

This test broke the clang-ppc64-aix build at https://lab.llvm.org/buildbot/#/builders/214/builds/6761/steps/6/logs/stdio

FAILED: unittests/ADT/CMakeFiles/ADTTests.dir/SmallVectorTest.cpp.o 
...
In file included from /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/unittests/ADT/SmallVectorTest.cpp:16:
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11: error: comparison of integers of different signs: 'const unsigned long' and 'const int' [-Werror,-Wsign-compare]
  if (lhs == rhs) {
      ~~~ ^  ~~~
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1553:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<unsigned long, int>' requested here
    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
           ^
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/unittests/ADT/SmallVectorTest.cpp:176:3: note: in instantiation of function template specialization 'testing::internal::EqHelper::Compare<unsigned long, int, nullptr>' requested here
  EXPECT_EQ(V.size(), 42);
  ^
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:2027:54: note: expanded from macro 'EXPECT_EQ'
  EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
                                                     ^
1 error generated.