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

Fix compile error in binaryop/compiled/util.cpp #10209

Merged
merged 5 commits into from
Feb 3, 2022

Conversation

ttnghia
Copy link
Contributor

@ttnghia ttnghia commented Feb 3, 2022

This PR fixes a compile error in binaryop/compiled/util.cpp, when a function with return type std::optional return {} instead of std::nullopt. As such, nvcc 11.5/g++-10.3 yell:

../src/binaryop/compiled/util.cpp: In function 'std::optional<cudf::data_type> cudf::binops::compiled::get_common_type(cudf::data_type, cudf::data_type, cudf::data_type)':
../src/binaryop/compiled/util.cpp:48:15: error: '<anonymous>' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   48 |       return {};
      |               ^

@ttnghia ttnghia added bug Something isn't working 3 - Ready for Review Ready for review by team libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change labels Feb 3, 2022
@ttnghia ttnghia self-assigned this Feb 3, 2022
@ttnghia ttnghia requested a review from a team as a code owner February 3, 2022 17:44
@@ -45,7 +45,7 @@ struct common_type_functor {
// Eg. d=t-t
return data_type{type_to_id<TypeCommon>()};
}
return {};
return std::nullopt;
Copy link
Contributor

Choose a reason for hiding this comment

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

A default-constructed std::optional should be equivalent to std::nullopt from my reading of cppreference. This pattern is used several times in libcudf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@ttnghia ttnghia Feb 3, 2022

Choose a reason for hiding this comment

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

Here is my reasoning:

  • The old code return {} will return a valid optional object with default-constructed data_type, not a nullopt.
  • Implicitly defined (by the compiler) default constructor of a class does not initialize members of built-in types. (https://stackoverflow.com/questions/2417065/does-the-default-constructor-initialize-built-in-types)
  • The class data_type has a default constructor, and calling {} will construct a default data_type object instead of an empty optional object.
  • "a default data_type object" does not initialize its members. That's why we got the compile error.

Copy link
Contributor

Choose a reason for hiding this comment

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

The old code return {} will return a valid optional object with default-constructed data_type, not a nullopt.

I don't think so, mate. (1) in the spec indicates otherwise. Here's a trivial godbolt example.

This sounds very much like a compiler bug that we're working around. That said, this change might still be worth having.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the only thing I can think of is a compiler bug that causes return {} to return a valid optional object with default-constructed data_type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hah, so it's compiler bug not just with gcc-10, but gcc <= 10?

We don't see this bug with GCC 9 or 11. There may be some confluence of issues here that cause it to only appear on GCC 10.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's warning treated as error. From the links above, I can see that such warning is issued with gcc-7 and 8 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guys, we have a very hot discussion. Thanks all for your attention 👍 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ttnghia Can you try moving this function out of the anonymous namespace and see if it compiles on GCC 10 with return {}?

Moving the function out of anonymous namespace does not help.

Copy link
Contributor

@bdice bdice Feb 3, 2022

Choose a reason for hiding this comment

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

Nothing to get us excited like a possible compiler bug! Appreciate all the voices here - I learned quite a bit. :)

Copy link
Contributor

@karthikeyann karthikeyann left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@mythrocks mythrocks left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

I'd like to know if return {} compiles without the warning on GCC 10 if the function is not in an anonymous namespace. If that fixes it, I would reference https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465 in the comment. Otherwise LGTM.

@codecov
Copy link

codecov bot commented Feb 3, 2022

Codecov Report

Merging #10209 (61fe1e8) into branch-22.04 (a7d88cd) will increase coverage by 0.04%.
The diff coverage is 0.00%.

❗ Current head 61fe1e8 differs from pull request most recent head fbae4ea. Consider uploading reports for the commit fbae4ea to get more accurate results

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-22.04   #10209      +/-   ##
================================================
+ Coverage         10.42%   10.47%   +0.04%     
================================================
  Files               119      122       +3     
  Lines             20603    20506      -97     
================================================
  Hits               2148     2148              
+ Misses            18455    18358      -97     
Impacted Files Coverage Δ
python/cudf/cudf/core/_base_index.py 0.00% <ø> (ø)
python/cudf/cudf/core/column/categorical.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/column.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/datetime.py 0.00% <ø> (ø)
python/cudf/cudf/core/column/numerical.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/string.py 0.00% <ø> (ø)
python/cudf/cudf/core/column/timedelta.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column_accessor.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/dataframe.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/frame.py 0.00% <0.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4ac6d4...fbae4ea. Read the comment docs.

@ttnghia
Copy link
Contributor Author

ttnghia commented Feb 3, 2022

@gpucibot merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants