public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7257] openmp: For min/max omp atomic compare forms verify arg types with build_binary_op [PR104531]
@ 2022-02-16  8:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-02-16  8:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:023327643969d5469902a9ecfa6738a315f9e362

commit r12-7257-g023327643969d5469902a9ecfa6738a315f9e362
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 16 09:27:11 2022 +0100

    openmp: For min/max omp atomic compare forms verify arg types with build_binary_op [PR104531]
    
    The MIN_EXPR/MAX_EXPR handling in *build_binary_op is minimal (especially
    for C FE), because min/max aren't expressions the languages contain directly.
    I'm using those for the
      #pragma omp atomic
      x = x < y ? y : x;
    forms, but e.g. for the attached testcase we normally reject _Complex int vs. int
    comparisons, in C++ due to MIN/MAX_EXPR we were diagnosing it as invalid types
    for <unknown> while in C we accept it and ICEd later on.
    
    The following patch will try build_binary_op with LT_EXPR on the operands first
    to get needed diagnostics and fail if it returns error_mark_node.
    
    2022-02-16  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/104531
            * c-omp.cc (c_finish_omp_atomic): For MIN_EXPR/MAX_EXPR, try first
            build_binary_op with LT_EXPR and only if that doesn't return
            error_mark_node call build_modify_expr.
    
            * c-c++-common/gomp/atomic-31.c: New test.

Diff:
---
 gcc/c-family/c-omp.cc                       |  9 +++++++--
 gcc/testsuite/c-c++-common/gomp/atomic-31.c | 11 +++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index f5314d66f27..cd9d86641e1 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -353,8 +353,13 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
     }
   bool save = in_late_binary_op;
   in_late_binary_op = true;
-  x = build_modify_expr (loc, blhs ? blhs : lhs, NULL_TREE, opcode,
-			 loc, rhs, NULL_TREE);
+  if ((opcode == MIN_EXPR || opcode == MAX_EXPR)
+      && build_binary_op (loc, LT_EXPR, blhs ? blhs : lhs, rhs,
+			  true) == error_mark_node)
+    x = error_mark_node;
+  else
+    x = build_modify_expr (loc, blhs ? blhs : lhs, NULL_TREE, opcode,
+			   loc, rhs, NULL_TREE);
   in_late_binary_op = save;
   if (x == error_mark_node)
     return error_mark_node;
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-31.c b/gcc/testsuite/c-c++-common/gomp/atomic-31.c
new file mode 100644
index 00000000000..9ec3140e2f0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/atomic-31.c
@@ -0,0 +1,11 @@
+/* c/104531 */
+/* { dg-do compile } */
+
+int x;
+
+void
+foo (_Complex int y)
+{
+  #pragma omp atomic compare	/* { dg-error "invalid operands" } */
+  x = x > y ? y : x;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-16  8:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16  8:32 [gcc r12-7257] openmp: For min/max omp atomic compare forms verify arg types with build_binary_op [PR104531] Jakub Jelinek

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).