From patchwork Wed Jul 17 21:45:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1961776 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=NPFFoB6A; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WPTyy01QSz20B2 for ; Thu, 18 Jul 2024 07:46:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C513385E836 for ; Wed, 17 Jul 2024 21:46:14 +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 1434C3858C48 for ; Wed, 17 Jul 2024 21:45:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1434C3858C48 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 1434C3858C48 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=1721252755; cv=none; b=Zv9B5nHT9W35zU/cxY5gmjX9ToVCvMazbbzWJ1Si+PBYCp85KaJBg6cviI3oQq5CF/qs736wAWYPor8xP76lzLFiJrOh8JshwL1lidyEhbGsbcICLWLbfnZFVvcIzjWOuC0bEb2dZ5bCWepHXOh6coFG793wbAvPhiIDLj1A3Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721252755; c=relaxed/simple; bh=4LzlKH8FM+HEb5ndL+ofDVIGnA2v+u0QhxOmufjxvMY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=dGlmoCAoBpGyUeO2ZK+b/lxfv4V49KYCEIXlkrurBg6Q65nWHIRVb7qoBSr0IwG3jhfxHrU46/NYTuK9Eg9S9ISglR66ry3QWtsJP174GqG7Ak6cNlzL3tOn3rCkl6kUumU6U0m5Pp1HL1sbunWR8K53Uu40gjzfaIXhZi6TMAk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721252753; 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: in-reply-to:in-reply-to:references:references; bh=MSaxbwXjX/A6hp+/j4cngZrEhPYY4O48nkQ7H6DBYoA=; b=NPFFoB6AilFVqh+0XoJ/gfxK+P374pNxAOo7Iay9/sZqpbB6Skc51k5n19VMA4Lw9/B6V1 hA6HCq4abszueOTqE9Fu4EWa9YvbSJukpO9nJPPDySUeSDtPfCWyB54dOOq72epNOJjgzL 9HzJTkgggBevAb3IFiPMY6lINVaizyI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-0YbKDi8-NrKFeL5m2egqZg-1; Wed, 17 Jul 2024 17:45:51 -0400 X-MC-Unique: 0YbKDi8-NrKFeL5m2egqZg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6b5e21026fcso2898796d6.0 for ; Wed, 17 Jul 2024 14:45:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721252751; x=1721857551; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MSaxbwXjX/A6hp+/j4cngZrEhPYY4O48nkQ7H6DBYoA=; b=hVFAmhtiJB7XLOju66V6pe/D48LeCI+aSj4Uy623FgtA+FOIXh923BstqYpOh4WwUZ ifK0Cn00NTGU/IAFTbxCx2nNgl62we5hn2MtgEBYpc0ZvpUFQuCo0f8sGR/EEwCQu7WO m7COsp7PF6ZPER11ZaJd+nYWIJ3aIxQvgWZC3akFB3lKa/VedDL/BVbvbzUE+q7zRMPG A+gZMrM8mu4tyBEX62qhUWTacbheD5sXabBPgY9V1mu7OqxruYaKgNNGINQux/mGE+S+ bM5oC3xToPpUvGOleCRn2yveLoADR5Y/kzxKPQxjAq5ms4G/2GRedkL2FYE7BTRnbDX8 JyIw== X-Forwarded-Encrypted: i=1; AJvYcCVqegXjAJXt1+UDXSBnGLas6na6IWstawozmx9da5XHsCAMXl6whlZpHdJyObgTqVwyZR8lSMVtFZLPuIrxu5VbJdmFQPdQ3Q== X-Gm-Message-State: AOJu0YzKa+e1DHlBpe7YveZLqGwINs34ohMz72mtWZlh2zxyPeaDnWJ9 XFUaA9S7QpyB0d28Ig85mMQrao0Rv0aE0zAFQE6bQWkcWD6cqtIBNKciKDPsf0sF+oG/g2LHLcX 4/X/6R/lGmDTMUfAp7Vl7zRZDDXB6bFc8SU+r/CS4va10BTfBToL1ID+u15Jl4Dg= X-Received: by 2002:a05:6214:5283:b0:6b5:46f1:6b05 with SMTP id 6a1803df08f44-6b78e322c25mr36839656d6.53.1721252750820; Wed, 17 Jul 2024 14:45:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpVorfvlObOSr0ut0c1nf5mWEgG7ysYLUBZFpvvKPT4DLQHIYaVlOaAlsSTXDmvqChg5BwCA== X-Received: by 2002:a05:6214:5283:b0:6b5:46f1:6b05 with SMTP id 6a1803df08f44-6b78e322c25mr36839416d6.53.1721252750459; Wed, 17 Jul 2024 14:45:50 -0700 (PDT) Received: from redhat.com ([2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b79c64d4easm2409736d6.114.2024.07.17.14.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 14:45:50 -0700 (PDT) Date: Wed, 17 Jul 2024 17:45:48 -0400 From: Marek Polacek To: Jakub Jelinek Cc: Jason Merrill , GCC Patches Subject: [PATCH v2] eh: ICE with std::initializer_list and ASan [PR115865] Message-ID: References: <20240711200820.502745-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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_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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org On Wed, Jul 17, 2024 at 01:37:23PM +0200, Jakub Jelinek wrote: > On Thu, Jul 11, 2024 at 04:08:20PM -0400, Marek Polacek wrote: > > 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. > > I'm not sure we need to check everywhere, the only spot is get_eh_else > from what I can see and IMHO that should be fixed with something like: [...] Okay, here's a v2 which does what you suggest: 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. PR c++/115865 gcc/ChangeLog: * tree-eh.cc (get_eh_else): Check that the result of gimple_seq_first_stmt is non-null. gcc/testsuite/ChangeLog: * g++.dg/asan/initlist2.C: New test. Co-authored-by: Jakub Jelinek --- gcc/testsuite/g++.dg/asan/initlist2.C | 16 ++++++++++++++++ gcc/tree-eh.cc | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/asan/initlist2.C base-commit: ec64666f97be24595ae0bc9055c19dabbe68a14c 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..9609bdc0d9b 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -950,7 +950,7 @@ static inline geh_else * get_eh_else (gimple_seq finally) { gimple *x = gimple_seq_first_stmt (finally); - if (gimple_code (x) == GIMPLE_EH_ELSE) + if (x && gimple_code (x) == GIMPLE_EH_ELSE) { gcc_assert (gimple_seq_singleton_p (finally)); return as_a (x);