public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7011] openmp, fortran: Improve !$omp atomic checks [PR104328]
Date: Thu,  3 Feb 2022 08:05:11 +0000 (GMT)	[thread overview]
Message-ID: <20220203080511.677D03858D37@sourceware.org> (raw)

https://gcc.gnu.org/g:54d21dd5b5c5c5539505b3e037cdecb3b0ab3918

commit r12-7011-g54d21dd5b5c5c5539505b3e037cdecb3b0ab3918
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Feb 3 09:01:07 2022 +0100

    openmp, fortran: Improve !$omp atomic checks [PR104328]
    
    The testcase shows some cases that weren't verified and we ICE on
    invalid because of that.
    One problem is that unlike before, we weren't checking if some expression
    is EXPR_VARIABLE with non-NULL symtree in the case where there was
    a conversion around it.
    The other two issues is that we check that in an IF ->block is non-NULL
    and then immediately dereference ->block->next->op, but on invalid
    code with no statements in the then clause ->block->next might be NULL.
    
    2022-02-02  Jakub Jelinek  <jakub@redhat.com>
    
            PR fortran/104328
            * openmp.cc (is_scalar_intrinsic_expr): If must_be_var && conv_ok
            and expr is conversion, verify it is a conversion from EXPR_VARIABLE
            with non-NULL symtree.  Check ->block->next before dereferencing it.
    
            * gfortran.dg/gomp/atomic-27.f90: New test.

Diff:
---
 gcc/fortran/openmp.cc                        | 15 +++++++++---
 gcc/testsuite/gfortran.dg/gomp/atomic-27.f90 | 34 ++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 073e5a16da5..38c67e1f640 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7660,9 +7660,16 @@ static bool
 is_scalar_intrinsic_expr (gfc_expr *expr, bool must_be_var, bool conv_ok)
 {
   if (must_be_var
-      && (expr->expr_type != EXPR_VARIABLE || !expr->symtree)
-      && (!conv_ok || !is_conversion (expr, true, true)))
-    return false;
+      && (expr->expr_type != EXPR_VARIABLE || !expr->symtree))
+    {
+      if (!conv_ok)
+	return false;
+      gfc_expr *conv = is_conversion (expr, true, true);
+      if (!conv)
+	return false;
+      if (conv->expr_type != EXPR_VARIABLE || !conv->symtree)
+	return false;
+    }
   return (expr->rank == 0
 	  && !gfc_is_coindexed (expr)
 	  && (expr->ts.type == BT_INTEGER
@@ -7705,6 +7712,7 @@ resolve_omp_atomic (gfc_code *code)
       if (next->op == EXEC_IF
 	  && next->block
 	  && next->block->op == EXEC_IF
+	  && next->block->next
 	  && next->block->next->op == EXEC_ASSIGN)
 	{
 	  comp_cond = next->block->expr1;
@@ -7757,6 +7765,7 @@ resolve_omp_atomic (gfc_code *code)
       if (code->op == EXEC_IF
 	  && code->block
 	  && code->block->op == EXEC_IF
+	  && code->block->next
 	  && code->block->next->op == EXEC_ASSIGN)
 	{
 	  comp_cond = code->block->expr1;
diff --git a/gcc/testsuite/gfortran.dg/gomp/atomic-27.f90 b/gcc/testsuite/gfortran.dg/gomp/atomic-27.f90
new file mode 100644
index 00000000000..5f7311a9d7d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/atomic-27.f90
@@ -0,0 +1,34 @@
+! PR fortran/104328
+! { dg-do compile }
+
+subroutine foo
+  integer :: k = 1
+  !$omp atomic compare
+  if ( k == 2 ) then	! { dg-error "unexpected !.OMP ATOMIC expression" }
+  end if
+end
+subroutine bar
+  real :: x = 1
+  !$omp atomic compare
+  if ( x == 2 ) then	! { dg-error "unexpected !.OMP ATOMIC expression" }
+  end if
+end
+subroutine baz
+  integer :: i
+  !$omp atomic capture
+  i = 1
+  i = i + 1.		! { dg-error "!.OMP ATOMIC capture-statement requires a scalar variable of intrinsic type" }
+end
+subroutine qux
+  integer :: i = 0
+  !$omp atomic capture
+  i = i + 1.0
+  i = i + 1.0		! { dg-error "!.OMP ATOMIC capture-statement requires a scalar variable of intrinsic type" }
+end
+subroutine garply
+  logical :: k = .true.
+  !$omp atomic capture compare
+  if ( k ) then		! { dg-error "unexpected !.OMP ATOMIC expression" }
+  else
+  end if
+end


                 reply	other threads:[~2022-02-03  8:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220203080511.677D03858D37@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).