This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix incorrect array name generation in cppcoreguidelines-pro-bounds-constant-array-index
Needs ReviewPublic

Authored by Quolyk on Jan 14 2019, 5:13 AM.

Details

Summary

This patch fixes incorrect array name generation for a cppcoreguidelines-pro-bounds-constant-array-index warning.
Motivation: https://bugs.llvm.org/show_bug.cgi?id=38510.

Event Timeline

Quolyk created this revision.Jan 14 2019, 5:13 AM

For now I just updated tests. The problem is in BaseRange definition, as it holds EndLoc and BeginLoc pointing to the beginning of ArrayExpression base https://github.com/llvm-mirror/clang-tools-extra/blob/e0441f6939da38f26bea9c1d75bb33024daa4e40/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp#L78. I'm investigating this.

Quolyk updated this revision to Diff 181763.Jan 15 2019, 3:22 AM

Patch is not yet fixed.

Thank you for working on this!

Could you please run the check over LLVM or any other significant codebase once you have the fix implemented and report if the transformation still breaks code?

alexfh removed a reviewer: alexfh.Jan 23 2019, 5:00 AM
Quolyk updated this revision to Diff 209485.Jul 12 2019, 7:52 AM

Update. Solution is not elegant, because DeclRef->BaseRange somehow has zero length.

Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2019, 7:52 AM
Herald added a subscriber: wuzish. · View Herald Transcript

Sorry for the long delay!

I have one question about a slighty different code constellation.

std::optional<std::array<int, 4>> my_array;

for(int i = 0; i < 42; ++i)
    (*my_array)[i] = 42;

Will this be fixed properly?

for(int i = 0; i < 42; ++i)
    gsl::at(*my_array, i) = 42;

If the braces in (*my_array) would be moved into the function that is ok as well.

This is just of general interest and should not block this patch in my opinion, as its a different bug.