Hi!

In this spot the code wants to verify the first operand of a COMPOUND_EXPR
is the result of save_expr.  As the testcase shows, that doesn't have
necessarily to be a SAVE_EXPR, but could be say a binary expression
involving two SAVE_EXPRs, or SAVE_EXPR and a constant etc. (constant alone
is unlikely, as the save_expr is called and COMPOUND_EXPR created if the
expression has side effects).

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk,
queued for backporting.

2019-06-25  Jakub Jelinek  <ja...@redhat.com>

        PR sanitizer/90954
        * c-omp.c (c_finish_omp_atomic): Allow tree_invariant_p in addition
        to SAVE_EXPR in first operand of a COMPOUND_EXPR.

        * c-c++-common/gomp/pr90954.c: New test.

--- gcc/c-family/c-omp.c.jj     2019-06-10 14:18:17.000000000 +0200
+++ gcc/c-family/c-omp.c        2019-06-24 12:44:56.311022694 +0200
@@ -305,7 +305,7 @@ c_finish_omp_atomic (location_t loc, enu
   if (TREE_CODE (x) == COMPOUND_EXPR)
     {
       pre = TREE_OPERAND (x, 0);
-      gcc_assert (TREE_CODE (pre) == SAVE_EXPR);
+      gcc_assert (TREE_CODE (pre) == SAVE_EXPR || tree_invariant_p (pre));
       x = TREE_OPERAND (x, 1);
     }
   gcc_assert (TREE_CODE (x) == MODIFY_EXPR);
--- gcc/testsuite/c-c++-common/gomp/pr90954.c.jj        2019-06-24 
13:15:17.201306780 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr90954.c   2019-06-25 08:34:40.353282739 
+0200
@@ -0,0 +1,27 @@
+/* PR sanitizer/90954 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -fsanitize=undefined" } */
+
+float v;
+int i;
+
+void
+foo (float x, float y)
+{
+  #pragma omp atomic
+  v += x / y;
+}
+
+void
+bar (int x, int y)
+{
+  #pragma omp atomic
+  i += x / y;
+}
+
+void
+baz (int x, int y)
+{
+  #pragma omp atomic
+  i *= (x << y);
+}

        Jakub

Reply via email to