-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[LLVM10] Fixing compilation warnings for Reco and SIM #29568
Conversation
The code-checks are being triggered in jenkins. |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29568/14874
|
A new Pull Request was created by @smuzaffar (Malik Shahzad Muzaffar) for master. It involves the following packages: DataFormats/Math @perrotta, @cmsbuild, @slava77 can you please review it and eventually sign? Thanks. cms-bot commands are listed here |
please test |
The tests are being triggered in jenkins. |
@@ -121,7 +121,7 @@ constexpr float unsafe_atan2f(float y, float x) { | |||
|
|||
template <int DEGREE> | |||
constexpr float safe_atan2f(float y, float x) { | |||
return unsafe_atan2f_impl<DEGREE>(y, (y == 0.f) & (x == 0.f) ? 0.2f : x); | |||
return unsafe_atan2f_impl<DEGREE>(y, ((y == 0.f) & (x == 0.f)) ? 0.2f : x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VinInn , shouldn't it be &&
instead of &
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. & is faster ( @makortel made some tests long ago )
@@ -164,7 +164,7 @@ inline edm::DetSet<SiStripRawDigi> SiStripZeroSuppression::formatRawDigis(const | |||
outRawDigis.reserve(rawDigis.size()); | |||
const std::vector<bool>& apvf = algorithms->getAPVFlags(); | |||
uint32_t strip = 0; | |||
for (const auto rawDigi : rawDigis) { | |||
for (const auto& rawDigi : rawDigis) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fully up to date with the latest recommendation, but why is this a warning? SiStripRawDigi (and SiStripDigi, in the two changes below) are small (one or two uint16_t
, respectively), so the code was intentionally written like this. Or will the compiler pick the most efficient option in any case when using const auto&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think regardless of the size of object, LLVM 10 complains that you are creating a copy of object and suggests to use a &
RecoLocalTracker/SiStripZeroSuppression/plugins/SiStripZeroSuppression.cc:167:19: warning: loop variable 'rawDigi' of type 'const SiStripRawDigi' creates a copy from type 'const SiStripRawDigi' [-Wrange-loop-construct]
for (const auto rawDigi : rawDigis) {
^
RecoLocalTracker/SiStripZeroSuppression/plugins/SiStripZeroSuppression.cc:167:8: note: use reference type 'const SiStripRawDigi &' to prevent copying
for (const auto rawDigi : rawDigis) {
^~~~~~~~~~~~~~~~~~~~
&
1 warning generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hope the compiler will optimize either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, we have quite a few cases where a copy is OK for small types.
It would be good to understand the underlying logic why it's triggered here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Playing around with compiler explorer revealed that it is the non-default destructor of SiStripRawDigi
~SiStripRawDigi() {} |
makes clang to issue the warning. Using the default destructor either by
~SiStripRawDigi() = default;
or removing the explicit definition removes the warning (while keeping the loop variable taken by value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Clang 10.0 release note [a], looks like clang is not treating simple class like SiStripRawDigi as small/trivially copyable types
[a]
https://releases.llvm.org/10.0.0/tools/clang/docs/ReleaseNotes.html#id3 ). So looks like clang 10.0 is not treating
-Wrange-loop-analysis got several improvements. It no longer warns about a copy being
made when the result is bound to an rvalue reference. It no longer warns when an object
of a small, trivially copyable type is copied. The warning now offers fix-its. Excluding
-Wrange loop-bind-reference it is now part of -Wall. To reduce the number of false
positives the diagnostic is disabled in macros and template instantiations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in principle going for default destructors where possible would be a slightly better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @makortel .
@pieterdavid @slava77 , let me know if you would like me to revert this change and go for default destructor for SiStripRawDigi class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sounds like the default constructor is a better solution.
If the compiler were to take this loop as is, the reference solution is supposedly more costly on this type with uint16_t memory footprint. I'm not sure how effective is the compiler optimization to get rid of the reference completely.
+1 |
Comparison job queued. |
Comparison is ready Comparison Summary:
|
+1
|
The code-checks are being triggered in jenkins. |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29568/14887
|
please test |
The tests are being triggered in jenkins. |
+1 |
Comparison job queued. |
Comparison is ready Comparison Summary:
|
+1 |
@@ -99,7 +99,7 @@ void SiStripMergeZeroSuppression::produce(edm::Event& event, const edm::EventSet | |||
LogTrace("SiStripMergeZeroSuppression::produce") << "inserting only the digis for not restored APVs" | |||
<< "\n"; | |||
LogTrace("SiStripMergeZeroSuppression::produce") << "size : " << zsModule->size() << "\n"; | |||
for (const auto itZsMod : *zsModule) { | |||
for (const auto& itZsMod : *zsModule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be reverted as well? (same for L118)
I am closing this and will merge it with #29572 |
PR description:
LLVM 10 integration in CLANG IBs shows new compilation warnings. This PR addresses few of those.
PR validation:
Local compilation for CLANG and normal IBs show no warnings.