See attached patch, 6/10 of v2 of the DO CONCURRENT to OpenMP series.

Changes since v1: warnings for the reasons that v2 adds in 1/10 to
4/10, and the warning for a call says that the procedure "is not a
declare target procedure".

Start with enum dc_why, struct dc_reason and dc_note in trans-openmp.cc:
dc_note keeps the first reason found, with the variable and locus.
dc_warn turns a reason into the warning, and gfc_dc_omp_lowering calls
it where a construct stays serial or, with =device, runs on the host.

The other hunks only add a dc_note call at the existing fallback points
in dc_scan_def, dc_scan_call, dc_scan_code, dc_scan_expr, dc_scan_body
and dc_device_ok, and pass the locus of a call to dc_scan_call.  No
lowering decision changes.

Regards,

Jerry

---

fortran: [PR128590]-6 Add -Wdo-concurrent-to-openmp

Add a warning, off by default, that says why -fdo-concurrent-to-openmp
translates a DO CONCURRENT construct serially or, with device, runs it
on the host, pointing at the statement or variable responsible and, for
variables, suggesting a LOCAL or REDUCE locality spec.

Assisted-by: Claude Opus 5.5

        PR fortran/128590

gcc/fortran/ChangeLog:

        * invoke.texi: Document -Wdo-concurrent-to-openmp.
        * lang.opt (Wdo-concurrent-to-openmp): New option.
        * trans-openmp.cc (enum dc_why, struct dc_reason, dc_note)
        (dc_warn): New.
        (struct dc_scan): Add host_why and device_why.
        (dc_scan_def, dc_scan_call, dc_scan_code, dc_scan_expr)
        (dc_scan_body, dc_device_ok): Record the reasons.
        (dc_scan_call_args): Pass the locus of the call.
        (gfc_dc_omp_lowering): Warn why a construct is not lowered or not
        offloaded.

gcc/testsuite/ChangeLog:

        * gfortran.dg/gomp/do_concurrent_to_openmp_9.f90: New test.
        * gfortran.dg/gomp/do_concurrent_to_openmp_17.f90: New test.
>From 8c293bc21fb92179586f074c09e9b3da51a249d4 Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Wed, 25 Nov 2026 15:57:40 -0800
Subject: [PATCH v2 6/10] fortran: [PR128590]-6 Add -Wdo-concurrent-to-openmp

Add a warning, off by default, that says why -fdo-concurrent-to-openmp
translates a DO CONCURRENT construct serially or, with device, runs it
on the host, pointing at the statement or variable responsible and, for
variables, suggesting a LOCAL or REDUCE locality spec.

Assisted-by: Claude Opus 5.5

	PR fortran/128590

gcc/fortran/ChangeLog:

	* invoke.texi: Document -Wdo-concurrent-to-openmp.
	* lang.opt (Wdo-concurrent-to-openmp): New option.
	* trans-openmp.cc (enum dc_why, struct dc_reason, dc_note)
	(dc_warn): New.
	(struct dc_scan): Add host_why and device_why.
	(dc_scan_def, dc_scan_call, dc_scan_code, dc_scan_expr)
	(dc_scan_body, dc_device_ok): Record the reasons.
	(dc_scan_call_args): Pass the locus of the call.
	(gfc_dc_omp_lowering): Warn why a construct is not lowered or not
	offloaded.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/do_concurrent_to_openmp_9.f90: New test.
	* gfortran.dg/gomp/do_concurrent_to_openmp_17.f90: New test.
---
 gcc/fortran/invoke.texi                       |  12 +-
 gcc/fortran/lang.opt                          |   4 +
 gcc/fortran/trans-openmp.cc                   | 269 ++++++++++++++++--
 .../gomp/do_concurrent_to_openmp_17.f90       |  45 +++
 .../gomp/do_concurrent_to_openmp_9.f90        |  83 ++++++
 5 files changed, 380 insertions(+), 33 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_17.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_9.f90

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index a61167eaeb7..81fde058c57 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -150,8 +150,8 @@ by type.  Explanations are in the following sections.
 and warnings}.
 @gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
 -Wc-binding-type -Wcharacter-truncation -Wconversion
