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

[GCC11] Fix warning "strncmp ... evaluates to nonzero" #36467

Merged
merged 3 commits into from
Dec 15, 2021

Conversation

iarspider
Copy link
Contributor

Log : https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/slc7_aarch64_gcc11/CMSSW_12_3_X_2021-12-10-2300/FWCore/Utilities
Warning message:

In function 'edm::{anonymous}::cpu_type edm::{anonymous}::get_cpu_type()',
    inlined from 'bool edm::MallocOptionSetter::retrieveFromCpuType()' at (...)/src/FWCore/Utilities/src/MallocOpts.cc:113:25:
  (...)/src/FWCore/Utilities/src/MallocOpts.cc:99:21: warning: 'int strncmp(const char*, const char*, size_t)' of strings of length 7 and 12 and bound of 12 evaluates to nonzero [-Wstring-compare]
    99 |       return strncmp(str, amd_str, amd_sz) == 0       ? AMD_CPU
      |              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
  (...)/src/FWCore/Utilities/src/MallocOpts.cc:100:23: warning: 'int strncmp(const char*, const char*, size_t)' of strings of length 7 and 12 and bound of 12 evaluates to nonzero [-Wstring-compare]
   100 |              : strncmp(str, intel_str, intel_sz) == 0 ? INTEL_CPU
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

PR description:

We do not need to compare all 12 characters, since the detected CPU name is truncated to 2 characters (see line 97).

@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36467/27321

  • This PR adds an extra 16KB to repository

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

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36467/27322

  • This PR adds an extra 16KB to repository

@cmsbuild
Copy link
Contributor

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

It involves the following packages:

  • FWCore/Utilities (core)

@cmsbuild, @smuzaffar, @Dr15Jones, @makortel can you please review it and eventually sign? Thanks.
@makortel, @felicepantaleo, @wddgit this is something you requested to watch as well.
@perrotta, @dpiparo, @qliphy you are the release manager for this.

cms-bot commands are listed here

@iarspider
Copy link
Contributor Author

assign core

@iarspider
Copy link
Contributor Author

please test

@makortel
Copy link
Contributor

We do not need to compare all 12 characters, since the detected CPU name is truncated to 2 characters (see line 97).

But ans is

static volatile int ans[4];

and, IIUC, line 97

truncates the str to 12 characters.

I think the warning for ARM and Power come from the #else branch

#else
const char* unknown_str = "Unknown";
// int unknown_sz = strlen(unknown_str);
strcpy((char*)&ans[0], unknown_str);
#endif

that the compiler is now able to figure out at compile time that "Unknown" is not equal to "AuthenticAMD" or "GenuineIntel".

I'd think a better "hotfix" would be to just return UNKNOWN_CPU; from the #else branch. In a bit longer term, I'd like to understand if this code is really needed, and if it is, what would be the implication for ARM and Power.

@Dr15Jones @dan131riley

@iarspider
Copy link
Contributor Author

@makortel good catch. Updated the code. I left this part in case there is an x86/x64 CPU that is not AMD or Intel:
https://github.com/cms-sw/cmssw/pull/36467/files#diff-a1bdb31e4f19fa367abed88913f55b6f1669032d65492064d2bb088f8fd86535L101

@makortel
Copy link
Contributor

In a bit longer term, I'd like to understand if this code is really needed, and if it is, what would be the implication for ARM and Power.

Sorry, I realized I was confusing. With "this code" I meant MallocOpts altogether.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36467/27333

  • This PR adds an extra 16KB to repository

@cmsbuild
Copy link
Contributor

Pull request #36467 was updated. @cmsbuild, @smuzaffar, @Dr15Jones, @makortel can you please check and sign again.

@makortel
Copy link
Contributor

@cmsbuild, please test

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-bd3489/21220/summary.html
COMMIT: ddd2617
CMSSW: CMSSW_12_3_X_2021-12-12-2300/slc7_amd64_gcc900
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/36467/21220/install.sh to create a dev area with all the needed externals and cmssw changes.

The following merge commits were also included on top of IB + this PR after doing git cms-merge-topic:

You can see more details here:
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-bd3489/21220/git-recent-commits.json
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-bd3489/21220/git-merge-result

CMS deprecated warnings: 39 CMS deprecated warnings found, see summary page for details.

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 6 differences found in the comparisons
  • DQMHistoTests: Total files compared: 42
  • DQMHistoTests: Total histograms compared: 3250704
  • DQMHistoTests: Total failures: 11
  • DQMHistoTests: Total nulls: 1
  • DQMHistoTests: Total successes: 3250670
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: -0.004 KiB( 41 files compared)
  • DQMHistoSizes: changed ( 312.0 ): -0.004 KiB MessageLogger/Warnings
  • Checked 177 log files, 37 edm output root files, 42 DQM output files
  • TriggerResults: no differences found

@makortel
Copy link
Contributor

+1

@cmsbuild
Copy link
Contributor

This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @perrotta, @dpiparo, @qliphy (and backports should be raised in the release meeting by the corresponding L2)

@qliphy
Copy link
Contributor

qliphy commented Dec 15, 2021

+1

@cmsbuild cmsbuild merged commit a75d65d into cms-sw:master Dec 15, 2021
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.

4 participants