Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

RIRF49 loop-convert doesn't recognize end-caching iterative loop #22195

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22196
Status REOPENED
Importance P normal
Reported by Richard (legalize@xmission.com)
Reported on 2015-01-11 13:41:19 -0800
Last modified on 2018-03-11 13:48:33 -0700
Version unspecified
Hardware PC Linux
CC alexfh@google.com, angelgarcia@google.com, djasper@google.com, edwin.vane@intel.com, klimek@google.com
Fixed by commit(s)
Attachments RIRF49.zip (73491 bytes, application/zip)
Blocks
Blocked by
See also
Created attachment 13666
test suite

See test case RIRF49 in ReplaceITerativeForWithRangeFor.cpp:

    std::vector<int> c;
    c.push_back('f');
    c.push_back('o');
    c.push_back('o');

    int sum = 0;
    // #TEST#: RIRF49 Replace iterative for with range for
    for (std::vector<int>::const_iterator it = c.cbegin(), end = c.cend();
        it != end; ++it)
    {
        sum += *it;
    }
    assert(int('f') + int('o') + int('o') == sum);

This is a fairly common idiom where people calculate the "end" value once and
then repeatedly compare against it while iterating over the container.

clang-modernize 3.5 build from svn
Quuxplusone commented 9 years ago

Attached RIRF49.zip (73491 bytes, application/zip): test suite

Quuxplusone commented 9 years ago

Test cases RIRF50, RIRF51, RIRF52, RIRF53, and RIRF55 also fail for the same reason.

Quuxplusone commented 9 years ago

Fixed in r248994.

Quuxplusone commented 6 years ago
This still fails when the code tests for end != it instead of it != end

    std::vector<int> c;
    c.push_back('f');
    c.push_back('o');
    c.push_back('o');

    int sum = 0;
    // #TEST#: RIRF50 Replace iterative for with range for
    for (std::vector<int>::const_iterator it = c.cbegin(), end = c.cend();
        end != it; ++it)
    {
        sum += *it;
    }
Quuxplusone commented 6 years ago
To reproduce:

git clone https://github.com/LegalizeAdulthood/refactor-test-suite
cd refactor-test-suite
Use CMake to generate build with compile_commans.json
Apply clang-tidy to file ReplaceIterativeForWithRangeFor.cpp

Check test cases RIRF50, RIRF51, RIRF52, RIRF53, and RIRF55

Test case RIRF49 now passes.