public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49651] New: [C++0x] nested lambdas and -O3 produced incorrect integer variable increments
@ 2011-07-05 20:15 pedro.larroy at gmail dot com
  2011-07-05 20:30 ` [Bug c++/49651] " pedro.larroy at gmail dot com
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: pedro.larroy at gmail dot com @ 2011-07-05 20:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49651

           Summary: [C++0x] nested lambdas and -O3 produced incorrect
                    integer variable increments
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pedro.larroy@gmail.com


Hi. I'm trying to reproduce this outside 'production' code but haven't been
successful yet. But the observation is the following:

I have 3 level nested lambdas iterating some vectors. Inside, printing and
incrementing this 'sentinel' variable, the output with -O3 shows the wrong
output:

0. sentinel: deadbee5
2. sentinel: deadbee6
1. sentinel: deadbee7
1. sentinel: deadbee8
3. sentinel: deadbee7
4. sentinel: deadbee8
1. sentinel: deadbee9
5. sentinel: deadbee9
6. sentinel: deadbeea
2. sentinel: deadbeeb

With -O0 the values are consecutive. The code is similar to:

u32 sentinel=0xdeadbee0;
auto run = [&](Class& c) {
   for_each(v3.begin(), v3.end(), [&](ClassC& cc) {
       print(sentinel++);
   });
   print(sentinel++);
};
for_each(v.begin(), v.end(), [&](ClassB& b) {

   for_each(v2.begin(), v2.end(), run);
   print(sentinel++);
});


I have observed that the sentinel variable for example, is captured inside the
lambda and the address is not the same as the outermost sentinel...   could
that be the problem that leads to the wrong optimizations?


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2012-03-13 17:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05 20:15 [Bug c++/49651] New: [C++0x] nested lambdas and -O3 produced incorrect integer variable increments pedro.larroy at gmail dot com
2011-07-05 20:30 ` [Bug c++/49651] " pedro.larroy at gmail dot com
2011-07-05 21:54 ` redi at gcc dot gnu.org
2011-07-05 22:24 ` pedro.larroy at gmail dot com
2011-07-05 23:54 ` redi at gcc dot gnu.org
2011-07-12 14:39 ` [Bug tree-optimization/49651] " jason at gcc dot gnu.org
2011-07-12 15:21 ` rguenth at gcc dot gnu.org
2011-07-13 12:32 ` rguenth at gcc dot gnu.org
2011-07-14 12:27 ` rguenth at gcc dot gnu.org
2011-07-14 12:37 ` rguenth at gcc dot gnu.org
2011-07-14 13:02 ` [Bug tree-optimization/49651] [4.4/4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
2011-07-14 14:54 ` rguenth at gcc dot gnu.org
2011-07-14 14:57 ` rguenth at gcc dot gnu.org
2011-07-14 15:01 ` [Bug tree-optimization/49651] [4.4/4.5 " rguenth at gcc dot gnu.org
2011-08-01 14:09 ` rguenth at gcc dot gnu.org
2011-08-01 16:00 ` pedro.larroy at gmail dot com
2012-01-04  9:48 ` rguenth at gcc dot gnu.org
2012-01-04  9:50 ` rguenth at gcc dot gnu.org
2012-01-04 11:55 ` rguenth at gcc dot gnu.org
2012-01-04 11:56 ` [Bug tree-optimization/49651] [4.4 " rguenth at gcc dot gnu.org
2012-03-13 17:00 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).