From patchwork Mon Jul 29 07:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1965879 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=HvSnRAHz; 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 4WXVhq6WS5z1ybY for ; Mon, 29 Jul 2024 17:43:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 169E5385840A for ; Mon, 29 Jul 2024 07:43:22 +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 ESMTP id 1E00D3858C52 for ; Mon, 29 Jul 2024 07:42:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E00D3858C52 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 1E00D3858C52 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=1722238975; cv=none; b=r/lF4Ek/1foMe1y+lleQveunrKjCyqtxvptuTEDKkaiBlBIIZ9SOjoT13pxxnCehPHu0mwZJ0Xd80ljTlqB5GFFn2kNk9HBrN310KBv3f9uByAszFAALf5OQ9b0WgPaXdBATGfWL6DYupVPVsMTboOMw7McEspTLiLURRHG41/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722238975; c=relaxed/simple; bh=8ftNtg19HYwzRYUuUJBaMNY8nsbthF7yx3tE6gZux8Q=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=nEB66iJbv60TN9XIzIR5TBW5uVguAFMAg4zeJufmnhAWyw6zlw82XLVnRziTW28eqaLQUZcJqtkqn1GlEvMvib16Fl1PuEPhwH5JgCSu+X+zWiQOnDBewxOh09fpYesCXEDycpkaxBZ6y7DAFw4CIUHKdnQZ0bNepCrUA4xM+Y4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722238973; 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=U/wqcsjXSE6FoIlfQkNhVfKZxHypGy6TzpQFjqJhUJY=; b=HvSnRAHz8Gm26zxCAWLVN3LBsXa/Xh/WZBTUf//Ce9MgXdCWWnYWUAmSKAmPnCvy7bZDl3 wNvyHfh35sQW3atWwVPGrCyL3vmsQTzTVu3mmfGLRTS0BISoQzL3Rlh8g7OIHI9DtVEcXp qdrERhyUzW2ivHD2KMjg/i11SwceaLE= Received: from mx-prod-mc-03.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-439-aTOkfXHZPH2hwb1u0xupsg-1; Mon, 29 Jul 2024 03:42:51 -0400 X-MC-Unique: aTOkfXHZPH2hwb1u0xupsg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 55F411955D44 for ; Mon, 29 Jul 2024 07:42:50 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B11723000197; Mon, 29 Jul 2024 07:42:49 +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 46T7gkPI901344 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 29 Jul 2024 09:42:46 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 46T7gkU7901343; Mon, 29 Jul 2024 09:42:46 +0200 Date: Mon, 29 Jul 2024 09:42:46 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up error recovery of invalid structured bindings used in conditions [PR116113] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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! The following testcase ICEs, because for structured binding error recovery DECL_DECOMP_BASE is kept NULL and the newly added code to pick up saved value from the base assumes that on structured binding bases the TARGET_EXPR will be always there (that is the case if there are no errors). The following patch fixes it by testing DECL_DECOMP_BASE before dereferencing it, another option would be not to do that if error_operand_p (cond). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-07-29 Jakub Jelinek PR c++/116113 * semantics.cc (maybe_convert_cond): Check DECL_DECOMP_BASE is non-NULL before dereferencing it. (finish_switch_cond): Likewise. * g++.dg/cpp26/decomp11.C: New test. Jakub --- gcc/cp/semantics.cc.jj 2024-07-24 15:47:15.238477295 +0200 +++ gcc/cp/semantics.cc 2024-07-27 09:44:44.537658588 +0200 @@ -972,6 +972,7 @@ maybe_convert_cond (tree cond) result in a TARGET_EXPR, pick it up from there. */ if (DECL_DECOMPOSITION_P (cond) && DECL_DECOMP_IS_BASE (cond) + && DECL_DECOMP_BASE (cond) && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR) cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond)); @@ -1714,6 +1715,7 @@ finish_switch_cond (tree cond, tree swit conversion result in a TARGET_EXPR, pick it up from there. */ if (DECL_DECOMPOSITION_P (cond) && DECL_DECOMP_IS_BASE (cond) + && DECL_DECOMP_BASE (cond) && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR) cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond)); cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); --- gcc/testsuite/g++.dg/cpp26/decomp11.C.jj 2024-07-27 09:49:54.931612663 +0200 +++ gcc/testsuite/g++.dg/cpp26/decomp11.C 2024-07-27 09:52:09.411859739 +0200 @@ -0,0 +1,19 @@ +// PR c++/116113 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +extern int b[]; + +void +foo () +{ + auto [a] = b; // { dg-error "is incomplete" } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + if (a) + ; + switch (a) + { + default: + break; + } +}