public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
@ 2021-03-10  8:45 burnus at gcc dot gnu.org
  2021-03-10 10:15 ` [Bug c++/99509] " burnus at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-03-10  8:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

            Bug ID: 99509
           Summary: [OpenMP] 'omp declare target' for global variable →
                    "hasn't been marked to be included in the offloaded
                    code"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: openmp, rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: cltang at gcc dot gnu.org, jakub at gcc dot gnu.org
  Target Milestone: ---

The following code fails when compiled for offloading with:

foo3.cc:2:7: error: variable 'data' has been referenced in offloaded code but
hasn't been marked to be included in the offloaded code
    2 |  int data[]={5};
      |      ^
lto1: fatal error: errors during merging of translation units



#pragma omp declare target
  int data[]={5};
#pragma omp end declare target

struct my { inline const int& operator[](const int idx) const { return
data[idx]; } };

int main()
{
  int i;
  struct my cs;
  #pragma omp target map(to:i)
    i = cs[0];
  return i;
}

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

* [Bug c++/99509] [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
  2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
@ 2021-03-10 10:15 ` burnus at gcc dot gnu.org
  2021-03-10 11:37 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-03-10 10:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Variant which also is valid C:

#pragma omp declare target
  int data[]={5};
#pragma omp end declare target

inline int foo(int idx) { return data[idx]; }

int main()
{
  int i;
  #pragma omp target map(to:i)
    i = foo(0);
  return i;
}


Result as follows; enclosing the 'foo' in the declare-target block has no
effect.


With g++ this still fails with:

bar2.cc:2:7: error: variable 'data' has been referenced in offloaded code but
hasn't been marked to be included in the offloaded code
    2 |   int data[]={5};
      |       ^
lto1: fatal error: errors during merging of translation units


But with cc it fails with:

unresolved symbol foo
mkoffload: fatal error: ...

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

* [Bug c++/99509] [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
  2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
  2021-03-10 10:15 ` [Bug c++/99509] " burnus at gcc dot gnu.org
@ 2021-03-10 11:37 ` jakub at gcc dot gnu.org
  2021-03-10 15:08 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-10 11:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #1)
> But with cc it fails with:
> 
> unresolved symbol foo
> mkoffload: fatal error: ...

For C99 and later you'd need either static inline, or extern inline, inline
means the compiler can use the body but that the definition is provided
somewhere else if it is not inlined.

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

* [Bug c++/99509] [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
  2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
  2021-03-10 10:15 ` [Bug c++/99509] " burnus at gcc dot gnu.org
  2021-03-10 11:37 ` jakub at gcc dot gnu.org
@ 2021-03-10 15:08 ` burnus at gcc dot gnu.org
  2021-03-15  9:13 ` cvs-commit at gcc dot gnu.org
  2021-03-15 10:31 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-03-10 15:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566547.html

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

* [Bug c++/99509] [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
  2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-03-10 15:08 ` burnus at gcc dot gnu.org
@ 2021-03-15  9:13 ` cvs-commit at gcc dot gnu.org
  2021-03-15 10:31 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-15  9:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:f20fe2cb213dffba47ec1b62c625590b5bbe50d7

commit r11-7665-gf20fe2cb213dffba47ec1b62c625590b5bbe50d7
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Mar 15 10:12:58 2021 +0100

    OpenMP: Fix 'omp declare target' handling for vars [PR99509]

    For variables with 'declare target' attribute,
    varpool_node::get_create marks variables as offload; however,
    if the node already exists, it is not updated. C/C++ may tag
    decl with 'declare target implicit', which may only be after
    varpool creation turned into 'declare target' or 'declare target link';
    in this case, the tagging has to happen in the FE.

    gcc/c/ChangeLog:

            PR c++/99509
            * c-decl.c (finish_decl): For 'omp declare target implicit' vars,
            ensure that the varpool node is marked as offloadable.

    gcc/cp/ChangeLog:

            PR c++/99509
            * decl.c (cp_finish_decl): For 'omp declare target implicit' vars,
            ensure that the varpool node is marked as offloadable.

    libgomp/ChangeLog:

            PR c++/99509
            * testsuite/libgomp.c-c++-common/declare_target-1.c: New test.

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

* [Bug c++/99509] [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code"
  2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-03-15  9:13 ` cvs-commit at gcc dot gnu.org
@ 2021-03-15 10:31 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-03-15 10:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99509

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
FIXED on mainline (GCC 11).

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

end of thread, other threads:[~2021-03-15 10:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  8:45 [Bug c++/99509] New: [OpenMP] 'omp declare target' for global variable → "hasn't been marked to be included in the offloaded code" burnus at gcc dot gnu.org
2021-03-10 10:15 ` [Bug c++/99509] " burnus at gcc dot gnu.org
2021-03-10 11:37 ` jakub at gcc dot gnu.org
2021-03-10 15:08 ` burnus at gcc dot gnu.org
2021-03-15  9:13 ` cvs-commit at gcc dot gnu.org
2021-03-15 10:31 ` burnus 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).