--Wno-deprecated-openmp -Wdo-subscript -Wformat-width
--Wfunction-elimination
+-Wno-deprecated-openmp -Wdo-concurrent-to-openmp -Wdo-subscript
+-Wformat-width -Wfunction-elimination
 -Wimplicit-interface -Wimplicit-procedure -Wintrinsic-shadow
 -Wuse-without-only -Wintrinsics-std -Wline-truncation -Wno-align-commons
 -Wno-overwrite-recursive -Wno-tabs -Wreal-q-constant -Wsurprising
@@ -1359,6 +1359,14 @@ target. This option is implied by @option{-Wall}.
 Warn if a @code{DO} loop is known to execute zero times at compile
 time.  This option is implied by @option{-Wall}.
 
+@opindex Wdo-concurrent-to-openmp
+@item -Wdo-concurrent-to-openmp
+Warn when @option{-fdo-concurrent-to-openmp} translates a @code{DO
+CONCURRENT} construct serially, or, with @samp{device}, runs it on the
+host, and say why.  No warning is given for a construct nested in an
+OpenMP or OpenACC construct or in another @code{DO CONCURRENT}
+construct.
+
 @opindex Wdo-subscript
 @item -Wdo-subscript
 Warn if an array subscript inside a @code{DO} loop could lead to an
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 2d7ae70b971..93505a07777 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -241,6 +241,10 @@ Wdeprecated-openmp
 Fortran Var(warn_deprecated_openmp) Warning Init(1)
 ; Documented in C
 
+Wdo-concurrent-to-openmp
+Fortran Warning Var(warn_do_concurrent_to_openmp)
+Warn if -fdo-concurrent-to-openmp leaves a DO CONCURRENT construct serial or on the host.
+
 Wdo-subscript
 Fortran Var(warn_do_subscript) Warning LangEnabledBy(Fortran,Wextra)
 Warn about possibly incorrect subscripts in do loops.
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index abfdbb22774..ceab04260a0 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -11018,6 +11018,48 @@ struct dc_use
 };
 
 
+/* Why a DO CONCURRENT construct keeps the serial lowering, or is not
+   offloaded, for -Wdo-concurrent-to-openmp.  */
+
+enum dc_why
+{
+  DC_WHY_NONE,
+  DC_WHY_IO,
+  DC_WHY_DIRECTIVE,
+  DC_WHY_STATIC_LOCAL,
+  DC_WHY_LABEL_ASSIGN,
+  DC_WHY_UNTRACKED_DEF,
+  DC_WHY_DYNAMIC_CALL,
+  DC_WHY_SHARED_PART,
+  DC_WHY_REF_BEFORE_DEF,
+  DC_WHY_NOT_PRIVATIZABLE,
+  DC_WHY_DEVICE_PROC,
+  DC_WHY_DEVICE_CALL,
+  DC_WHY_DEVICE_VAR,
+  DC_WHY_DEVICE_CONDITIONAL
+};
+
+struct dc_reason
+{
+  enum dc_why why;
+  gfc_symbol *sym;
+  locus where;
+};
+
+
+/* Record WHY, about SYM at WHERE, in R unless R holds a reason already.  */
+
+static void
+dc_note (dc_reason *r, enum dc_why why, gfc_symbol *sym, locus *where)
+{
+  if (r->why != DC_WHY_NONE)
+    return;
+  r->why = why;
+  r->sym = sym;
+  r->where = *where;
+}
+
+
 /* State of the walk over the body of a DO CONCURRENT construct.  */
 
 struct dc_scan
@@ -11063,6 +11105,9 @@ struct dc_scan
   auto_vec<gfc_symbol *> part_defs;
   /* The body references a variable that offloading does not support.  */
   bool device_bad;
+  /* The first reason found to keep the construct serial, and to keep it
+     on the host.  */
+  dc_reason host_why, device_why;
   /* The body references a procedure other than an intrinsic one, one
      that can see the variables of the procedure containing DC, and one
      other than an intrinsic or declare target procedure.  */
@@ -11249,7 +11294,10 @@ dc_scan_def (dc_scan *scan, gfc_expr *e, enum dc_def_kind kind)
   if (sym->attr.flavor == FL_PROCEDURE && !dc_result_var (sym))
     {
       if (sym->attr.proc_pointer)
-	scan->ok = false;
+	{
+	  scan->ok = false;
+	  dc_note (&scan->host_why, DC_WHY_UNTRACKED_DEF, sym, &e->where);
+	}
       return;
     }
 
