This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix crash on "reference to array" parameters in 'bugprone-easily-swappable-parameters'
ClosedPublic

Authored by whisperity on Jul 28 2021, 4:41 AM.

Details

Summary

Fixes #50995.

A(n otherwise unexercised) code path related to trying to model "array-to-pointer decay" resulted in a null pointer dereference crash when parameters of type "reference to array" are encountered.

The aforementioned code path is not needed, as cases when arrays can decay are already handled by the main function of the modelling routine when desugaring the DecayedType.

Diff Detail

Event Timeline

whisperity created this revision.Jul 28 2021, 4:41 AM
whisperity requested review of this revision.Jul 28 2021, 4:41 AM

Add some more test cases!

NFC Typo-fix: Remove empty line from end of diff.

aaron.ballman added inline comments.Jul 28 2021, 5:23 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
46

Can you also add a test case like:

template <int N, int M>
void func(int (&array1)[N], int (&array2)[M]) {}

void instantiate() {
  int foo[12], bar[12];
  func(foo, bar);

  int baz[12], quux[42];
  func(baz, quux);
}
whisperity added inline comments.Jul 28 2021, 5:31 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
46

(Implicitly) instantiated decls are excluded from the check as a whole, so this test case will not drive the check.

Add a test case where the referenced arrays are deduced from template parameters.

whisperity marked an inline comment as done.Jul 28 2021, 5:37 AM
aaron.ballman accepted this revision.Jul 28 2021, 5:41 AM

LGTM

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.cpp
60

Thank you for adding the comment, I'd have otherwise assumed there was a bug with the first example in this function not warning. :-)

This revision is now accepted and ready to land.Jul 28 2021, 5:41 AM
This revision was landed with ongoing or failed builds.Jul 28 2021, 5:45 AM
This revision was automatically updated to reflect the committed changes.