diff mbox series

gimple-fold: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531]

Message ID Zbosd2N2K6oeGGeZ@tucnak
State New
Headers show
Series gimple-fold: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531] | expand

Commit Message

Jakub Jelinek Jan. 31, 2024, 11:18 a.m. UTC
On Wed, Jan 31, 2024 at 10:07:28AM +0100, Jakub Jelinek wrote:
> Indeed.  But what we could do is try to fold_stmt those .ASAN_MARK calls
> away earlier (but sure, the asan.cc change would be still required because
> that would be just an optimization).  But that can be handled incrementally,
> so I think the patch is ok as is (and I can handle the incremental part
> myself).

Like this, so far just tested on the testcase.  Ok for trunk if it passes
bootstrap/regtest on top of Jason's patch?

2024-01-31  Jakub Jelinek  <jakub@redhat.com>

	PR c++/113531
	* gimple-fold.cc (gimple_fold_call): Remove .ASAN_MARK calls
	on variables which were promoted to TREE_STATIC.



	Jakub

Comments

Richard Biener Jan. 31, 2024, 12:04 p.m. UTC | #1
On Wed, Jan 31, 2024 at 12:18 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Jan 31, 2024 at 10:07:28AM +0100, Jakub Jelinek wrote:
> > Indeed.  But what we could do is try to fold_stmt those .ASAN_MARK calls
> > away earlier (but sure, the asan.cc change would be still required because
> > that would be just an optimization).  But that can be handled incrementally,
> > so I think the patch is ok as is (and I can handle the incremental part
> > myself).
>
> Like this, so far just tested on the testcase.  Ok for trunk if it passes
> bootstrap/regtest on top of Jason's patch?

Note we fold all - well, all builtin - calls during gimple lowering.
Maybe we can put this special-casing there instead? (gimple-low.cc:797,
you possibly have to replace with a GIMPLE_NOP)

> 2024-01-31  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/113531
>         * gimple-fold.cc (gimple_fold_call): Remove .ASAN_MARK calls
>         on variables which were promoted to TREE_STATIC.
>
> --- gcc/gimple-fold.cc.jj       2024-01-03 11:51:27.236790799 +0100
> +++ gcc/gimple-fold.cc  2024-01-31 12:09:14.853348505 +0100
> @@ -5722,6 +5722,21 @@ gimple_fold_call (gimple_stmt_iterator *
>               }
>           }
>           break;
> +        case IFN_ASAN_MARK:
> +          {
> +            tree base = gimple_call_arg (stmt, 1);
> +            gcc_checking_assert (TREE_CODE (base) == ADDR_EXPR);
> +            tree decl = TREE_OPERAND (base, 0);
> +            if (VAR_P (decl) && TREE_STATIC (decl))
> +             {
> +               /* Don't poison a variable with static storage; it might have
> +                  gotten marked before gimplify_init_constructor promoted it
> +                  to static.  */
> +               replace_call_with_value (gsi, NULL_TREE);
> +               return true;
> +             }
> +          }
> +         break;
>         case IFN_GOACC_DIM_SIZE:
>         case IFN_GOACC_DIM_POS:
>           result = fold_internal_goacc_dim (stmt);
>
>
>         Jakub
>
diff mbox series

Patch

--- gcc/gimple-fold.cc.jj	2024-01-03 11:51:27.236790799 +0100
+++ gcc/gimple-fold.cc	2024-01-31 12:09:14.853348505 +0100
@@ -5722,6 +5722,21 @@  gimple_fold_call (gimple_stmt_iterator *
 	      }
 	  }
 	  break;
+        case IFN_ASAN_MARK:
+          {
+            tree base = gimple_call_arg (stmt, 1);
+            gcc_checking_assert (TREE_CODE (base) == ADDR_EXPR);
+            tree decl = TREE_OPERAND (base, 0);
+            if (VAR_P (decl) && TREE_STATIC (decl))
+	      {
+	        /* Don't poison a variable with static storage; it might have
+		   gotten marked before gimplify_init_constructor promoted it
+		   to static.  */
+		replace_call_with_value (gsi, NULL_TREE);
+		return true;
+	      }
+          }
+	  break;
 	case IFN_GOACC_DIM_SIZE:
 	case IFN_GOACC_DIM_POS:
 	  result = fold_internal_goacc_dim (stmt);