Modify

Opened 5 years ago

Last modified 4 years ago

#8438 new Bugs

vector & circular_buffer storage misbehave when using compiler optimizations

Reported by: ofir Owned by: Gunter
Milestone: To Be Determined Component: uBLAS
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc: Douglas Gregor, Jan Gaspar, ofirmebel@…

Description (last modified by viboes)

When compiling the following code without optimizations, it behaves as expected: (compiled with g++-4.7.2 with no flags at all)

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/circular_buffer.hpp>

int main () {
    boost::numeric::ublas::vector<double, boost::circular_buffer<double> > v (3, 1);
    std::cout << v << std::endl;
    v[1] = 5;
    std::cout << v << std::endl;
    std::cout << v[1] << std::endl;
    return 0;
}

Output:

[3](1,1,1)
[3](1,5,1)
5

When compiling the exact same code with O1, O2, and O3 it produces the following output:

[3](0,0,0)
[3](0,0,0)
5

I noticed that inner_prod() also sees the vector as zeros.

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by ofir <ofirmebel@…>

Cc: ofirmebel@… added

comment:2 Changed 5 years ago by Marshall Clow

I was able to replicate this with clang, but I got a warning which probably has some bearing here:

trunk/boost/numeric/ublas/vector.hpp:205:20: warning: returning reference to
      local temporary object [-Wreturn-stack-address]
            return data () [i];
                   ^~~~~~~~~~~
trunk/boost/numeric/ublas/io.hpp:58:18: note: in instantiation of member
      function 'boost::numeric::ublas::vector<double,
      boost::circular_buffer<double, std::allocator<double> > >::operator()'
      requested here
            s << v () (0);
                 ^
junk.cpp:7:15: note: in instantiation of function template specialization
      'boost::numeric::ublas::operator<<<char, std::char_traits<char>,
      boost::numeric::ublas::vector<double, boost::circular_buffer<double,
      std::allocator<double> > > >' requested here
    std::cout << v << std::endl;
              ^
1 warning generated.

comment:3 Changed 4 years ago by viboes

Description: modified (diff)

comment:4 Changed 4 years ago by viboes

Component: circular_bufferuBLAS
Owner: changed from Jan Gaspar to Gunter

Could some experts of UBlas take a look at this ticket? Please, reassign to circular buffer if this has nothing to be with UBlas.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Gunter.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.