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

[LLVM10] Fixing compilation warnings for Reco and SIM #29568

Closed
wants to merge 4 commits into from
Closed

[LLVM10] Fixing compilation warnings for Reco and SIM #29568

wants to merge 4 commits into from

Conversation

smuzaffar
Copy link
Contributor

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.

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29568/14874

  • This PR adds an extra 52KB to repository

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @smuzaffar (Malik Shahzad Muzaffar) for master.

It involves the following packages:

DataFormats/Math
RecoLocalTracker/SiStripZeroSuppression
RecoMuon/MuonIdentification
RecoTracker/TkTrackingRegions
RecoTracker/TrackProducer

@perrotta, @cmsbuild, @slava77 can you please review it and eventually sign? Thanks.
@echabert, @felicepantaleo, @pieterdavid, @robervalwalsh, @echapon, @alesaggio, @abbiendi, @mmusich, @cericeci, @makortel, @threus, @jhgoh, @dgulhan, @HuguesBrun, @trocino, @rociovilar, @yduhm, @GiacomoSguazzoni, @rovere, @VinInn, @bellan, @mschrode, @ebrondol, @fabiocos, @gbenelli, @Fedespring, @calderona, @gpetruc, @folguera this is something you requested to watch as well.
@silviodonato, @dpiparo you are the release manager for this.

cms-bot commands are listed here

@perrotta
Copy link
Contributor

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 28, 2020

The tests are being triggered in jenkins.
https://cmssdt.cern.ch/jenkins/job/ib-run-pr-tests/5881/console Started: 2020/04/28 11:06

@@ -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);
Copy link
Contributor Author

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?

Copy link
Contributor

@VinInn VinInn Apr 28, 2020

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) {
Copy link
Contributor

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&?

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 regardless of the size of object, LLVM 10 complains that you are creating a copy of object and suggests to use a &

https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/slc7_amd64_gcc820/CMSSW_11_1_CLANG_X_2020-04-27-2300/RecoLocalTracker/SiStripZeroSuppression

  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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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


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).

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@smuzaffar smuzaffar Apr 28, 2020

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.

Copy link
Contributor

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.

@cmsbuild
Copy link
Contributor

+1
Tested at: 2d9f8ab
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-57acd7/5881/summary.html
CMSSW: CMSSW_11_1_X_2020-04-27-2300
SCRAM_ARCH: slc7_amd64_gcc820

@cmsbuild
Copy link
Contributor

Comparison job queued.

@cmsbuild
Copy link
Contributor

Comparison is ready
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-57acd7/5881/summary.html

Comparison Summary:

  • No significant changes to the logs found
  • Reco comparison results: 0 differences found in the comparisons
  • DQMHistoTests: Total files compared: 34
  • DQMHistoTests: Total histograms compared: 2696435
  • DQMHistoTests: Total failures: 30
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 2696086
  • DQMHistoTests: Total skipped: 319
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 33 files compared)
  • Checked 147 log files, 16 edm output root files, 34 DQM output files

@perrotta
Copy link
Contributor

+1

  • Technical and rather trivial adjustments
  • Jenkins tests pass

@cmsbuild
Copy link
Contributor

Pull request #29568 was updated. @perrotta, @cmsbuild, @civanch, @mdhildreth, @slava77 can you please check and sign again.

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29568/14887

@cmsbuild
Copy link
Contributor

Pull request #29568 was updated. @perrotta, @cmsbuild, @civanch, @mdhildreth, @slava77 can you please check and sign again.

@smuzaffar smuzaffar changed the title [LLVM10] Fixing compilation warnings for Reco [LLVM10] Fixing compilation warnings for Reco and SIM Apr 28, 2020
@smuzaffar
Copy link
Contributor Author

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 28, 2020

The tests are being triggered in jenkins.
https://cmssdt.cern.ch/jenkins/job/ib-run-pr-tests/5889/console Started: 2020/04/28 17:11

@cmsbuild
Copy link
Contributor

+1
Tested at: 58fc07f
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-57acd7/5889/summary.html
CMSSW: CMSSW_11_1_X_2020-04-28-1100
SCRAM_ARCH: slc7_amd64_gcc820

@cmsbuild
Copy link
Contributor

Comparison job queued.

@cmsbuild
Copy link
Contributor

Comparison is ready
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-57acd7/5889/summary.html

Comparison Summary:

  • No significant changes to the logs found
  • Reco comparison results: 2 differences found in the comparisons
  • DQMHistoTests: Total files compared: 34
  • DQMHistoTests: Total histograms compared: 2696435
  • DQMHistoTests: Total failures: 18
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 2696098
  • DQMHistoTests: Total skipped: 319
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 33 files compared)
  • Checked 147 log files, 16 edm output root files, 34 DQM output files

@civanch
Copy link
Contributor

civanch commented Apr 29, 2020

+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) {
Copy link
Contributor

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)

@smuzaffar
Copy link
Contributor Author

I am closing this and will merge it with #29572

@smuzaffar smuzaffar closed this Apr 30, 2020
@smuzaffar smuzaffar deleted the llvm10-warnings-reco1 branch April 30, 2020 09:39
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.

8 participants