@@ -11281,7 +11329,10 @@ dc_scan_def (dc_scan *scan, gfc_expr *e, enum dc_def_kind kind)
       /* A part that depends on an index-name is defined by its own
 	 iteration; any other part may be shared between iterations.  */
       if (!dc_indexed_designator (scan, e, spec))
-	scan->unindexed_def = true;
+	{
+	  scan->unindexed_def = true;
+	  dc_note (&scan->host_why, DC_WHY_SHARED_PART, sym, &e->where);
+	}
       else if (e->rank == 0 && !sym->attr.dimension
 	       && !scan->part_def_seen.add (sym))
 	scan->part_defs.safe_push (sym);
@@ -11291,6 +11342,7 @@ dc_scan_def (dc_scan *scan, gfc_expr *e, enum dc_def_kind kind)
   if (kind == DC_DEF_UNTRACKED)
     {
       scan->ok = false;
+      dc_note (&scan->host_why, DC_WHY_UNTRACKED_DEF, sym, &e->where);
       return;
     }
 
@@ -11321,22 +11373,29 @@ dc_scan_index_def (dc_scan *scan, gfc_expr *e, gfc_expr *value)
 }
 
 
-/* Record a reference to procedure SYM.  */
+/* Record a reference at WHERE to procedure SYM, or to an unknown one if
+   SYM is NULL.  */
 
 static void
-dc_scan_call (dc_scan *scan, gfc_symbol *sym)
+dc_scan_call (dc_scan *scan, gfc_symbol *sym, locus *where)
 {
   if (sym == NULL
       || sym->attr.proc == PROC_INTERNAL
       || sym->attr.proc == PROC_ST_FUNCTION
       || sym->attr.dummy
       || sym->attr.proc_pointer)
-    scan->internal_calls = true;
+    {
+      scan->internal_calls = true;
+      dc_note (&scan->device_why, DC_WHY_DEVICE_CALL, sym, where);
+    }
   else if (!sym->attr.intrinsic)
     {
       scan->calls = true;
       if (!sym->attr.omp_declare_target)
-	scan->host_calls = true;
+	{
+	  scan->host_calls = true;
+	  dc_note (&scan->device_why, DC_WHY_DEVICE_CALL, sym, where);
+	}
     }
 }
 
@@ -11364,7 +11423,7 @@ dc_scan_call_args (dc_scan *scan, gfc_code *code)
 
   gfc_symbol *proc = code->resolved_sym ? code->resolved_sym
 					: code->symtree->n.sym;
-  dc_scan_call (scan, proc);
+  dc_scan_call (scan, proc, &code->loc);
 
   gfc_formal_arglist *f = gfc_sym_get_dummy_args (proc);
   for (; a; a = a->next, f = f ? f->next : NULL)
@@ -11391,9 +11450,16 @@ dc_scan_code (gfc_code **cp, int *, void *data)
 
   /* Parallel execution would reorder I/O, and an OpenMP or OpenACC
      directive in the body could not nest in the synthesized construct.  */
