From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2602 invoked by alias); 5 Jul 2011 20:15:41 -0000 Received: (qmail 2513 invoked by uid 22791); 5 Jul 2011 20:15:17 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jul 2011 20:15:03 +0000 From: "pedro.larroy at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49651] New: [C++0x] nested lambdas and -O3 produced incorrect integer variable increments X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: pedro.larroy at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 05 Jul 2011 20:15:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg00363.txt.bz2 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?