Skip to content
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

GH-41478: [C++] Clean up more redundant move warnings #41487

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

WillAyd
Copy link
Contributor

@WillAyd WillAyd commented May 1, 2024

Rationale for this change

Minor warning cleanup for downstream libraries trying to get warning-free builds

What changes are included in this PR?

Removed redundant std::move from return statements

Are these changes tested?

Builds cleanly

Are there any user-facing changes?

No

Copy link

github-actions bot commented May 1, 2024

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

In the case of PARQUET issues on JIRA the title also supports:

PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

See also:

@WillAyd
Copy link
Contributor Author

WillAyd commented May 1, 2024

Can see this in a branch adding meson warning level 2 downstream to nanoarrow:

https://github.com/apache/arrow-nanoarrow/actions/runs/8912807091/job/24476999593?pr=448

@github-actions github-actions bot added the awaiting review Awaiting review label May 1, 2024
@WillAyd WillAyd changed the title GH41478: [C++] Clean up more redundant move warnings GH-41478: [C++] Clean up more redundant move warnings May 1, 2024
Copy link

github-actions bot commented May 1, 2024

⚠️ GitHub issue #41478 has been automatically assigned in GitHub to PR creator.

@kou
Copy link
Member

kou commented May 5, 2024

@github-actions crossbow submit -g cpp

Copy link

github-actions bot commented May 5, 2024

Revision: 0920f96

Submitted crossbow builds: ursacomputing/crossbow @ actions-87d0bf1ec5

Task Status
test-alpine-linux-cpp GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-cuda-cpp GitHub Actions
test-debian-12-cpp-amd64 GitHub Actions
test-debian-12-cpp-i386 GitHub Actions
test-fedora-39-cpp GitHub Actions
test-ubuntu-20.04-cpp GitHub Actions
test-ubuntu-20.04-cpp-bundled GitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizer GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-20 GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions

@kou
Copy link
Member

kou commented May 5, 2024

Hmm. Why is -Wredundant-move warning detected in our CI?
It seems that nanoarrow uses warning_level=2 https://github.com/apache/arrow-nanoarrow/blob/ae84d5f1f195f7345fe27d00e09507958746590e/meson.build#L27 . Is it related? If so, should we use -Wextra or -Wredundant-move in our CMake configuration?

@WillAyd
Copy link
Contributor Author

WillAyd commented May 6, 2024

I think you are asking why redundant move is not is the Arrow CI but correct me if mistaken. Yea Meson's warning level 2 is essentially Wextra/Wall for gcc/clang.

I haven't fully sifted through the current Arrow CMake configuration but I see that there is a BUILD_WARNING_LEVEL for CHECKIN that should pair both Wall and Wextra. I couldn't find that in the workflows - maybe it is not being used?

@kou
Copy link
Member

kou commented May 6, 2024

You're right... I missed "not"... Sorry...

Could you try this whether we can detect these warnings in our build?

diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake
index ea357b4779..a7001d6774 100644
--- a/cpp/cmake_modules/SetupCxxFlags.cmake
+++ b/cpp/cmake_modules/SetupCxxFlags.cmake
@@ -330,8 +330,9 @@ if("${BUILD_WARNING_LEVEL}" STREQUAL "CHECKIN")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-conversion")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-sign-conversion")
-    set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunused-result")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wdate-time")
+    set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wredundant-move")
+    set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunused-result")
   elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL
                                                    "IntelLLVM")
     if(WIN32)

@WillAyd
Copy link
Contributor Author

WillAyd commented May 7, 2024

So I've added that but it flags a lot of issues in the current code base. What I have so far generates a clean build with the ninja-debug preset but there are still issues; guessing they come from full builds.

I'm happy to clean those up as well just wanted to confirm it isn't too big of a change in its current state with you before continuing.

Another possible issue is that the -Wredundant-move flag also gets applied to non-cpp files, yielding the following warnings during a build:

