cmssw icon indicating copy to clipboard operation
cmssw copied to clipboard

[RFC] cleanup of frequent shadow warnings

Open slava77 opened this issue 1 year ago • 26 comments

While compiling with -Wshadow for a test I decided to cleanup some of the more frequent cases exposed mainly by being present in interface/. Perhaps this can be a step towards enabling this warning in our builds.

One curious case was the use of CLHEP/Units/GlobalSystemOfUnits.h, which puts a few singe character (m, s, g) and other short-name symbols in the global scope. The scoped SystemOfUnits.h seems to be more appropriate for a large sw project.

The total count of warnings goes down from 48.6K to 14K.

slava77 avatar Apr 26 '24 13:04 slava77

cms-bot internal usage

cmsbuild avatar Apr 26 '24 13:04 cmsbuild

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40105

  • This PR adds an extra 164KB to repository

Code check has found code style and quality issues which could be resolved by applying following patch(s)

  • code-format: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40105/code-format.patch e.g. curl -k https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40105/code-format.patch | patch -p1 You can also run scram build code-format to apply code format directly

cmsbuild avatar Apr 26 '24 13:04 cmsbuild

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40106

  • This PR adds an extra 236KB to repository

cmsbuild avatar Apr 26 '24 13:04 cmsbuild

A new Pull Request was created by @slava77 for master.

It involves the following packages:

  • DataFormats/BTauReco (reconstruction)
  • DataFormats/Common (core)
  • DataFormats/PatCandidates (xpog, reconstruction)
  • DataFormats/SoATemplate (heterogeneous)
  • DataFormats/VertexReco (reconstruction)
  • FWCore/Framework (core)
  • Geometry/CommonTopologies (geometry)
  • Geometry/HcalCommonData (geometry)
  • HeterogeneousCore/AlpakaInterface (heterogeneous)
  • HeterogeneousCore/CUDAUtilities (heterogeneous)
  • OnlineDB/EcalCondDB (db)
  • PhysicsTools/MVAComputer (ml)
  • RecoBTag/FeatureTools (reconstruction)
  • RecoLocalTracker/SiPixelClusterizer (reconstruction)
  • SimG4CMS/Calo (simulation)
  • SimTracker/SiPhase2Digitizer (simulation, upgrade)
  • TrackPropagation/Geant4e (simulation)
  • Validation/GlobalHits (dqm)
  • Validation/HcalHits (dqm)

@wpmccormack, @saumyaphor4252, @mandrenguyen, @fwyzard, @srimanob, @cmsbuild, @hqucms, @jfernan2, @civanch, @rvenditti, @francescobrivio, @Dr15Jones, @perrotta, @nothingface0, @bsunanda, @vlimant, @subirsarkar, @smuzaffar, @consuegs, @syuvivida, @antoniovagnerini, @makortel, @mdhildreth, @valsdav, @tjavaid can you please review it and eventually sign? Thanks. @felicepantaleo, @dkotlins, @slomeo, @abdoulline, @argiro, @hatakeyamak, @castaned, @dgulhan, @Ming-Yan, @mroguljic, @VinInn, @AlexDeMoor, @ReyerBand, @gouskos, @demuller, @wddgit, @rsreds, @hqucms, @yuanchao, @rchatter, @andrzejnovak, @VourMa, @PonIlya, @GiacomoSguazzoni, @tvami, @JanChyczynski, @Senphy, @tsusa, @rovere, @bsunanda, @missirol, @fabiocos, @JanFSchulte, @mtosi, @gpetruc, @mmusich, @thomreis, @ferencek, @makortel, @wang0jin, @threus this is something you requested to watch as well. @rappoccio, @antoniovilela, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

cmsbuild avatar Apr 26 '24 13:04 cmsbuild

@cmsbuild please test

slava77 avatar Apr 26 '24 14:04 slava77

-1

Failed Tests: UnitTests Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-631d6d/39120/summary.html COMMIT: 2344e8df211fb31f4ed4a5687b04bb1c8c993f91 CMSSW: CMSSW_14_1_X_2024-04-26-1100/el8_amd64_gcc12 User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/44855/39120/install.sh to create a dev area with all the needed externals and cmssw changes.

Unit Tests

I found 4 errors in the following unit tests:

---> test testHeterogeneousCoreCUDATestWriteRead had ERRORS
---> test testHeterogeneousCoreAlpakaTestWriteReadSerialSync had ERRORS
---> test testHeterogeneousCoreAlpakaTestModulesCPU had ERRORS
and more ...

Comparison Summary

There are some workflows for which there are errors in the baseline: 24834.78 step 2 The results for the comparisons for these workflows could be incomplete This means most likely that the IB is having errors in the relvals.The error does NOT come from this pull request

Summary:

cmsbuild avatar Apr 26 '24 20:04 cmsbuild

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40111

  • This PR adds an extra 428KB to repository

cmsbuild avatar Apr 26 '24 22:04 cmsbuild

Pull request #44855 was updated. @smuzaffar, @mandrenguyen, @srimanob, @tjavaid, @saumyaphor4252, @antoniovagnerini, @civanch, @hqucms, @jfernan2, @valsdav, @consuegs, @vlimant, @cmsbuild, @nothingface0, @wpmccormack, @rvenditti, @francescobrivio, @bsunanda, @Dr15Jones, @mdhildreth, @syuvivida, @makortel, @subirsarkar, @perrotta, @fwyzard can you please check and sign again.

