public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop
@ 2011-05-21 11:45 bisqwit at iki dot fi
  2011-05-21 12:01 ` [Bug c++/49100] " bisqwit at iki dot fi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-21 11:45 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [OpenMP]: Compiler error when inline method defined
                    within OpenMP loop
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@iki.fi


This report is similar to PR49043, but unlike it, this does not involve C++0x.

This valid code fails to compile on GCC.
GCC spews an "invalid exit from OpenMP structured block" error message.

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

If the explicit "return" statement is removed, it compiles.
It is also triggered by code such as this:

struct y
{
    static bool test(int c) { return c==5; }
};

if put inside the OpenMP loop construct, meaning it happens for static and
non-static methods as long as they include an explicit "return" statement.

The purpose of this error is to catch exits from an OpenMP construct (return,
break, goto). No such thing happens when a function is called or defined. The
error is not given when the struct is defined outside the loop (even if invoked
inside the loop). It is clearly a parser error.

It failed on all GCC versions that I tried that support OpenMP. These include
GCC 4.2.4, 4.3.5, 4.4.6, 4.5.3 and 4.6.1.

I have not tested whether the patch committed as a result of PR49043 also fixes
this bug.


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

* [Bug c++/49100] [OpenMP]: Compiler error when inline method defined within OpenMP loop
  2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
@ 2011-05-21 12:01 ` bisqwit at iki dot fi
  2011-07-25  9:55 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-21 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Joel Yliluoma <bisqwit at iki dot fi> 2011-05-21 11:31:46 UTC ---
It also does not happen with C's nested functions. This for instance compiles
and works just fine (to my surprise).

#include <stdio.h>
int main()
{
    int a;
    #pragma omp parallel for
    for(a=0; a<10; ++a)
    {
        int c() { return 65; }
        putchar( c() );
    }
    return 0;
}

I venture into another bug report here, but I wonder if this is a bug or
intentional behavior, that the code below outputs "YYYYYYYYYY", as though the
variable "a" within c() is bound to the a from the surrounding context rather
than the OpenMP loop's private copy of "a". If the OpenMP loop is removed, it
outputs "ABCDEFGHIJ" as expected.

#include <stdio.h>
int main()
{
    int a = 24;
    #pragma omp parallel for
    for(a=0; a<10; ++a)
    {
        int c() { return a+65; }
        putchar( c() );
    }
    return 0;
}


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

* [Bug c++/49100] [OpenMP]: Compiler error when inline method defined within OpenMP loop
  2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
  2011-05-21 12:01 ` [Bug c++/49100] " bisqwit at iki dot fi
@ 2011-07-25  9:55 ` jakub at gcc dot gnu.org
  2011-07-25 10:01 ` bisqwit at iki dot fi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-25  9:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-25 09:54:13 UTC ---
The first comment has been resolved by PR49043, at least I can't reproduce this
anymore with current trunk or 4.6.
The second is a user bug, OpenMP standard says that you shouldn't reference in
a parallel region the original copy of the variable and you do exactly that
through the nested function.

*** This bug has been marked as a duplicate of bug 49043 ***


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

* [Bug c++/49100] [OpenMP]: Compiler error when inline method defined within OpenMP loop
  2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
  2011-05-21 12:01 ` [Bug c++/49100] " bisqwit at iki dot fi
  2011-07-25  9:55 ` jakub at gcc dot gnu.org
@ 2011-07-25 10:01 ` bisqwit at iki dot fi
  2011-07-25 10:10 ` jakub at gcc dot gnu.org
  2011-07-25 10:25 ` bisqwit at iki dot fi
  4 siblings, 0 replies; 6+ messages in thread
From: bisqwit at iki dot fi @ 2011-07-25 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Joel Yliluoma <bisqwit at iki dot fi> 2011-07-25 10:01:08 UTC ---
While it's true that one should not reference the original variable within the
loop, question is, why does the inner function reference the original variable
rather than the inloop variable when there's no explicit reference to the
original variable. A reference is established, by name, within the loop, but
within the loop there should be no possible way to reference the outside-loop
variable because the inner-loop namespace shadows the outer one, and hence the
reference should bind into the inner-loop variable, thus conforming to OpenMP
specification.


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

* [Bug c++/49100] [OpenMP]: Compiler error when inline method defined within OpenMP loop
  2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
                   ` (2 preceding siblings ...)
  2011-07-25 10:01 ` bisqwit at iki dot fi
@ 2011-07-25 10:10 ` jakub at gcc dot gnu.org
  2011-07-25 10:25 ` bisqwit at iki dot fi
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-25 10:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-25 10:10:04 UTC ---
You are outside of the scope of OpenMP standard and C99 language.  GNU nested
functions and OpenMP simply don't play nicely together if the containing
function has #pragma omp parallel or #pragma omp task.


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

* [Bug c++/49100] [OpenMP]: Compiler error when inline method defined within OpenMP loop
  2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
                   ` (3 preceding siblings ...)
  2011-07-25 10:10 ` jakub at gcc dot gnu.org
@ 2011-07-25 10:25 ` bisqwit at iki dot fi
  4 siblings, 0 replies; 6+ messages in thread
From: bisqwit at iki dot fi @ 2011-07-25 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Joel Yliluoma <bisqwit at iki dot fi> 2011-07-25 10:24:20 UTC ---
Obviously :) All right, thanks.


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-21 11:45 [Bug c++/49100] New: [OpenMP]: Compiler error when inline method defined within OpenMP loop bisqwit at iki dot fi
2011-05-21 12:01 ` [Bug c++/49100] " bisqwit at iki dot fi
2011-07-25  9:55 ` jakub at gcc dot gnu.org
2011-07-25 10:01 ` bisqwit at iki dot fi
2011-07-25 10:10 ` jakub at gcc dot gnu.org
2011-07-25 10:25 ` bisqwit at iki dot fi

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).