[140/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/musl/strptime.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[147/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriIp4Base.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[148/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriIp4.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[149/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriMemory.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[150/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriCompare.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[151/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriCommon.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[152/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriNormalizeBase.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[153/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriParseBase.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[154/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriEscape.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[155/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriNormalize.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[156/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriResolve.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[157/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriShorten.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[159/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriFile.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[160/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriRecompose.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[162/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriQuery.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C
[164/780] Building C object src/arrow/CMakeFiles/arrow_vendored.dir/vendored/uriparser/UriParse.c.o
cc1: warning: command-line option ‘-Wredundant-move’ is valid for C++/ObjC++ but not for C

I didn't quite where those flags were getting intermixed yet; something to investigate

@kou
Copy link
Member

kou commented May 8, 2024

Ah, sorry. Could you use CXX_ONLY_FLAGS instead?

diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake
index ea357b4779..0bfb1e5a29 100644
--- a/cpp/cmake_modules/SetupCxxFlags.cmake
+++ b/cpp/cmake_modules/SetupCxxFlags.cmake
@@ -332,6 +332,7 @@ if("${BUILD_WARNING_LEVEL}" STREQUAL "CHECKIN")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-sign-conversion")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunused-result")
     set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wdate-time")
+    string(APPEND CXX_ONLY_FLAGS " -Wredundant-move")
   elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL
                                                    "IntelLLVM")
     if(WIN32)

@WillAyd
Copy link
Contributor Author

WillAyd commented May 11, 2024

Don't have a CUDA device to locally test that. Fixed the latest crossbow issue - hopefully that covers it

@kou
Copy link
Member

kou commented May 11, 2024

@github-actions crossbow submit -g cpp

Copy link

Revision: 54cb257

Submitted crossbow builds: ursacomputing/crossbow @ actions-999a090d8e

Task Status
test-alpine-linux-cpp GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-cuda-cpp GitHub Actions
test-debian-12-cpp-amd64 GitHub Actions
test-debian-12-cpp-i386 GitHub Actions
test-fedora-39-cpp GitHub Actions
test-ubuntu-20.04-cpp GitHub Actions
test-ubuntu-20.04-cpp-bundled GitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizer GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-20 GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions

@WillAyd
Copy link
Contributor Author

WillAyd commented May 11, 2024

I don't believe the CI failures are related - maybe flaky tests?

@@ -409,7 +409,7 @@ class DatasetWriterDirectoryQueue {
dir_queue->PrepareDirectory();
ARROW_ASSIGN_OR_RAISE(dir_queue->current_filename_, dir_queue->GetNextFilename());
// std::move required to make RTools 3.5 mingw compiler happy
Copy link
Member

Choose a reason for hiding this comment

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

Could you remove this comment?

Comment on lines 414 to 415
// Using std::move because some compiler might has issue below:
// https://wg21.cmeerw.net/cwg/issue1579
Copy link
Member

@kou kou May 12, 2024

Choose a reason for hiding this comment

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

Hmm. We may not be able to remove this std::move(): #41025

Let's try R jobs.

// ARROW-8193: On gcc-4.8 without the explicit move it tries to use the
// copy constructor, which may be deleted on the elements of type T
return std::move(out);

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@kou
Copy link
Member

kou commented May 12, 2024

@github-actions crossbow submit -g r

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels May 12, 2024

This comment was marked as outdated.

@kou
Copy link
Member

kou commented May 12, 2024

test-r-rstudio-r-base-4.1-opensuse153 failed:

https://dev.azure.com/ursacomputing/crossbow/_build/results?buildId=63897&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb&t=6c939d89-0d1a-51f2-8b30-091a7a82e98c&l=1320

[ 26%] Building CXX object src/arrow/CMakeFiles/arrow_util.dir/util/align_util.cc.o
/arrow/cpp/src/arrow/util/align_util.cc: In function ‘arrow::Result<std::shared_ptr<arrow::Buffer> > arrow::util::EnsureAlignment(std::shared_ptr<arrow::Buffer>, int64_t, arrow::MemoryPool*)’:
/arrow/cpp/src/arrow/util/align_util.cc:162:12: error: could not convert ‘new_buffer’ from ‘std::unique_ptr<arrow::Buffer>’ to ‘arrow::Result<std::shared_ptr<arrow::Buffer> >’
     return new_buffer;
            ^~~~~~~~~~
make[2]: *** [src/arrow/CMakeFiles/arrow_util.dir/build.make:80: src/arrow/CMakeFiles/arrow_util.dir/util/align_util.cc.o] Error 1

Let's update test-r-rstudio-r-base-4.1-opensuse153: #41626

@kou
Copy link
Member

kou commented May 12, 2024

Could you rebase on main to use OpenSUSE 15.5 not 15.3?

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 13, 2024
Copy link
Member

@westonpace westonpace left a comment

Choose a reason for hiding this comment

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

+1 (providing CI / nightly tests pass) These look like nice improvements to me. I think the main reason we had the move on return in the first place was due to a compiler bug in the old R 3.5 toolchain. Now that we no longer need to build there I think this is a good cleanup.

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels May 13, 2024
@kou
Copy link
Member

kou commented May 13, 2024

@github-actions crossbow submit test-r-rstudio-r-base-4.1-opensuse155

This comment was marked as outdated.

@kou
Copy link
Member

kou commented May 13, 2024

@github-actions crossbow submit -g cpp -g r

This comment was marked as outdated.

@WillAyd
Copy link
Contributor Author

WillAyd commented May 14, 2024

Well this is fun...looks like the compilers have conflicting desires. With code like this:

template <typename Options, typename... Properties>
const FunctionOptionsType* GetFunctionOptionsType(const Properties&... properties) {
  ...
  auto options = std::make_unique<Options>();
  RETURN_NOT_OK(
      FromStructScalarImpl<Options>(options.get(), scalar, properties_).status_);

   return std::move(options);
}

The more modern compilers complain about a redundant move:

/home/willayd/clones/arrow/cpp/src/arrow/compute/function_internal.h: In instantiation of ‘arrow::Result<std::unique_ptr<arrow::compute::FunctionOptions> > arrow::compute::internal::GetFunctionOptionsType(const Properties& ...)::OptionsType::FromStructScalar(const arrow::StructScalar&) const [with Options = arrow::compute::ArithmeticOptions; Properties = {arrow::internal::DataMemberProperty<arrow::compute::ArithmeticOptions, bool>}]’:
/home/willayd/clones/arrow/cpp/src/arrow/compute/function_internal.h:697:3:   required from ‘const arrow::compute::FunctionOptionsType* arrow::compute::internal::GetFunctionOptionsType(const Properties& ...) [with Options = arrow::compute::ArithmeticOptions; Properties = {arrow::internal::DataMemberProperty<arrow::compute::ArithmeticOptions, bool>}]’
/home/willayd/clones/arrow/cpp/src/arrow/compute/api_scalar.cc:314:79:   required from here
/home/willayd/clones/arrow/cpp/src/arrow/compute/function_internal.h:687:31: error: redundant move in return statement [-Werror=redundant-move]
  687 |       return std::move(options);

If you remove the std::move(...) then the test-r-rstudio-r-base-4.1-opensuse155 build complains that it cannot convert the templated pointer type to that which matches the function declaration:

  /arrow/cpp/src/arrow/compute/function_internal.h:687:14: error: could not convert ‘options’ from ‘std::unique_ptr<arrow::compute::ArithmeticOptions, std::default_delete<arrow::compute::ArithmeticOptions> >’ to ‘arrow::Result<std::unique_ptr<arrow::compute::FunctionOptions> >return options;

This also seems to happen in cases where the returned value is a unique_ptr but the function/method declaration is that of a shared_ptr; I'm assuming more modern compilers happily convert that automatically for you but the compiler on the openSUSE build does not

For now I've tried to be really explicit about the return type in the offending functions to try and appease all platforms, but happy to change to any better idea

@kou
Copy link
Member

kou commented May 15, 2024

@github-actions crossbow submit -g cpp -g r

Copy link

Revision: cc3c73d

Submitted crossbow builds: ursacomputing/crossbow @ actions-40bb465e0a

Task Status
r-binary-packages GitHub Actions
test-alpine-linux-cpp GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-cuda-cpp GitHub Actions
test-debian-12-cpp-amd64 GitHub Actions
test-debian-12-cpp-i386 GitHub Actions
test-fedora-39-cpp GitHub Actions
test-r-arrow-backwards-compatibility GitHub Actions
test-r-clang-sanitizer GitHub Actions
test-r-depsource-bundled Azure
test-r-depsource-system GitHub Actions
test-r-dev-duckdb GitHub Actions
test-r-devdocs GitHub Actions
test-r-gcc-11 GitHub Actions
test-r-gcc-12 GitHub Actions
test-r-install-local GitHub Actions
test-r-install-local-minsizerel GitHub Actions
test-r-linux-as-cran GitHub Actions
test-r-linux-rchk GitHub Actions
test-r-linux-valgrind GitHub Actions
test-r-minimal-build Azure
test-r-offline-maximal GitHub Actions
test-r-offline-minimal Azure
test-r-rhub-debian-gcc-devel-lto-latest Azure
test-r-rhub-debian-gcc-release-custom-ccache Azure
test-r-rhub-ubuntu-release-latest Azure
test-r-rocker-r-ver-latest Azure
test-r-rstudio-r-base-4.1-opensuse155 Azure
test-r-rstudio-r-base-4.2-focal Azure
test-r-ubuntu-22.04 GitHub Actions
test-r-versions GitHub Actions
test-ubuntu-20.04-cpp GitHub Actions
test-ubuntu-20.04-cpp-bundled GitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizer GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-20 GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions
test-ubuntu-r-sanitizer GitHub Actions

@WillAyd
Copy link
Contributor Author

WillAyd commented May 15, 2024

Looks like the valgrind failures are from AWS cryptography code - I don't think that is related to this

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

+1

@pitrou @bkietz Do you want to review this before we merge this?

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

+1, thanks for doing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants