Handle 'omp declare target' attribute set for both OpenACC and OpenMP 'target' [PR894...
authorThomas Schwinge <thomas@codesourcery.com>
Wed, 4 Mar 2020 16:58:33 +0000 (17:58 +0100)
committerThomas Schwinge <thomas@codesourcery.com>
Fri, 10 Apr 2020 13:34:22 +0000 (15:34 +0200)
... which as of PR89433 commit b48f44bf77a39fefc238a16cf1225c6464c82406 causes
an ICE.  Not sure if this is actually supposed to be valid or invalid code.
Until the interactions between OpenACC and OpenMP 'target' get defined
properly, make this a compile-time error.

gcc/
PR middle-end/89433
PR middle-end/93465
* omp-general.c (oacc_verify_routine_clauses): Diagnose if
"#pragma omp declare target" has also been applied.
gcc/testsuite/
PR middle-end/89433
PR middle-end/93465
* c-c++-common/goacc-gomp/pr93465-1.c: New file.

gcc/ChangeLog
gcc/omp-general.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/goacc-gomp/pr93465-1.c [new file with mode: 0644]

index bce700e..33e980b 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-10  Thomas Schwinge  <thomas@codesourcery.com>
+
+       PR middle-end/89433
+       PR middle-end/93465
+       * omp-general.c (oacc_verify_routine_clauses): Diagnose if
+       "#pragma omp declare target" has also been applied.
+
 2020-04-09  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * config/msp430/msp430.c (msp430_expand_epilogue): Use emit_jump_insn
index f107f4c..49023f4 100644 (file)
@@ -1776,6 +1776,19 @@ oacc_verify_routine_clauses (tree fndecl, tree *clauses, location_t loc,
     = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl));
   if (attr != NULL_TREE)
     {
+      /* Diagnose if "#pragma omp declare target" has also been applied.  */
+      if (TREE_VALUE (attr) == NULL_TREE)
+       {
+         /* See <https://gcc.gnu.org/PR93465>; the semantics of combining
+            OpenACC and OpenMP 'target' are not clear.  */
+         error_at (loc,
+                   "cannot apply %<%s%> to %qD, which has also been"
+                   " marked with an OpenMP 'declare target' directive",
+                   routine_str, fndecl);
+         /* Incompatible.  */
+         return -1;
+       }
+
       /* If a "#pragma acc routine" has already been applied, just verify
         this one for compatibility.  */
       /* Collect previous directive's clauses.  */
index bced3e2..235d481 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-10  Thomas Schwinge  <thomas@codesourcery.com>
+
+       PR middle-end/89433
+       PR middle-end/93465
+       * c-c++-common/goacc-gomp/pr93465-1.c: New file.
+
 2020-04-10  Iain Buclaw  <ibuclaw@gdcproject.org>
 
        * lib/gdc.exp (gdc_link_flags): Remove libdruntime library paths.
diff --git a/gcc/testsuite/c-c++-common/goacc-gomp/pr93465-1.c b/gcc/testsuite/c-c++-common/goacc-gomp/pr93465-1.c
new file mode 100644 (file)
index 0000000..c8b9135
--- /dev/null
@@ -0,0 +1,56 @@
+#pragma omp declare target
+#pragma acc routine seq /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f1\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+void f1 (void) {}
+#pragma omp end declare target
+
+#pragma omp declare target
+void f1 (void);
+
+#pragma acc routine seq /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f1\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+void f1 (void);
+
+
+
+#pragma omp declare target
+#pragma acc routine /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f2\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+extern void f2 (void);
+#pragma omp end declare target
+
+#pragma omp declare target
+extern void f2 (void);
+#pragma omp end declare target
+
+#pragma acc routine gang /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f2\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+extern void f2 (void);
+
+
+#pragma omp declare target
+#pragma acc routine gang /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f3\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+void f3 (void);
+#pragma omp end declare target
+
+#pragma omp declare target
+void f3 (void) {}
+#pragma omp end declare target
+
+#pragma acc routine (f3) gang /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f3\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+
+
+/* Surprisingly, this diagnosis also works for '#pragma acc routine' first,
+   followed by '#pragma omp declare target'; the latter gets applied first.  */
+
+
+#pragma acc routine /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f4\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+extern void f4 (void);
+
+#pragma omp declare target
+extern void f4 (void);
+#pragma omp end declare target
+
+
+#pragma acc routine gang /* { dg-error "cannot apply '#pragma acc routine' to '\(void \)?f5\(\\(\\)\)?', which has also been marked with an OpenMP 'declare target' directive" } */
+void f5 (void) {}
+
+#pragma omp declare target
+extern void f5 (void);
+#pragma omp end declare target