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.
&& !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);
--- /dev/null
+-- { 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;
--- /dev/null
+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;