-  if ((c->op >= EXEC_OPEN && c->op <= EXEC_FLUSH)
-      || c->op >= EXEC_OACC_KERNELS_LOOP)
-    scan->ok = false;
+  if (c->op >= EXEC_OPEN && c->op <= EXEC_FLUSH)
+    {
+      scan->ok = false;
+      dc_note (&scan->host_why, DC_WHY_IO, NULL, &c->loc);
+    }
+  else if (c->op >= EXEC_OACC_KERNELS_LOOP)
+    {
+      scan->ok = false;
+      dc_note (&scan->host_why, DC_WHY_DIRECTIVE, NULL, &c->loc);
+    }
 
   switch (c->op)
     {
@@ -11401,7 +11467,10 @@ dc_scan_code (gfc_code **cp, int *, void *data)
       scan->inner.add (c->ext.block.ns);
       /* All iterations would share a static variable of the block.  */
       if (dc_static_local (c->ext.block.ns, c->ext.block.ns->sym_root))
-	scan->ok = false;
+	{
+	  scan->ok = false;
+	  dc_note (&scan->host_why, DC_WHY_STATIC_LOCAL, NULL, &c->loc);
+	}
       for (gfc_association_list *a = c->ext.block.assoc; a; a = a->next)
 	dc_scan_def (scan, a->target, DC_DEF_UNTRACKED);
       break;
@@ -11443,8 +11512,13 @@ dc_scan_code (gfc_code **cp, int *, void *data)
 
     case EXEC_COMPCALL:
     case EXEC_CALL_PPC:
+      scan->ok = false;
+      dc_note (&scan->host_why, DC_WHY_DYNAMIC_CALL, NULL, &c->loc);
+      break;
+
     case EXEC_LABEL_ASSIGN:
       scan->ok = false;
+      dc_note (&scan->host_why, DC_WHY_LABEL_ASSIGN, NULL, &c->loc);
       break;
 
     case EXEC_CYCLE:
@@ -11513,12 +11587,13 @@ dc_scan_expr (gfc_expr **ep, int *, void *data)
     case EXPR_FUNCTION:
       if (!e->value.function.isym)
 	dc_scan_call (scan, e->value.function.esym
-			    ? e->value.function.esym : e->symtree->n.sym);
+			    ? e->value.function.esym : e->symtree->n.sym,
+		      &e->where);
       break;
 
     case EXPR_COMPCALL:
     case EXPR_PPC:
-      scan->internal_calls = true;
+      dc_scan_call (scan, NULL, &e->where);
       break;
 
     case EXPR_VARIABLE:
@@ -11527,12 +11602,15 @@ dc_scan_expr (gfc_expr **ep, int *, void *data)
 	/* A procedure actual argument may be called.  */
 	if (sym->attr.flavor == FL_PROCEDURE && !dc_result_var (sym))
 	  {
-	    dc_scan_call (scan, sym);
+	    dc_scan_call (scan, sym, &e->where);
 	    break;
 	  }
 	bool var = sym->attr.flavor == FL_VARIABLE || dc_result_var (sym);
 	if (var && !dc_device_var_ok (sym))
-	  scan->device_bad = true;
+	  {
+	    scan->device_bad = true;
+	    dc_note (&scan->device_why, DC_WHY_DEVICE_VAR, sym, &e->where);
+	  }
 	if (var && !scan->defs.contains (e) && !dc_locality_known (scan, sym))
 	  {
 	    dc_use &use = dc_use_of (scan, sym);
@@ -11709,6 +11787,7 @@ dc_scan_body (gfc_code *code, dc_scan *scan)
       scan->exits = 0;
       scan->host_calls = false;
       scan->unindexed_def = scan->device_bad = false;
+      scan->host_why.why = scan->device_why.why = DC_WHY_NONE;
       scan->part_def_seen.empty ();
       scan->part_defs.truncate (0);
       scan->ok = true;
@@ -11736,9 +11815,16 @@ dc_scan_body (gfc_code *code, dc_scan *scan)
   for (gfc_symbol *sym : scan->order)
     {
       dc_use *use = scan->uses.get (sym);
-      if (use->defined
-	  && (use->ref_first || !dc_privatizable (scan, sym)))
-	return false;
+      if (use->defined && use->ref_first)
+	{
+	  dc_note (&scan->host_why, DC_WHY_REF_BEFORE_DEF, sym, &code->loc);
+	  return false;
+	}
+      if (use->defined && !dc_privatizable (scan, sym))
+	{
+	  dc_note (&scan->host_why, DC_WHY_NOT_PRIVATIZABLE, sym, &code->loc);
+	  return false;
+	}
     }
 
   return true;
@@ -11764,7 +11850,12 @@ dc_device_ok (dc_scan *scan)
   if (proc
       && (proc->attr.pure || proc->attr.implicit_pure
 	  || proc->attr.elemental || proc->attr.omp_declare_target))
-    return false;
+    {
+      scan->device_why.why = DC_WHY_NONE;
+      dc_note (&scan->device_why, DC_WHY_DEVICE_PROC, proc,
+	       &scan->dc->loc);
+      return false;
+    }
 
   if (scan->device_bad || scan->host_calls || scan->internal_calls)
     return false;
@@ -11774,13 +11865,21 @@ dc_device_ok (dc_scan *scan)
 	 el; el = el->next)
       if (el->expr->expr_type == EXPR_VARIABLE
 	  && !dc_device_var_ok (el->expr->symtree->n.sym))
