public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code
@ 2011-05-18 13:48 bisqwit at iki dot fi
  2011-05-19  8:30 ` [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop bisqwit at iki dot fi
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-18 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Returns from lambda functions incorrectly detected as
                    "exits" from OpenMP loops in surrounding code
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@iki.fi


GCC incorrectly considers return statements within lambda functions as "exits"
from an OpenMP structured block.

For the code below, this error message is generated:

tmp3.cc: In lambda function:
tmp3.cc:7:40: error: invalid exit from OpenMP structured block

#include <iostream>
int main()
{
    #pragma omp parallel for
    for(int a=0; a<10; ++a)
    {
        auto func = [=] () { return a; };
        std::cout << func();
    }
}

Compiled with: -fopenmp -std=gnu++0x
Tested versions: 4.5.3 , 4.6.1

The purpose of this error is to catch exits from an OpenMP construct (return,
break, goto). No such thing happens when a lamdba function is called, which is
not different from calling an inlined function, therefore the error message is
misplaced.


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
@ 2011-05-19  8:30 ` bisqwit at iki dot fi
  2011-05-19  9:03 ` bisqwit at iki dot fi
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-19  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Joel Yliluoma <bisqwit at iki dot fi> 2011-05-19 08:10:06 UTC ---
Even if the lambda function is not called, it happens. Merely defining the
function causes it.
Interestingly though, it does not happen if a method body is defined within the
loop. The code below does not cause the error. So it is restricted to lambda
function bodies.
It also does not happen when calling lambda functions that are defined outside
the loop.

int main()
{
    #pragma omp parallel for
    for(int a=0; a<10; ++a)
    {
        struct tmp
        {
            static int test() { return 0; }
        };
    }
}


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
  2011-05-19  8:30 ` [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop bisqwit at iki dot fi
@ 2011-05-19  9:03 ` bisqwit at iki dot fi
  2011-05-19  9:16 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-19  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

Joel Yliluoma <bisqwit at iki dot fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[C++0x] Returns from lambda |[OpenMP & C++0x]: Compiler
                   |functions incorrectly       |error when lambda-function
                   |detected as "exits" from    |within OpenMP loop
                   |OpenMP loops in surrounding |
                   |code                        |

--- Comment #1 from Joel Yliluoma <bisqwit at iki dot fi> 2011-05-19 08:05:26 UTC ---
It also happens if the lambda-function does not explicitly contain the "return"
statement.

For example, this code triggers the same error.

int main()
{
    #pragma omp parallel for
    for(int a=0; a<10; ++a)
    {
        auto func = [] () -> void { };
        func();
    }
}


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
  2011-05-19  8:30 ` [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop bisqwit at iki dot fi
  2011-05-19  9:03 ` bisqwit at iki dot fi
@ 2011-05-19  9:16 ` jakub at gcc dot gnu.org
  2011-05-19 13:30 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-05-19  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.05.19 08:55:08
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-05-19 08:55:08 UTC ---
Created attachment 24287
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24287
gcc46-pr49043.patch

Untested fix.

That said, I'd advise not to use lambdas in OpenMP regions, because the OpenMP
standard doesn't say anything about the data environment of those and how it
should behave.  Even the upcoming OpenMP 3.1 doesn't cover C++0x, I hope OpenMP
4.0 will.


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
                   ` (2 preceding siblings ...)
  2011-05-19  9:16 ` jakub at gcc dot gnu.org
@ 2011-05-19 13:30 ` jakub at gcc dot gnu.org
  2011-05-19 14:10 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-05-19 13:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-05-19 13:12:02 UTC ---
Author: jakub
Date: Thu May 19 13:11:56 2011
New Revision: 173907

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173907
Log:
    PR c++/49043
    * decl.c (check_omp_return): Stop searching on sk_function_parms.

    * testsuite/libgomp.c++/pr49043.C: New test.

Added:
    trunk/libgomp/testsuite/libgomp.c++/pr49043.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/libgomp/ChangeLog


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
                   ` (3 preceding siblings ...)
  2011-05-19 13:30 ` jakub at gcc dot gnu.org
@ 2011-05-19 14:10 ` jakub at gcc dot gnu.org
  2011-05-19 14:29 ` jakub at gcc dot gnu.org
  2011-07-25  9:54 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-05-19 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-05-19 13:39:33 UTC ---
Fixed.


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
                   ` (4 preceding siblings ...)
  2011-05-19 14:10 ` jakub at gcc dot gnu.org
@ 2011-05-19 14:29 ` jakub at gcc dot gnu.org
  2011-07-25  9:54 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-05-19 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-05-19 13:14:00 UTC ---
Author: jakub
Date: Thu May 19 13:13:57 2011
New Revision: 173908

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173908
Log:
    PR c++/49043
    * decl.c (check_omp_return): Stop searching on sk_function_parms.

    * testsuite/libgomp.c++/pr49043.C: New test.

Added:
    branches/gcc-4_6-branch/libgomp/testsuite/libgomp.c++/pr49043.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/libgomp/ChangeLog


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

* [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop
  2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
                   ` (5 preceding siblings ...)
  2011-05-19 14:29 ` jakub at gcc dot gnu.org
@ 2011-07-25  9:54 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-25  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-25 09:54:13 UTC ---
*** Bug 49100 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2011-07-25  9:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-18 13:48 [Bug c++/49043] New: Returns from lambda functions incorrectly detected as "exits" from OpenMP loops in surrounding code bisqwit at iki dot fi
2011-05-19  8:30 ` [Bug c++/49043] [OpenMP & C++0x]: Compiler error when lambda-function within OpenMP loop bisqwit at iki dot fi
2011-05-19  9:03 ` bisqwit at iki dot fi
2011-05-19  9:16 ` jakub at gcc dot gnu.org
2011-05-19 13:30 ` jakub at gcc dot gnu.org
2011-05-19 14:10 ` jakub at gcc dot gnu.org
2011-05-19 14:29 ` jakub at gcc dot gnu.org
2011-07-25  9:54 ` 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).