Message ID | ZqtNFuQm0shtuzdZ@tucnak |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D7C03858414 for <patchwork@sourceware.org>; Thu, 1 Aug 2024 08:54:45 +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 30FE63858C78 for <gcc-patches@gcc.gnu.org>; Thu, 1 Aug 2024 08:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30FE63858C78 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 30FE63858C78 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=1722502436; cv=none; b=HtIXxPPd+fu4BEO00XTs1su40gRj91jPU7WIEuW2j2J0itDy1miv1Y8DE5n00XmpB9odLYPRLE93kBYipmnKMEpLHl/d5cM+5PkjB4lDVhRlj6uGRIx8oGiCUJSxTSUreoyFGMGjqlgTcDn4LMUz4MLBFdeQGjQR7jGSKxV3y0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722502436; c=relaxed/simple; bh=ZsbYGcOmVS7HZJmrjTcMyIScXDSYEqmBY23p37ElzYk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=DCyXlwFV/QMaFoNpiRjm3Ql32WSreAoZO1DBOxy2z+ylUBQF+0EkoLzE8uEvfTM9rQ8W6ZZZ9ocZ8eJeW7d9jeyHr045vb7x54w9ypt+Qm/4C8EI5MU+URT0l4eVYqKT2Lls2Kt6x4fEqNnTw3RS/ERPlu3sMfHNHuSiO40WtoA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722502431; 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=4YD4MX0tWt6bU2vFYz3hir4R7a67iB6WEsfiW+pGsmU=; b=PFxFWktcYaKHm3wfpN2X+tgGIa3S88K0X7kHw0Z2wUfoLFu+RR0+DZDpnvriJ0Nz3uyZND XWaMiIYHNNGIHX7zFBwunHu+ewhYcuuIo85xQlXdChFEp1pBjWijrqcdzyxIM06K6Mc1me A+WAZjQgmVaTmdYAGmyANQAsn4BX7x0= 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-575-0Hdi0uBzNs299loaC2wcJg-1; Thu, 01 Aug 2024 04:53:48 -0400 X-MC-Unique: 0Hdi0uBzNs299loaC2wcJg-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 A0D671955D59; Thu, 1 Aug 2024 08:53:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E08091955E8C; Thu, 1 Aug 2024 08:53:45 +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 4718rgvT3077084 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Aug 2024 10:53:42 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4718rgai3077083; Thu, 1 Aug 2024 10:53:42 +0200 Date: Thu, 1 Aug 2024 10:53:42 +0200 From: Jakub Jelinek <jakub@redhat.com> To: fortran@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] fortran: Fix up paste in gfc_get_array_descr_info Message-ID: <ZqtNFuQm0shtuzdZ@tucnak> 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-Type: text/plain; charset=us-ascii 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
Series |
fortran: Fix up paste in gfc_get_array_descr_info
|
|
Checks
Context | Check | Description |
---|---|---|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 | success | Build passed |
linaro-tcwg-bot/tcwg_gcc_build--master-arm | success | Build passed |
Commit Message
Jakub Jelinek
Aug. 1, 2024, 8:53 a.m. UTC
Hi! A static analyzer found a pasto in gfc_get_array_descr_info. The code does t = base_decl; if (!integer_zerop (dtype_off)) t = fold_build_pointer_plus (t, dtype_off); dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); rank_off = byte_position (field); if (!integer_zerop (dtype_off)) t = fold_build_pointer_plus (t, rank_off); i.e. uses the same !integer_zerop check between both, while it should be checking rank_off in the latter case. This actually doesn't change anything on the generated code, because both the dtype_off and rank_off aren't zero, typedef struct dtype_type { size_t elem_len; int version; signed char rank; signed char type; signed short attribute; } dtype_type; struct { type *base_addr; size_t offset; dtype_type dtype; index_type span; descriptor_dimension dim[]; }; dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is 12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to pacify those static analyzers or be prepared if the ABI changes in the future. Though, as we know that the offsets currently aren't zero, checking for !integer_zerop isn't actually an optimization but slow things down, fold_build_pointer_plus will handle += 0 as well, so maybe we should just drop it for the cases where we know it isn't 0. Anyway, the following patch just does the minimal change, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-01 Jakub Jelinek <jakub@redhat.com> * trans-types.cc (gfc_get_array_descr_info): Add rank_off to t if rank_off isn't zero rather than dtype_off. Jakub
Comments
Hello, Le 01/08/2024 à 10:53, Jakub Jelinek a écrit : > Hi! > > A static analyzer found a pasto in gfc_get_array_descr_info. > The code does > t = base_decl; > if (!integer_zerop (dtype_off)) > t = fold_build_pointer_plus (t, dtype_off); > dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); > field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); > rank_off = byte_position (field); > if (!integer_zerop (dtype_off)) > t = fold_build_pointer_plus (t, rank_off); > i.e. uses the same !integer_zerop check between both, while it should > be checking rank_off in the latter case. > This actually doesn't change anything on the generated code, because > both the dtype_off and rank_off aren't zero, > typedef struct dtype_type > { > size_t elem_len; > int version; > signed char rank; > signed char type; > signed short attribute; > } > dtype_type; > struct { > type *base_addr; > size_t offset; > dtype_type dtype; > index_type span; > descriptor_dimension dim[]; > }; > dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is > 12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to > pacify those static analyzers or be prepared if the ABI changes in the > future. > Though, as we know that the offsets currently aren't zero, checking for > !integer_zerop isn't actually an optimization but slow things down, > fold_build_pointer_plus will handle += 0 as well, so maybe we should just > drop it for the cases where we know it isn't 0. > Yes, I've always wondered how much of a win these integer_zerop checks were, probably not that much. In the cases we know they are useless, let's remove them (patch pre-approved for gfc_get_array_descr_info). > Anyway, the following patch just does the minimal change, > bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > Looks good, but as said removing the check seems preferable. > 2024-08-01 Jakub Jelinek <jakub@redhat.com> > > * trans-types.cc (gfc_get_array_descr_info): Add rank_off to t > if rank_off isn't zero rather than dtype_off. > > --- gcc/fortran/trans-types.cc.jj 2024-07-19 17:22:59.405097054 +0200 > +++ gcc/fortran/trans-types.cc 2024-07-31 20:48:20.546569993 +0200 > @@ -3605,7 +3605,7 @@ gfc_get_array_descr_info (const_tree typ > dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); > field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); > rank_off = byte_position (field); > - if (!integer_zerop (dtype_off)) > + if (!integer_zerop (rank_off)) > t = fold_build_pointer_plus (t, rank_off); > > t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t); > > Jakub >
--- gcc/fortran/trans-types.cc.jj 2024-07-19 17:22:59.405097054 +0200 +++ gcc/fortran/trans-types.cc 2024-07-31 20:48:20.546569993 +0200 @@ -3605,7 +3605,7 @@ gfc_get_array_descr_info (const_tree typ dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); rank_off = byte_position (field); - if (!integer_zerop (dtype_off)) + if (!integer_zerop (rank_off)) t = fold_build_pointer_plus (t, rank_off); t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t);