http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49651
--- Comment #3 from Pedro Larroy <pedro.larroy at gmail dot com> 2011-07-05 
22:24:26 UTC ---
(In reply to comment #2)
> Can you produce a testcase that aborts/fails if the problem occurs? Otherwise 
> I
> seem to need to inspect thousands of lines to look for non-consecutive values!
> 
> Could this be the same underlying issue as PR 49598 and so (very recently)
> fixed?

It doesn't look the same to me since the variable doesn't have garbage, but I
don't have enough insight to judge. Can you point to which particular source
file to check to investigate this?

Here is the program that asserts on error. Works with -O0 and fails with -O3
quite soon (12 iterations):


g++-4.6 -Wall -std=c++0x -O3 -o test test.cc




#include <iostream>
#include <string>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <stdexcept>
#include <stdint.h>
#include <algorithm>
#include <stdint.h>

typedef uint32_t u32;
using namespace std;
vector<u32> g;
void f(u32 a, u32 b) 
{   
    g.push_back(b);
    for(size_t i=1; i<g.size() && ! g.empty(); ++i) {
        if ( g[i-1]+1 != g[i]) {
            cerr << g[i-1]+1 << " != " << g[i] << endl;
            cerr << "g: " << endl;
            for(size_t i=0; i<g.size() && ! g.empty(); ++i)
                cerr << g[i] << endl;
            assert(0);
        }
    }
}

int main(int argc, char *argv[])
{
    u32 a = 0;
    vector<int> vi;
    vi.push_back(0);
    vi.push_back(1);
    vi.push_back(2);
    vi.push_back(3);
    vi.push_back(4);


    vector<int> vo;
    vo.push_back(5);
    vo.push_back(5);

    vector<int> ve;
    ve.push_back(5);


    vector<int> v3;
    vector<int> v4;
    vector<int> v5;
    vector<int> v6;
    vector<int> v7;

    f(32, a++);
    cout << "bmain.a: " << a << endl;

    f(32, a++);
    cout << "bmain.a: " << a << endl;


    auto run = [&](int& i) {
        // inside this lambda &a is not the same as the &a in the first line
        v3.push_back(i);
        v4.push_back(i);
        v5.push_back(i);
        v6.push_back(i);
        v7.push_back(i);
        f(32, a++);
        cout << "run.a: " << a << endl;

        v3.push_back(i);
        v4.push_back(i);
        v5.push_back(i);
        v6.push_back(i);
        v7.push_back(i);
        f(32, a++);
        cout << "run.a: " << a << endl;



        for_each(ve.begin(), ve.end(), [&](int& xi) {
            v7.push_back(xi);
            f(32, a++);
            cout << "run.for_each.a: " << a << endl;

        });

        f(32, a++);
        cout << "run.a: " << a << endl;
    };

    f(32, a++);
    cout << "main.a: " << a << endl;

    while(true) {
    for_each(vi.begin(), vi.end(), [&](int& xi) {
        f(32, a++);
        cout << "1 for_each.a: " << a << endl;


        for_each(vo.begin(), vo.end(), run);

        f(32, a++);
        cout << "1 for_each.a: " << a << endl;


        for_each(ve.begin(), ve.end(), run);

        f(32, a++);
        cout << "1 for_each.a: " << a << endl;


    });
    }
    cout << "main.a: " << a << endl;
}

Reply via email to