cmsbuild avatar Apr 26 '24 22:04 cmsbuild

@cmsbuild please test

slava77 avatar Apr 26 '24 22:04 slava77

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-631d6d/39126/summary.html COMMIT: 3b6ed17a0bcc05fddce9fc33b24e344841db1b8c CMSSW: CMSSW_14_1_X_2024-04-26-1100/el8_amd64_gcc12 User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/44855/39126/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

There are some workflows for which there are errors in the baseline: 24834.78 step 2 The results for the comparisons for these workflows could be incomplete This means most likely that the IB is having errors in the relvals.The error does NOT come from this pull request

Summary:

cmsbuild avatar Apr 27 '24 06:04 cmsbuild

+db

  • Why not?

perrotta avatar Apr 27 '24 10:04 perrotta

-heterogeneous

I'm personally not in favour of these changes. Some are false positives, and many make the code less intuitive and more complicated to read.

fwyzard avatar Apr 27 '24 10:04 fwyzard

@slava77 , yes, itis "" --><>. an ideal solution for CLHEP headers is do not use inside header files except the situation when it is unavoidable. In such case to use <CLHEP/Units/SystemOfUnits.h> is the recommendation.

civanch avatar Apr 27 '24 12:04 civanch

@slava77 , yes, itis "" --><>. an ideal solution for CLHEP headers is do not use inside header files except the situation when it is unavoidable. In such case to use <CLHEP/Units/SystemOfUnits.h> is the recommendation.

thanks for clarifying; I updated the headers now. files were selected by git diff --stat --name-only CMSSW_14_1_0_pre2 | grep h$ | while read -r f; do grep -l \"CLHEP/ $f; done

slava77 avatar Apr 27 '24 16:04 slava77

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-44855/40112

  • This PR adds an extra 192KB to repository

  • There are other open Pull requests which might conflict with changes you have proposed:

    • File DataFormats/SoATemplate/interface/SoAView.h modified in PR(s): #44858
    • File HeterogeneousCore/AlpakaInterface/interface/getDeviceCachingAllocator.h modified in PR(s): #44858

cmsbuild avatar Apr 27 '24 16:04 cmsbuild

Pull request #44855 was updated. @jfernan2, @vlimant, @makortel, @cmsbuild, @rvenditti, @bsunanda, @Dr15Jones, @syuvivida, @mandrenguyen, @smuzaffar, @tjavaid, @fwyzard, @mdhildreth, @subirsarkar, @civanch, @wpmccormack, @valsdav, @srimanob, @antoniovagnerini, @nothingface0, @hqucms can you please check and sign again.

cmsbuild avatar Apr 27 '24 16:04 cmsbuild

@cmsbuild please test

slava77 avatar Apr 27 '24 16:04 slava77

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-631d6d/39127/summary.html COMMIT: 46695cca66ff86843320b201445af84079375e86 CMSSW: CMSSW_14_1_X_2024-04-27-1100/el8_amd64_gcc12 User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/44855/39127/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

cmsbuild avatar Apr 27 '24 22:04 cmsbuild

-1

sorry, but for me these changes are simply making the code ~~worse~~ less readable.

fwyzard avatar Apr 28 '24 07:04 fwyzard

@slava77 , may be it is possible to split PR into two: one for "law and order for CLHEP" and another for heterogenous?

civanch avatar Apr 28 '24 10:04 civanch

"himself" on the subject https://lkml.org/lkml/2006/11/28/253

VinInn avatar Apr 28 '24 11:04 VinInn

Anyhow I'm sure you all read this ttps://stackoverflow.com/questions/2958457/gcc-wshadow-is-too-strict and are aware of the possible options to attach to Wshadow (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html) So why "global" has been chosen? would not be better to move to -Wshadow=compatible-local ?

VinInn avatar Apr 28 '24 11:04 VinInn

Anyhow for this trivial example (that is surely not doing what the naive author intended)

class foo {
foo(int);
int i;
};

foo::foo(int i) : i(i){
    for (int j=0; j<i; ++j)
      i++;
}

-Wshadow=local (or compatible-local) will not issue any warning. Only -Wshadow(global) will.

So: do we want to warn for such cases or we consider the authors able to avoid armful shadow of global (actually class-member) variables?

VinInn avatar Apr 28 '24 12:04 VinInn

@slava77 , may be it is possible to split PR into two: one for "law and order for CLHEP" and another for heterogenous?

yes; this clearly became an RFC PR

slava77 avatar Apr 28 '24 14:04 slava77

@cms-sw/core-l2 please comment if any of these are useful. Thank you.

slava77 avatar May 10 '24 14:05 slava77

@cms-sw/core-l2 please comment if any of these are useful.

Do you mean in the core packages specifically, or in general?

In core packages some of the changes looked useful, some could have been kept as they were (as the scoping was very clear), but I'd rather have the renamed versions than adding #pragma GCC diagnostic.

makortel avatar May 10 '24 21:05 makortel

it looks like there is no significant interest to have fixes other than in CLHEP (done in #44882 )

slava77 avatar May 23 '24 15:05 slava77