Merge 'c-c++-common/goacc/routine-6.c' into 'c-c++-common/goacc/routine-5.c', and document current C/C++ difference (was: [PATCH] openacc: Fix up C++ #pragma acc routine handling [PR101731])

Message ID 87wnj3dekd.fsf@euler.schwinge.homeip.net
State New
Headers show
Series
  • Merge 'c-c++-common/goacc/routine-6.c' into 'c-c++-common/goacc/routine-5.c', and document current C/C++ difference (was: [PATCH] openacc: Fix up C++ #pragma acc routine handling [PR101731])
Related show

Commit Message

Thomas Schwinge Jan. 13, 2022, 12:07 p.m.
Hi!

On 2021-11-22T16:02:31+0100, Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> On Mon, Nov 22, 2021 at 03:49:42PM +0100, Thomas Schwinge wrote:

>> Then, regarding the user-visible behavior:

>>

>> > +#pragma acc routine  /* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */

>> > +int foo (int bar ());

>>

>> So in C++ we now refuse, but in C we do accept this.  I suppose I shall

>> look into making C behave the same way -- unless there is a reason for

>> the different behavior?  And/or, is it actually is useful to allow such

>> nested usage?  Per its associated clauses, an OpenACC 'routine' directive

>> really is meant to apply to one function only, in contrast to OpenMP

>> 'target declare'.  But the question is whether we should raise an error

>> for the example above, or whether the 'routine' shall just apply to 'foo'

>> but not 'bar', but without an error diagnostic?

>

> All I've verified is that our OpenMP code handles it the same way,


Thanks for the explanation.

Pushed to master branch commit 67fdcc8835665b5bc13652205e815e498d65c5a1
"Merge 'c-c++-common/goacc/routine-6.c' into
'c-c++-common/goacc/routine-5.c', and document current C/C++ difference",
see attached.


Grüße
 Thomas


> i.e.

> #pragma omp declare simd

> int foo (int bar ());

> is accepted in C and rejected in C++.

> I guess one question is to check if it is in both languages actually

> the same thing.  If we want to accept it in C++ and let the pragma

> apply only to the outer declaration, I guess we'd need to temporarily

> set to NULL parser->omp_declare_simd and parser->oacc_routine while

> parsing the parameters of a function declaration or definition.

> At least OpenMP is fairly fuzzy here, the reason we error on

> #pragma omp declare simd

> int foo (), i;

> has been mainly some discussions in the lang committee and the fact

> that it talks about a single declaration, not all affected declarations.

> Whether int foo (int bar ()); should be in that light treated as two

> function declarations or one with another one nested in it and irrelevant

> for it is unclear.

>

>       Jakub



-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

Patch

From 67fdcc8835665b5bc13652205e815e498d65c5a1 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 22 Nov 2021 16:09:09 +0100
Subject: [PATCH] Merge 'c-c++-common/goacc/routine-6.c' into
 'c-c++-common/goacc/routine-5.c', and document current C/C++ difference

	gcc/testsuite/
	* c-c++-common/goacc/routine-6.c: Merge into...
	* c-c++-common/goacc/routine-5.c: ... this, and document current
	C/C++ difference.
---
 gcc/testsuite/c-c++-common/goacc/routine-5.c | 8 ++++++++
 gcc/testsuite/c-c++-common/goacc/routine-6.c | 4 ----
 2 files changed, 8 insertions(+), 4 deletions(-)
 delete mode 100644 gcc/testsuite/c-c++-common/goacc/routine-6.c

diff --git a/gcc/testsuite/c-c++-common/goacc/routine-5.c b/gcc/testsuite/c-c++-common/goacc/routine-5.c
index e3fbd6573b8..94678f2bf5b 100644
--- a/gcc/testsuite/c-c++-common/goacc/routine-5.c
+++ b/gcc/testsuite/c-c++-common/goacc/routine-5.c
@@ -94,6 +94,14 @@  typedef struct c_2 c_2;
 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
 struct d_2 {} d_2;
 
+/* PR c++/101731 */
+/* Regarding the current C/C++ difference, see
+   <http://mid.mail-archive.com/20211122150231.GP2646553@tucnak>.  */
+#pragma acc routine /* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */
+int pr101731_foo (int pr101731_bar ());
+#pragma acc routine (pr101731_foo) vector /* { dg-error "has already been marked with an OpenACC 'routine' directive" "" { target c } } */
+#pragma acc routine (pr101731_bar) vector /* { dg-error "'pr101731_bar' has not been declared" } */
+
 #pragma acc routine /* { dg-error ".#pragma acc routine. not immediately followed by function declaration or definition" } */
 #pragma acc routine
 int fn4 (void);
diff --git a/gcc/testsuite/c-c++-common/goacc/routine-6.c b/gcc/testsuite/c-c++-common/goacc/routine-6.c
deleted file mode 100644
index 0a231a015a7..00000000000
--- a/gcc/testsuite/c-c++-common/goacc/routine-6.c
+++ /dev/null
@@ -1,4 +0,0 @@ 
-/* PR c++/101731 */
-
-#pragma acc routine	/* { dg-error "not immediately followed by a single function declaration or definition" "" { target c++ } } */
-int foo (int bar ());
-- 
2.34.1