From patchwork Mon Oct 25 14:45:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 46618 Return-Path: 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 83F833858420 for ; Mon, 25 Oct 2021 14:46:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83F833858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635173171; bh=wsqg/bmvDmz+pREigl4MJgbZc7g8Gmp4hwcDljG7xuA=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AD9pVvXdNacAsR0VTPYI37LAzSpEumAQFOmvNlP5b3E90NLJ/z9fCt5I3I/SX9vzJ eLV5HQLOgrsxuycgd9JWlH01iIgJdLmWSUAT1m0s5uXqGS5ScUz/cSTEExPVyCLXGX 5OQB76TmDkyxwd4qSzn6Vb9T+/2LayeLRxzwjFig= 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 ESMTPS id 26CB03858001 for ; Mon, 25 Oct 2021 14:45:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 26CB03858001 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-mKvrKqqJO7qcCeHjvZ3HVg-1; Mon, 25 Oct 2021 10:45:28 -0400 X-MC-Unique: mKvrKqqJO7qcCeHjvZ3HVg-1 Received: by mail-qv1-f69.google.com with SMTP id c15-20020a0cd60f000000b0038509b60a93so3794308qvj.20 for ; Mon, 25 Oct 2021 07:45:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=wsqg/bmvDmz+pREigl4MJgbZc7g8Gmp4hwcDljG7xuA=; b=x8MHHK3E2I3k9Avm2aGiXZLBikYZrC6NdbDbSrujxMc3jdmxi9HSZzqcEGzPE6TdiG g6eX69KOd1VqerixBsPz5TG+IvKAx9VAu2f6fDauALqkR9cexi2HS50k4Ns9T+ElcMyA 5ns0Frd72Fim43wI0N9JncWjGIybLcK8jbt6PiwlirBuDOE64j86d3MuP5gRqd/P+jvc vc2LyVWZutGX2qtbuWBdnkKw+QhsngOmOcBgWSApTqWZg4DJFHhxPIRNNAq+PwGYDowC OahirpGjVOVpU9EjIkNBwgE8JWev9eWG/9qU5VEhEoNClDzr35+mvuOJmZqAbjIXMxEq a4Uw== X-Gm-Message-State: AOAM530s0hdwizkQugSSiriz4PrdrMJGlz3t8UXpQayGmP27TKZYfVc+ 7UhFCu38fLQhpLGt6k5mhmQ1TKy3OSHksYjIyh6LVDuaaABoYrMUjYV2iMK1tbxeeON6Rvc8Ddu P86j/YLTk3DZgI+LUV4Paz0nRxY7eMDr6o0kUjSXCKrpUIUSdf/BFGpDVyL3AcGYBcEN/KA== X-Received: by 2002:a05:620a:1a28:: with SMTP id bk40mr13905668qkb.224.1635173127302; Mon, 25 Oct 2021 07:45:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZqVrHSpVbWFw8wlQpDuaFHoaxD58iFQXRNyxYYHCXiRwocVjQIQfvJRXapj0d9BoRiG/bMg== X-Received: by 2002:a05:620a:1a28:: with SMTP id bk40mr13905639qkb.224.1635173126961; Mon, 25 Oct 2021 07:45:26 -0700 (PDT) Received: from [192.168.0.102] ([192.24.49.122]) by smtp.gmail.com with ESMTPSA id s17sm8258300qtw.95.2021.10.25.07.45.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Oct 2021 07:45:26 -0700 (PDT) Subject: [COMMITTED] Re: [PATCH] Possible use before def in fortran/trans-decl.c. To: gcc-patches References: Message-ID: Date: Mon, 25 Oct 2021 10:45:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On 10/21/21 3:02 PM, Andrew MacLeod wrote: > As I'm tweaking installing ranger as the VRP2 pass, I am getting a > stage 2 bootstrap failure now: > > In file included from > /opt/notnfs/amacleod/master/gcc/gcc/fortran/trans-decl.c:28: > /opt/notnfs/amacleod/master/gcc/gcc/tree.h: In function ‘void > gfc_conv_cfi_to_gfc(stmtblock_t*, stmtblock_t*, tree, tree, > gfc_symbol*)’: > /opt/notnfs/amacleod/master/gcc/gcc/tree.h:244:56: error: ‘rank’ may > be used uninitialized in this function [-Werror=maybe-uninitialized] >   244 | #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code) >       | ^~~~ > /opt/notnfs/amacleod/master/gcc/gcc/fortran/trans-decl.c:6671:8: note: > ‘rank’ was declared here >  6671 |   tree rank, idx, etype, tmp, tmp2, size_var = NULL_TREE; >       |        ^~~~ > cc1plus: all warnings being treated as errors > make[3]: *** [Makefile:1136: fortran/trans-decl.o] Error 1 > > > looking at that function, in the middle I see: > >   if (sym->as->rank < 0) >     { >       /* Set gfc->dtype.rank, if assumed-rank.  */ >       rank = gfc_get_cfi_desc_rank (cfi); >       gfc_add_modify (&block, gfc_conv_descriptor_rank (gfc_desc), rank); >     } >   else if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (gfc_desc))) >     /* In that case, the CFI rank and the declared rank can differ.  */ >     rank = gfc_get_cfi_desc_rank (cfi); >   else >     rank = build_int_cst (signed_char_type_node, sym->as->rank); > > > so rank is set on all paths here.   However, stepping back a bit, > earlier in the function I see: > >   if (!sym->attr.dimension || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE > (gfc_desc))) >     { >       tmp = gfc_get_cfi_desc_base_addr (cfi); >       gfc_add_modify (&block, gfc_desc, >                       fold_convert (TREE_TYPE (gfc_desc), tmp)); >       if (!sym->attr.dimension) >         goto done; >     } > > The done: label occurs *after* that block of initialization code, and > bit furtehr down , I see this: > >           gfc_add_modify (&loop_body, tmpidx, idx); >           stmtblock_t inner_loop; >           gfc_init_block (&inner_loop); >           tree dim = gfc_create_var (TREE_TYPE (rank), "dim"); > > I cannot convince myself by looking at the intervening code that this > can not be executed along this path.  Perhaps someone more familiar > with the code can check it out.   However, It seems worthwhile to at > least initialize rank to NULL_TREE, thus we can be more likely to see > a trap if that path ever gets followed. > > And it makes the warning go away :-) > > OK? > > Andrew > > PS as a side note, it would be handy to have the def point *and* the > use point that might be undefined.   Its a big function and it took me > a while just to see where a possible use might be. > > > > Bootstraps onx86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 387c665392366a543fb29badaee329533b32abb3 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 21 Oct 2021 14:48:20 -0400 Subject: [PATCH 3/3] Initialize variable. gcc/fortran/ * trans-decl.c (gfc_conv_cfi_to_gfc): Initialize rank to NULL_TREE. --- gcc/fortran/trans-decl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index de624c82fcf..fe5511b5285 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -6668,7 +6668,7 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t *finally, stmtblock_t block; gfc_init_block (&block); tree cfi = build_fold_indirect_ref_loc (input_location, cfi_desc); - tree rank, idx, etype, tmp, tmp2, size_var = NULL_TREE; + tree idx, etype, tmp, tmp2, size_var = NULL_TREE, rank = NULL_TREE; bool do_copy_inout = false; /* When allocatable + intent out, free the cfi descriptor. */ -- 2.17.2