-	return false;
+	{
+	  dc_note (&scan->device_why, DC_WHY_DEVICE_VAR,
+		   el->expr->symtree->n.sym, &el->expr->where);
+	  return false;
+	}
 
   for (gfc_symbol *sym : scan->order)
     {
       dc_use *use = scan->uses.get (sym);
       if (use->defined && !use->udef)
-	return false;
+	{
+	  dc_note (&scan->device_why, DC_WHY_DEVICE_CONDITIONAL, sym,
+		   &scan->dc->loc);
+	  return false;
+	}
     }
 
   return true;
@@ -11788,6 +11887,85 @@ dc_device_ok (dc_scan *scan)
 
 
 
+/* Warn why a DO CONCURRENT construct is not lowered to OpenMP, or, if
+   DEVICE, not offloaded, for reason R.  */
+
+static void
+dc_warn (dc_reason *r, bool device)
+{
+  const char *name = r->sym ? r->sym->name : NULL;
+  int opt = OPT_Wdo_concurrent_to_openmp;
+
+  switch (r->why)
+    {
+    case DC_WHY_IO:
+      gfc_warning (opt, "Input/output statement at %L keeps DO CONCURRENT "
+		   "serial", &r->where);
+      break;
+    case DC_WHY_DIRECTIVE:
+      gfc_warning (opt, "OpenMP or OpenACC directive at %L keeps DO "
+		   "CONCURRENT serial", &r->where);
+      break;
+    case DC_WHY_STATIC_LOCAL:
+      gfc_warning (opt, "Variable with static storage in the BLOCK construct "
+		   "at %L keeps DO CONCURRENT serial", &r->where);
+      break;
+    case DC_WHY_LABEL_ASSIGN:
+      gfc_warning (opt, "ASSIGN statement at %L keeps DO CONCURRENT serial",
+		   &r->where);
+      break;
+    case DC_WHY_UNTRACKED_DEF:
+      gfc_warning (opt, "Allocation, pointer assignment or association of "
+		   "%qs at %L keeps DO CONCURRENT serial", name, &r->where);
+      break;
+    case DC_WHY_DYNAMIC_CALL:
+      gfc_warning (opt, "Call through a procedure pointer or binding at %L "
+		   "keeps DO CONCURRENT serial", &r->where);
+      break;
+    case DC_WHY_SHARED_PART:
+      gfc_warning (opt, "Definition of %qs at %L, not indexed by an "
+		   "index-name, keeps DO CONCURRENT serial; consider a LOCAL "
+		   "locality spec", name, &r->where);
+      break;
+    case DC_WHY_REF_BEFORE_DEF:
+      gfc_warning (opt, "DO CONCURRENT at %L references %qs before every "
+		   "iteration defines it, so it stays serial; consider a "
+		   "REDUCE or LOCAL locality spec", &r->where, name);
+      break;
+    case DC_WHY_NOT_PRIVATIZABLE:
+      gfc_warning (opt, "DO CONCURRENT at %L defines %qs, which cannot be "
+		   "given a private copy, so it stays serial; consider a "
+		   "LOCAL locality spec", &r->where, name);
+      break;
+    case DC_WHY_DEVICE_PROC:
+      gfc_warning (opt, "DO CONCURRENT at %L runs on the host because "
+		   "procedure %qs may itself run on the device", &r->where,
+		   name);
+      break;
+    case DC_WHY_DEVICE_CALL:
+      if (name)
+	gfc_warning (opt, "Reference to %qs at %L keeps DO CONCURRENT on "
+		     "the host; it is not a declare target procedure",
+		     name, &r->where);
+      else
+	gfc_warning (opt, "Call through a procedure pointer or binding at %L "
+		     "keeps DO CONCURRENT on the host", &r->where);
+      break;
+    case DC_WHY_DEVICE_VAR:
+      gfc_warning (opt, "Variable %qs at %L cannot be mapped implicitly, so "
+		   "DO CONCURRENT runs on the host", name, &r->where);
+      break;
+    case DC_WHY_DEVICE_CONDITIONAL:
+      gfc_warning (opt, "DO CONCURRENT at %L runs on the host because only "
+		   "some iterations may define %qs", &r->where, name);
+      break;
+    case DC_WHY_NONE:
+      gcc_assert (!device);
+      break;
+    }
+}
+
+
 /* State of the search for a branch into a DO CONCURRENT construct.  */
 
 struct dc_entry
