From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 89CB138582AC; Thu, 1 Feb 2024 08:19:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89CB138582AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706775593; bh=zTaeMTd/SffD+Q6IwTBG7r4y0Up4SmuXKjdJT3Dk7hw=; h=From:To:Subject:Date:From; b=JPxYzMKuRClUKLT+qkVlSzScmpKsHMC/gOVsyTCwKOcAqCY36Zprw0mW0+YijwmvE /kqITdlxJk0IEHIjYAJfYAVe8yWF5NccDU6Fnn4BfWvuaC0dpb3ZrdeN3faUQHesIA b1FlfsqyPDRnzobuu3Xt30Zivs+YiLEZDQFjWd6U= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8681] gimple-low: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 2f14c0dbb789852947cb58fdf7d3162413f053fa X-Git-Newrev: ceb242f5302027c44a7dca86c344863004b6fec4 Message-Id: <20240201081953.89CB138582AC@sourceware.org> Date: Thu, 1 Feb 2024 08:19:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ceb242f5302027c44a7dca86c344863004b6fec4 commit r14-8681-gceb242f5302027c44a7dca86c344863004b6fec4 Author: Jakub Jelinek Date: Thu Feb 1 09:16:57 2024 +0100 gimple-low: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531] Since the r14-1500-g4d935f52b0d5c0 commit we promote an initializer_list backing array to static storage where appropriate, but this happens after we decided to add it to asan_poisoned_variables. As a result we add unpoison/poison for it to the gimple. But then sanopt removes the unpoison. So the second time we call the function and want to load from the array asan still considers it poisoned. The following patch fixes it by removing the .ASAN_MARK internal calls during gimple lowering if they refer to TREE_STATIC vars. 2024-02-01 Jakub Jelinek Jason Merrill PR c++/113531 * gimple-low.cc (lower_stmt): Remove .ASAN_MARK calls on variables which were promoted to TREE_STATIC. * g++.dg/asan/initlist1.C: New test. Co-authored-by: Jason Merrill Diff: --- gcc/gimple-low.cc | 15 +++++++++++++++ gcc/testsuite/g++.dg/asan/initlist1.C | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/gimple-low.cc b/gcc/gimple-low.cc index 0fca9740898b..e19fc2cce9d4 100644 --- a/gcc/gimple-low.cc +++ b/gcc/gimple-low.cc @@ -790,6 +790,21 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data) return; } + if (gimple_call_internal_p (stmt, 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. */ + gsi_remove (gsi, true); + return; + } + } + /* We delay folding of built calls from gimplification to here so the IL is in consistent state for the diagnostic machineries job. */ diff --git a/gcc/testsuite/g++.dg/asan/initlist1.C b/gcc/testsuite/g++.dg/asan/initlist1.C new file mode 100644 index 000000000000..6cd5b7d3aba1 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/initlist1.C @@ -0,0 +1,20 @@ +// PR c++/113531 +// { dg-do run { target c++11 } } +// { dg-additional-options "-fsanitize=address" } + +#include + +void f(int) { } + +void g() +{ + for (auto i : { 1, 2, 3 }) + f (i); + f(42); +} + +int main() +{ + g(); + g(); +}