Fix wrong use-after-scope sanitization for omp variable (PR sanitizer/85081).
authorJakub Jelinek <jakub@redhat.com>
Wed, 28 Mar 2018 14:45:21 +0000 (16:45 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 28 Mar 2018 14:45:21 +0000 (14:45 +0000)
2018-03-28  Jakub Jelinek  <jakub@redhat.com>
    Martin Liska  <mliska@suse.cz>

PR sanitizer/85081
* gimplify.c (asan_poison_variable): Don't do the check for
gimplify_omp_ctxp here.
(gimplify_decl_expr): Do it here.
(gimplify_target_expr): Likewise.
2018-03-28  Jakub Jelinek  <jakub@redhat.com>
    Martin Liska  <mliska@suse.cz>

PR sanitizer/85081
* g++.dg/asan/pr85081.C: New test.

Co-Authored-By: Martin Liska <mliska@suse.cz>
From-SVN: r258924

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/asan/pr85081.C [new file with mode: 0644]

index 33f78bc91ba929904fc2b1bf329d6b733d8fb54b..7742da1f89b3f0d7b8ebb18e0ecde0f1a93e961d 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-28  Jakub Jelinek  <jakub@redhat.com>
+           Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/85081
+       * gimplify.c (asan_poison_variable): Don't do the check for
+       gimplify_omp_ctxp here.
+       (gimplify_decl_expr): Do it here.
+       (gimplify_target_expr): Likewise.
+
 2018-03-28  Martin Liska  <mliska@suse.cz>
 
        PR target/84988
index 115f80bef9b6fa9238495a53d791fcb0e820a776..c32869b4c59d3b7057efbbf8698b0188acd969f7 100644 (file)
@@ -1168,10 +1168,6 @@ static void
 asan_poison_variable (tree decl, bool poison, gimple_stmt_iterator *it,
                      bool before)
 {
-  /* When within an OMP context, do not emit ASAN_MARK internal fns.  */
-  if (gimplify_omp_ctxp)
-    return;
-
   tree unit_size = DECL_SIZE_UNIT (decl);
   tree base = build_fold_addr_expr (decl);
 
@@ -1689,7 +1685,8 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p)
          && !TREE_STATIC (decl)
          && !DECL_HAS_VALUE_EXPR_P (decl)
          && DECL_ALIGN (decl) <= MAX_SUPPORTED_STACK_ALIGNMENT
-         && dbg_cnt (asan_use_after_scope))
+         && dbg_cnt (asan_use_after_scope)
+         && !gimplify_omp_ctxp)
        {
          asan_poisoned_variables->add (decl);
          asan_poison_variable (decl, false, seq_p);
@@ -6614,7 +6611,8 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
            }
          if (asan_poisoned_variables
              && DECL_ALIGN (temp) <= MAX_SUPPORTED_STACK_ALIGNMENT
-             && dbg_cnt (asan_use_after_scope))
+             && dbg_cnt (asan_use_after_scope)
+             && !gimplify_omp_ctxp)
            {
              tree asan_cleanup = build_asan_poison_call_expr (temp);
              if (asan_cleanup)
index 0fea41898605bde28a06b8cfb61903c0ffcf7123..fc1d5d078ed46c125beffa2321ad577a01ed1e8d 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-28  Jakub Jelinek  <jakub@redhat.com>
+           Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/85081
+       * g++.dg/asan/pr85081.C: New test.
+
 2018-03-28  Alexandre Oliva <aoliva@redhat.com>
 
        PR c++/84789
diff --git a/gcc/testsuite/g++.dg/asan/pr85081.C b/gcc/testsuite/g++.dg/asan/pr85081.C
new file mode 100644 (file)
index 0000000..d7dec31
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR sanitizer/85081 */
+/* { dg-do run } */
+/* { dg-options "-fopenmp-simd" } */
+/* { dg-require-effective-target fopenmp } */
+
+inline const int& max(const int& a, const int& b)
+{
+  return a < b ? b : a;
+}
+
+int main()
+{
+  #pragma omp simd
+  for ( int i = 0; i < 20; ++i )
+  {
+    const int j = max(i, 1);
+  }
+
+  return 0;
+}