From patchwork Thu Oct 24 07:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 2001501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BdiomcQ8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XYyGp1pfCz1xtp for ; Thu, 24 Oct 2024 18:29:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66AFB3858D21 for ; Thu, 24 Oct 2024 07:29:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id E9B7A3858D21 for ; Thu, 24 Oct 2024 07:29:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E9B7A3858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E9B7A3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754956; cv=none; b=VI8khURqsgS6nQ8kb923RPNLW5YP+xIupdYoR7jT+rohuNuZlVXMCmSsbJ+Id9bp7Mh+gxIy2hChXcRHgcohS5CIReLscEf9g1rjz5sWSqph15gq8oq97aFZVaU4iLm7ksCoSyCv1CAcBsUXxSavCzO6DFr/zeRv5QxGPiSN+sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729754956; c=relaxed/simple; bh=LNmaPtzcnWHVFh7PO0fm9xv/WLRDAi4cDwPLE6AaGXI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=nKxh3Ky9lQqOdMR82zKUauaS96o6jKCoZy8FEE/A54LsfiJ7kZiwzNLvs17z+mc5a4KMe4Gvb1SilucsIelCKcEDio/E6HHhlH7Qvm2RZnrVLsLUz5qTSqeSqbW+h87gMrNGGjbF9TmytE/xg11fDlUo+IxfSYLZM6MmuSvJDtQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729754945; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=amu7ktn466pMDtk3rAA/9o31cSbT+Ob8lZpd1lMX3Pw=; b=BdiomcQ8148Alm/9M1i1RtkRM8oPa1H0iq2SRMGYRhk7UwkXFhuOWfxNR+3ektp5g7Y+DX tRwKBF03nrix807b4NvR/rE4p7kzO06+KfzJXEQP7anWV73FyJ66xihRyveGAFlhplDrfY I1o/BVTTn54R4hMUFIRzSLH2RRd1/aE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-iqRAyHkQOLiZhuYTN3VIJQ-1; Thu, 24 Oct 2024 03:29:03 -0400 X-MC-Unique: iqRAyHkQOLiZhuYTN3VIJQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C13D1956089; Thu, 24 Oct 2024 07:29:02 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EEE6C1956056; Thu, 24 Oct 2024 07:29:01 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 49O7SwSt2282547 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 09:28:58 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49O7Sw6K2282546; Thu, 24 Oct 2024 09:28:58 +0200 Date: Thu, 24 Oct 2024 09:28:58 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] asan: Fix up build_check_stmt gsi handling [PR117209] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! gsi_safe_insert_before properly updates gsi_bb in gimple_stmt_iterator in case it splits objects, but unfortunately build_check_stmt was in some places (but not others) using a copy of the iterator rather than the iterator passed from callers and so didn't propagate that to callers. I guess it didn't matter much before when it was just using gsi_insert_before as that really didn't change the iterator. The !before_p case is apparently dead code, nothing is calling it with before_p=false since around 4.9. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-10-24 Jakub Jelinek PR sanitizer/117209 * asan.cc (maybe_cast_to_ptrmode): Formatting fix. (build_check_stmt): Don't copy *iter into gsi, perform all the updates on iter directly. * gcc.dg/asan/pr117209.c: New test. Jakub --- gcc/asan.cc.jj 2024-08-30 09:09:44.924630892 +0200 +++ gcc/asan.cc 2024-10-23 12:00:39.352238282 +0200 @@ -2610,7 +2610,7 @@ maybe_cast_to_ptrmode (location_t loc, t if (ptrofftype_p (len)) return len; gimple *g = gimple_build_assign (make_ssa_name (pointer_sized_int_node), - NOP_EXPR, len); + NOP_EXPR, len); gimple_set_location (g, loc); if (before_p) gsi_safe_insert_before (iter, g); @@ -2644,16 +2644,13 @@ build_check_stmt (location_t loc, tree b bool is_non_zero_len, bool before_p, bool is_store, bool is_scalar_access, unsigned int align = 0) { - gimple_stmt_iterator gsi = *iter; gimple *g; gcc_assert (!(size_in_bytes > 0 && !is_non_zero_len)); gcc_assert (size_in_bytes == -1 || size_in_bytes >= 1); - gsi = *iter; - base = unshare_expr (base); - base = maybe_create_ssa_name (loc, base, &gsi, before_p); + base = maybe_create_ssa_name (loc, base, iter, before_p); if (len) { @@ -2704,12 +2701,11 @@ build_check_stmt (location_t loc, tree b align / BITS_PER_UNIT)); gimple_set_location (g, loc); if (before_p) - gsi_safe_insert_before (&gsi, g); + gsi_safe_insert_before (iter, g); else { - gsi_insert_after (&gsi, g, GSI_NEW_STMT); - gsi_next (&gsi); - *iter = gsi; + gsi_insert_after (iter, g, GSI_NEW_STMT); + gsi_next (iter); } } --- gcc/testsuite/gcc.dg/asan/pr117209.c.jj 2024-10-23 12:16:19.418928237 +0200 +++ gcc/testsuite/gcc.dg/asan/pr117209.c 2024-10-23 12:16:12.970019545 +0200 @@ -0,0 +1,15 @@ +/* PR sanitizer/117209 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=address" } */ + +struct A { char a; }; +void foo (void); +__attribute__((returns_twice, const)) int bar (struct A); + +void +baz (struct A *x, int *y, int z) +{ + if (z) + foo (); + *y = bar (*x); +}