From patchwork Thu Jul 11 20:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1959518 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=MqaHlqLL; 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 4WKm5J4yt2z1xqr for ; Fri, 12 Jul 2024 06:08:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92A313875DCE for ; Thu, 11 Jul 2024 20:08:50 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id E074D385DDE6 for ; Thu, 11 Jul 2024 20:08:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E074D385DDE6 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 E074D385DDE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720728514; cv=none; b=rija+1XSHd23rurpDe80aoUqHcnQuhvPqBREz0nmo5ltCIzI/bUSH7Dx4hw39OP+4yeHM2AnLS/KKIASTE8ISQOBQVFEgUYX8YNWnIVN2FoArh1wPeEJ9BdPq4QiC/n0b0ZCBc1SY72qBGtegnSFD5Y29JXwjWJWi/FQc9gcPCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720728514; c=relaxed/simple; bh=6cPIBlLh5dEAUy2pp9ZdHQyaMZWHZCRTg8cVn+97Zx4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wiqscBu79FRDBjBeTpOHN7FRftV7SYMI3GFwjSCYCIuPlc7hVRwhevXnfTeUUuVj2N3OmREB6+05JT5tdhuL1CeuNkLmh+3JMy0zrbnlNP7AxJEE90tdu68RaBb9DH4FpIYGe2qt75/BjLbyIJe+EIiVn8o50+uXhgYZlsLJ2GU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720728512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D/Er0gJ9+/Qcv8wIJVYUPA54aiMik1HKDwj0y0Z4+FI=; b=MqaHlqLLP2RRm3+em2b2S4u5NRNkLue5quVef0yGTGQWAb0KCycyBf0CNZp3ypXq0h9qNZ SN8rKfH1fTOOsEH764Nj+ZqeuLZBVboRxlnuXEP6jxz41eOSpbdVCXaB1X3sXB3ayQ5sB8 N+uI98avtHRwIoOoOyRv+UgjATbOFVY= 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-571-fIbBV_8TMD6UkSlM4Xj1UA-1; Thu, 11 Jul 2024 16:08:31 -0400 X-MC-Unique: fIbBV_8TMD6UkSlM4Xj1UA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 1460E196CDEF for ; Thu, 11 Jul 2024 20:08:30 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.33.100]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3BB8F1955F3B; Thu, 11 Jul 2024 20:08:28 +0000 (UTC) From: Marek Polacek To: GCC Patches Cc: Jakub Jelinek , Jason Merrill Subject: [PATCH] eh: ICE with std::initializer_list and ASan [PR115865] Date: Thu, 11 Jul 2024 16:08:20 -0400 Message-ID: <20240711200820.502745-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Here we ICE with -fsanitize=address on std::initializer_list x = { 1, 2, 3 }; since r14-8681, which removed .ASAN_MARK calls on TREE_STATIC variables. That means that lower_try_finally now instead of try { .ASAN_MARK (UNPOISON, &C.0, 12); x = {}; x._M_len = 3; x._M_array = &C.0; } finally { .ASAN_MARK (POISON, &C.0, 12); } gets: try { x = {}; x._M_len = 3; x._M_array = &C.0; } finally { } and we ICE on the empty finally in lower_try_finally_onedest while getting get_eh_else. Rather than checking everywhere that a GIMPLE_TRY_FINALLY is not empty, I thought we could process it as if it were unreachable. PR c++/115865 gcc/ChangeLog: * tree-eh.cc (lower_try_finally): If the FINALLY block is empty, treat it as if it were not reachable. gcc/testsuite/ChangeLog: * g++.dg/asan/initlist2.C: New test. --- gcc/testsuite/g++.dg/asan/initlist2.C | 16 ++++++++++++++++ gcc/tree-eh.cc | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asan/initlist2.C base-commit: 74d8accaf88f83bfcab1150bf9be5140e7ac0e94 diff --git a/gcc/testsuite/g++.dg/asan/initlist2.C b/gcc/testsuite/g++.dg/asan/initlist2.C new file mode 100644 index 00000000000..bce5410be33 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/initlist2.C @@ -0,0 +1,16 @@ +// PR c++/115865 +// { dg-do compile } +// { dg-options "-fsanitize=address" } + +typedef decltype(sizeof(char)) size_t; + +namespace std { +template class initializer_list { + int *_M_array; + size_t _M_len; +}; +} + +int main() { + std::initializer_list x = { 1, 2, 3 }; +} diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index a776ad5c92b..6ae6dab223e 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -1703,8 +1703,8 @@ lower_try_finally (struct leh_state *state, gtry *tp) ndests += this_tf.may_return; ndests += this_tf.may_throw; - /* If the FINALLY block is not reachable, dike it out. */ - if (ndests == 0) + /* If the FINALLY block is not reachable or empty, dike it out. */ + if (ndests == 0 || gimple_seq_empty_p (gimple_try_cleanup (tp))) { gimple_seq_add_seq (&this_tf.top_p_seq, gimple_try_eval (tp)); gimple_try_set_cleanup (tp, NULL);