@@ -11933,27 +12111,56 @@ gfc_dc_omp_lowering (gfc_code *code)
 
   if (flag_do_concurrent_to_openmp == GFC_DC_OMP_NONE
       || gfc_omp_construct_depth > 0
-      || code->ext.concur.forall_iterator == NULL
-      || code->expr1
-      || !dc_locality_ok (code))
+      || code->ext.concur.forall_iterator == NULL)
     return GFC_DC_OMP_NONE;
 
+  if (code->expr1)
+    {
+      gfc_warning (OPT_Wdo_concurrent_to_openmp, "DO CONCURRENT at %L with "
+		   "a mask stays serial", &code->loc);
+      return GFC_DC_OMP_NONE;
+    }
+
+  if (!dc_locality_ok (code))
+    {
+      gfc_warning (OPT_Wdo_concurrent_to_openmp, "DO CONCURRENT at %L stays "
+		   "serial because a variable of its SHARED or REDUCE "
+		   "locality spec cannot appear in an OpenMP clause",
+		   &code->loc);
+      return GFC_DC_OMP_NONE;
+    }
+
   /* The OpenMP loop would not honor these directives.  */
   for (gfc_forall_iterator *fa = code->ext.concur.forall_iterator;
        fa; fa = fa->next)
     if (fa->annot.unroll || fa->annot.novector)
-      return GFC_DC_OMP_NONE;
+      {
+	gfc_warning (OPT_Wdo_concurrent_to_openmp, "DO CONCURRENT at %L "
+		     "with !GCC$ UNROLL or NOVECTOR stays serial", &code->loc);
+	return GFC_DC_OMP_NONE;
+      }
 
   dc_scan scan;
   if (!dc_scan_body (code, &scan))
-    return GFC_DC_OMP_NONE;
+    {
+      dc_warn (&scan.host_why, false);
+      return GFC_DC_OMP_NONE;
+    }
 
-  if (dc_branch_into (code))
-    return GFC_DC_OMP_NONE;
+  if (gfc_code *branch = dc_branch_into (code))
+    {
+      gfc_warning (OPT_Wdo_concurrent_to_openmp, "DO CONCURRENT at %L "
+		   "stays serial because the statement at %L branches into "
+		   "it", &code->loc, &branch->loc);
+      return GFC_DC_OMP_NONE;
+    }
 
-  if (flag_do_concurrent_to_openmp == GFC_DC_OMP_DEVICE
-      && dc_device_ok (&scan))
-    return GFC_DC_OMP_DEVICE;
+  if (flag_do_concurrent_to_openmp == GFC_DC_OMP_DEVICE)
+    {
+      if (dc_device_ok (&scan))
+	return GFC_DC_OMP_DEVICE;
+      dc_warn (&scan.device_why, true);
+    }
 
   return GFC_DC_OMP_HOST;
 }
