This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated
ClosedPublic

Authored by JonasToth on Jul 29 2022, 11:57 AM.

Details

Summary

'misc-const-correctness' previously considered arrays as 'Values' independent of the type of the elements.
This is inconsistent with the configuration of the check to disable treating pointers as values.
This patch rectifies this inconsistency.

Fixes #56749

Diff Detail

Event Timeline

JonasToth created this revision.Jul 29 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2022, 11:57 AM
JonasToth requested review of this revision.Jul 29 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2022, 11:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
JonasToth added inline comments.Jul 30 2022, 2:34 AM
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
77

the tests must be exanded to check that typedefs in arrays are handled properly.

JonasToth updated this revision to Diff 450358.Aug 5 2022, 12:36 PM
  • add test with typedef
  • [docs] improve documentation for misc-const-correctness
JonasToth updated this revision to Diff 450359.Aug 5 2022, 12:43 PM
  • improve test
njames93 added inline comments.Aug 5 2022, 3:18 PM
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
14

Typically don't need this include.

clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
7 ↗(On Diff #450359)

These documentation changes should be split into their own patch.
Same goes for below

JonasToth updated this revision to Diff 454031.Aug 19 2022, 8:54 AM
JonasToth marked an inline comment as done.
  • split patch
  • remove unnecessary includes
JonasToth marked an inline comment as done.Aug 19 2022, 8:55 AM
JonasToth updated this revision to Diff 454032.Aug 19 2022, 8:56 AM
  • remove bad change from diff
njames93 added inline comments.Aug 27 2022, 2:33 AM
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
27–30

Wouldn't this behaviour be expected before the changes added in this patch, as p_local1 isn't an array type.

JonasToth added inline comments.Aug 29 2022, 12:42 AM
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp
27–30

the behaviour for p_local1 does not change with the patch and is tested/moved here.

only p_local0 has a behaviour change. this test file activates the analysis for pointers-as-values, so it must be diagnosed in this test file.
in the other test-file -values.cpp p_local0 is not diagnosed, making it np_local0.

originally, the tests for the range based for loops lived in the values part of the tests. As this is incorrect for the pointer-arrays I moved them into this file instead (for pointer arrays).
the tests here mostly verify that the variables are properly matched and filtered. The actual analysis has its own unit tests for these cases.

JonasToth marked an inline comment as done.Sep 17 2022, 4:29 AM

ping @njames93 :)

njames93 accepted this revision.Sep 17 2022, 6:39 AM

LGTM, just with one small testing nit

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
533

This not fixes line is pretty redundant, and unstable. If you really want to ensure no fix was generated, you can do a check-fixes with the original line contents. But as there is no warning generated here there shouldn't be a need to check for any fix behaviour, same goes below.

This revision is now accepted and ready to land.Sep 17 2022, 6:39 AM
JonasToth marked an inline comment as done.Sep 25 2022, 11:14 AM
JonasToth updated this revision to Diff 462838.Sep 26 2022, 1:37 AM
  • remove unproductive check-fixes line
This revision was landed with ongoing or failed builds.Sep 26 2022, 1:39 AM
This revision was automatically updated to reflect the committed changes.