From patchwork Wed Oct 16 12:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1998026 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=a5eqKpTx; 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 4XT9Z06x8Zz1xvV for ; Wed, 16 Oct 2024 23:41:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DBB83857346 for ; Wed, 16 Oct 2024 12:41:09 +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 7904A3858289 for ; Wed, 16 Oct 2024 12:40:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7904A3858289 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 7904A3858289 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=1729082448; cv=none; b=wjvthpqFTLfR2fg+/c/JLqY0QQ5y7B077FOrqmBYRLX2sAtzvuRydn1kejyIRpVUvOMiuuCk9uV6jBAZPUfMNXfO6JIzqPX9cAP7XbL400wWVthJHbLLITxqWJOiDP9BL0VE1DSPs7av3/HzAB5S8pJoCJM139H6+nph3FnCkLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729082448; c=relaxed/simple; bh=ReEZc/RHeNmpTkrb3cntw4Ocpg0XMEAQFzt0/L2wLKQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=e4k+QLClVdgNWCQmnnY1NVGGs3pmSlzcUrDJ2BsOEiA6UXSTxuj1vsvQcyWfBNKseAgcGi22d8jX0FxgXNUy8wPZ1/WKl4DD5Y2Bvjf2TyxH3bz8sewcLkl9E/ZFj6WRb+oW+dYTA5WMt6yMdg/r1PQ3Yux0NKMc5xAriHdI0R8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729082446; 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=SESQ3BM1aVtHDV0KXh6jHldzxFszJ8UEadXyoirXY18=; b=a5eqKpTxKSpMHXnZmQveere4tWQgsNwVrJq+Ulcd2z4PhP0PQRyz0akC+wEQGjJVgL/3yu FhwAk5I4Suekg4cEL8nqVTfnO8cvKullcDAduHacT9aO5cQeh5N7ZLVvzdnKmlgx4kkgE/ oWp93vO2XcQRy4wdFAJdHb/IiyulPMA= Received: from mx-prod-mc-05.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-244-ZdyM_ntTOaKOJof_g2QvQQ-1; Wed, 16 Oct 2024 08:40:45 -0400 X-MC-Unique: ZdyM_ntTOaKOJof_g2QvQQ-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6E9FA195608C for ; Wed, 16 Oct 2024 12:40:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 994C51955F43; Wed, 16 Oct 2024 12:40:42 +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 49GCedEk1584637 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 16 Oct 2024 14:40:39 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49GCedSa1584636; Wed, 16 Oct 2024 14:40:39 +0200 Date: Wed, 16 Oct 2024 14:40:39 +0200 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Add some checking asserts to named loops handling code Message-ID: 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 Content-Disposition: inline X-Spam-Status: No, score=-0.9 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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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! Jonathan mentioned an unnamed static analyzer reported issue in c_finish_bc_name. It is actually a false positive, because the construction of the loop_names vector guarantees that the last element of the vector (if the vector is non-empty) always has either C_DECL_LOOP_NAME (l) or C_DECL_SWITCH_NAME (l) (or both) flags set, so c will be always non-NULL after the if at the start of the loops. The following patch is an attempt to help those static analyzers (though dunno if it actually helps), by adding a checking assert. Tested on x86_64-linux, ok for trunk? 2024-10-16 Jakub Jelinek * c-decl.cc (c_get_loop_names): Add checking assert that c is non-NULL in the loop. (c_finish_bc_name): Likewise. Jakub --- gcc/c/c-decl.cc.jj 2024-10-16 10:06:06.378589144 +0200 +++ gcc/c/c-decl.cc 2024-10-16 14:30:36.253187498 +0200 @@ -13881,6 +13881,7 @@ c_get_loop_names (tree before_labels, bo { if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l)) c = l; + gcc_checking_assert (c); loop_names_hash->put (l, c); if (i == first) break; @@ -13952,6 +13953,7 @@ c_finish_bc_name (location_t loc, tree n { if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l)) c = l; + gcc_checking_assert (c); if (l == lab) { label = c; @@ -13970,6 +13972,7 @@ c_finish_bc_name (location_t loc, tree n { if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l)) c = l; + gcc_checking_assert (c); if (is_break || C_DECL_LOOP_NAME (c)) candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l))); }