diff mbox

[PR59627,c++] Handle DECL_OMP_DECLARE_REDUCTION in discriminator_for_local_entity

Message ID 20160208110615.GD3017@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 8, 2016, 11:06 a.m. UTC
On Mon, Feb 08, 2016 at 11:20:57AM +0100, Tom de Vries wrote:
> When running libgomp testsuite with -flto, we run into an ICE in the udr-*.C
> tests.
> 
> A minimal testcase is in listed in PR59627:
> ...
> struct A { int i; };
> 
> void foo()
> {
>   A a;
>   #pragma omp declare reduction (+: A: omp_out.i += omp_in.i)
>   #pragma omp parallel reduction (+: a)
>   ;
> }
> ...
> The problem seems to be that we're trying to get a discriminator (the
> lexical ordinal of a var among entities with the same name in the same
> function) for a DECL_OMP_DECLARE_REDUCTION_P function, which is not handled
> in discriminator_for_local_entity.
> 
> For the test-case above the declared reduction is shown as:
> ...
>   void omp declare reduction operator+~1A (struct A &);
> ...
> 
> AFAIU, those DECL_OMP_DECLARE_REDUCTION_P decls are unique in a function, so
> I'd say we can simply return '0'.

They certainly aren't unique to a function, you can have hundreds of them:
void foo()
{  
  A a;
  {
    #pragma omp declare reduction (+: A: omp_out.i += omp_in.i)
    #pragma omp parallel reduction (+: a)
    ;
  }
  {
    #pragma omp declare reduction (+: A: omp_out.i += omp_in.i)
    #pragma omp parallel reduction (+: a)
    ;
  }
  {
    #pragma omp declare reduction (+: A: omp_out.i += omp_in.i)
    #pragma omp parallel reduction (+: a)
    ;
  }
//...
}
etc.  But they really should not be mangled, so IMHO it is better
to ensure they are not mangled, nothing really needs their mangled name for
anything.  They don't show up in the debug info, don't have a real body,
nothing calls them...

Thus I think I'd prefer something like following patch
(so far untested, will test later today), or returning early from
mangle_decl for DECL_OMP_DECLARE_REDUCTION_P:

2016-02-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/59627
	* parser.c (cp_parser_omp_declare_reduction): Set assembler name
	of the DECL_OMP_DECLARE_REDUCTION_P decls.

	* g++.dg/gomp/pr59627.C: New test.


	Jakub
diff mbox

Patch

--- gcc/cp/parser.c.jj	2016-01-29 21:32:54.000000000 +0100
+++ gcc/cp/parser.c	2016-02-08 11:45:34.229860265 +0100
@@ -36080,6 +36080,7 @@  cp_parser_omp_declare_reduction (cp_pars
       DECL_DECLARED_INLINE_P (fndecl) = 1;
       DECL_IGNORED_P (fndecl) = 1;
       DECL_OMP_DECLARE_REDUCTION_P (fndecl) = 1;
+      SET_DECL_ASSEMBLER_NAME (fndecl, get_identifier ("<udr>"));
       DECL_ATTRIBUTES (fndecl)
 	= tree_cons (get_identifier ("gnu_inline"), NULL_TREE,
 		     DECL_ATTRIBUTES (fndecl));
--- gcc/testsuite/g++.dg/gomp/pr59627.C.jj	2016-02-08 11:59:26.650053692 +0100
+++ gcc/testsuite/g++.dg/gomp/pr59627.C	2016-02-08 11:55:52.000000000 +0100
@@ -0,0 +1,14 @@ 
+// PR c++/59627
+// { dg-do compile { target lto } }
+// { dg-options "-fopenmp -flto" }
+
+struct A { A () : i (0) {} int i; };
+
+void
+foo ()
+{
+  A a;
+  #pragma omp declare reduction (+: A: omp_out.i += omp_in.i)
+  #pragma omp parallel reduction (+: a)
+  ;
+}