[LLVMbugs] [Bug 13870] New: Combination of vector and pair with armadillo library leed to memory corruption

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 19 02:00:54 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13870

             Bug #: 13870
           Summary: Combination of vector and pair with armadillo library
                    leed to memory corruption
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ldan at gmx.net
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9229
  --> http://llvm.org/bugs/attachment.cgi?id=9229
Example triggering the problem. Compile with "clang++ -std=c++11 clangtest.cpp"

The following code works with g++ 4.7, but gives wrong results using Clang 3.1
on Arch Linux with the Armadillo library 3.4.0 (http://arma.sourceforge.net/)
    double a = 0, b = 0;
    std::vector<std::pair<arma::vec2, int>> list;

    for(int i = 0; i < 10; ++i) {
        a += 1.0;
        b += 2.0;
        list.push_back(std::pair<arma::vec2, int>{arma::vec2{a,b}, 1});
    }

    for(int i = 0; i < list.size(); ++i)
        std::cout << list.at(i).first(0) << "\t"
            << list.at(i).first(1) << std::endl;

Compiled with GCC the results are
  1       2
  2       4
  3       6
  4       8
  ...

With clang++ old values in the vector seem to be getting overwritten and the
results look like this:
2       4
3       6
5       10
5       10
9       18
9       18
9       18
9       18
9       18
10      20

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list