public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6903] skip asan-poisoning of discarded vars
@ 2021-01-26  0:46 Alexandre Oliva
  0 siblings, 0 replies; only message in thread
From: Alexandre Oliva @ 2021-01-26  0:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:667c8e33270e267c764202021c350ef2d5d861e7

commit r11-6903-g667c8e33270e267c764202021c350ef2d5d861e7
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Mon Jan 25 21:45:58 2021 -0300

    skip asan-poisoning of discarded vars
    
    GNAT may create temporaries to hold return values of function calls.
    If such a temporary is created as part of a dynamic initializer of a
    variable in a unit other than the one being compiled, the initializer
    is dropped, including the temporary and its binding block.
    
    Don't issue asan mark calls for such variables, they are gone.
    
    
    for  gcc/ChangeLog
    
            * gimplify.c (gimplify_decl_expr): Skip asan marking calls for
            temporaries not seen in binding block, and not about to be
            added as gimple variables.
    
    for  gcc/testsuite/ChangeLog
    
            * gnat.dg/asan1.adb: New test.
            * gnat.dg/asan1_pkg.ads: New additional source.

Diff:
---
 gcc/gimplify.c                      |  8 +++++++-
 gcc/testsuite/gnat.dg/asan1.adb     | 15 +++++++++++++++
 gcc/testsuite/gnat.dg/asan1_pkg.ads |  9 +++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index d2ac5f91359..95d55bb8ba4 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1795,7 +1795,13 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p)
 	  && !DECL_HAS_VALUE_EXPR_P (decl)
 	  && DECL_ALIGN (decl) <= MAX_SUPPORTED_STACK_ALIGNMENT
 	  && dbg_cnt (asan_use_after_scope)
-	  && !gimplify_omp_ctxp)
+	  && !gimplify_omp_ctxp
+	  /* GNAT introduces temporaries to hold return values of calls in
+	     initializers of variables defined in other units, so the
+	     declaration of the variable is discarded completely.  We do not
+	     want to issue poison calls for such dropped variables.  */
+	  && (DECL_SEEN_IN_BIND_EXPR_P (decl)
+	      || (DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE)))
 	{
 	  asan_poisoned_variables->add (decl);
 	  asan_poison_variable (decl, false, seq_p);
diff --git a/gcc/testsuite/gnat.dg/asan1.adb b/gcc/testsuite/gnat.dg/asan1.adb
new file mode 100644
index 00000000000..a4bc59a9a21
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/asan1.adb
@@ -0,0 +1,15 @@
+--  { dg-do compile }
+--  { dg-additional-sources asan1_pkg.ads }
+--  { dg-options "-fsanitize=address" }
+--  { dg-skip-if "" no_fsanitize_address }
+
+with Asan1_Pkg;
+
+procedure Asan1 is
+   use Asan1_Pkg;
+
+   X, Y : E;
+begin
+   X := C (N);
+   Y := V;
+end Asan1;
diff --git a/gcc/testsuite/gnat.dg/asan1_pkg.ads b/gcc/testsuite/gnat.dg/asan1_pkg.ads
new file mode 100644
index 00000000000..fbbc1c5e7f5
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/asan1_pkg.ads
@@ -0,0 +1,9 @@
+package Asan1_Pkg is
+   subtype E is Integer;
+   type T is array (1..32) of E;
+
+   function N return T;
+   function C (P : T) return E;
+
+   V : constant E := C (N);
+end Asan1_Pkg;


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

only message in thread, other threads:[~2021-01-26  0:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-26  0:46 [gcc r11-6903] skip asan-poisoning of discarded vars Alexandre Oliva

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