diff --git a/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_17.f90 b/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_17.f90
new file mode 100644
index 00000000000..157b353c9cd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_17.f90
@@ -0,0 +1,45 @@
+! { dg-do compile }
+! { dg-additional-options "-fdo-concurrent-to-openmp=host -Wdo-concurrent-to-openmp" }
+!
+! PR 128590
+
+subroutine static_local (b, n)
+  integer :: n, i
+  integer :: b(n)
+  do concurrent (i = 1:n)
+    block ! { dg-warning "Variable with static storage in the BLOCK construct at .1. keeps DO CONCURRENT serial" }
+      integer :: t
+      data t /3/
+      b(i) = t
+    end block
+  end do
+end subroutine static_local
+
+subroutine label_assign (b, n)
+  integer :: n, i, k
+  integer :: b(n)
+  do concurrent (i = 1:n)
+    assign 10 to k ! { dg-warning "ASSIGN statement at .1. keeps DO CONCURRENT serial" }
+    ! { dg-warning "Deleted feature: ASSIGN" "" { target *-*-* } .-1 }
+    goto k (10) ! { dg-warning "Deleted feature: Assigned GOTO" }
+10  b(i) = 1
+  end do
+end subroutine label_assign
+
+subroutine reduce_char (w, c)
+  character(len=3) :: w(5), c
+  integer :: i
+  do concurrent (i = 1:5) reduce(max:c) ! { dg-warning "SHARED or REDUCE locality spec cannot appear in an OpenMP clause" }
+    c = max (c, w(i))
+  end do
+end subroutine reduce_char
+
+subroutine common_member (a, b, n)
+  integer :: n, i, t
+  integer :: a(n), b(n)
+  common /c/ t
+  do concurrent (i = 1:n) ! { dg-warning "defines 't', which cannot be given a private copy" }
+    t = a(i)
+    b(i) = t
+  end do
+end subroutine common_member
diff --git a/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_9.f90 b/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_9.f90
new file mode 100644
index 00000000000..e74cfae08fa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/do_concurrent_to_openmp_9.f90
@@ -0,0 +1,83 @@
+! { dg-do compile }
+! { dg-additional-options "-fdo-concurrent-to-openmp=device -Wdo-concurrent-to-openmp" }
+! PR 128590
+!
+! -Wdo-concurrent-to-openmp says why a DO CONCURRENT construct stays
+! serial or runs on the host.
+
+module m
+  implicit none
+contains
+  pure real function f (x)
+    real, intent(in) :: x
+    f = x + 1.0
+  end function f
+
+  pure subroutine in_pure (a, n)
+    integer, intent(in) :: n
+    real, intent(inout) :: a(n)
+    integer :: i
+    do concurrent (i = 1:n) ! { dg-warning "runs on the host because procedure 'in_pure' may itself run on the device" }
+       a(i) = a(i) * 2.0
+    end do
+  end subroutine in_pure
+end module m
+
+subroutine reasons (a, b, n, s, idx, p)
+  use m
+  integer :: n, i, idx
+  real :: a(n), b(n), s, tmp(3)
+  real, pointer :: p(:)
+  real, allocatable :: w(:)
+
+  do concurrent (i = 1:n, a(i) > 0.0) ! { dg-warning "with a mask stays serial" }
+     b(i) = a(i)
+  end do
+
+  do concurrent (i = 1:n)
+     print *, a(i) ! { dg-warning "Input/output statement at .1. keeps DO CONCURRENT serial" }
+  end do
+
+  do concurrent (i = 1:n)
+     tmp(1) = a(i) ! { dg-warning "Definition of 'tmp' at .1., not indexed by an index-name, keeps DO CONCURRENT serial" }
+     b(i) = tmp(1)
+  end do
+
+  do concurrent (i = 1:n) ! { dg-warning "references 's' before every iteration defines it" }
+     s = s + a(i)
+  end do
+
+  do concurrent (i = 1:n)
+     allocate (w(2)) ! { dg-warning "Allocation, pointer assignment or association of .w. at .1. keeps DO CONCURRENT serial" }
+     b(i) = 1.0
+     deallocate (w)
+  end do
+
+  do concurrent (i = 1:n)
+     b(i) = f (a(i)) ! { dg-warning "Reference to 'f' at .1. keeps DO CONCURRENT on the host" }
+  end do
+
+  do concurrent (i = 1:n) ! { dg-warning "runs on the host because only some iterations may define 'idx'" }
+     if (a(i) == 3.0) idx = i
+  end do
+
+  do concurrent (i = 1:n)
+     p(i) = 0.0 ! { dg-warning "Variable 'p' at .1. cannot be mapped implicitly" }
+  end do
+
+  ! Lowered; no warning.
+  do concurrent (i = 1:n)
+     b(i) = a(i)
+  end do
+end subroutine reasons
+
+subroutine branch_into (a, n)
+  integer :: n, i
+  real :: a(n)
+  if (n > 2) goto 10 ! { dg-warning "Label at .1. is not in the same block" }
+! { dg-warning "branches into it" "" { target *-*-* } .-1 }
+  do concurrent (i = 1:n) ! { dg-warning "stays serial because the statement at .2. branches into it" }
+     a(i) = 2.0
+10 end do ! { dg-warning "Label at .1. is not in the same block" }
+! { dg-warning "ignoring loop annotation" "" { target *-*-* } .-1 }
+end subroutine branch_into
-- 
2.56.1

Reply via email to