From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 F416B3858C83 for ; Tue, 15 Feb 2022 21:40:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F416B3858C83 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-KDjSM3C6NCOB99-s-Oyctg-1; Tue, 15 Feb 2022 16:40:21 -0500 X-MC-Unique: KDjSM3C6NCOB99-s-Oyctg-1 Received: by mail-qt1-f200.google.com with SMTP id a6-20020ac844a6000000b002cf3968d32aso122069qto.1 for ; Tue, 15 Feb 2022 13:40:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=U78jb/mM0sRHTnjfRdVW0XD5nJBId9YcdlpyGQ0DFCU=; b=F/BUSzHIVlEJbyKVxh9GgF2ZDJYEWY12Ay9Vyr69iIrQ55QF+y92hrWZJSYC4NgNti Il3Q/TnUE1dI5JjOaYRY4xZvnK+LUZ6+yc/uMJ4QbTr7fdTHpfJjm1Xl4oA3y6GMWqsI fFVqOPPo2m68HaKQRyYWRop/dHtTFU1+cbxw8x6gFaQiKLkr1tgb8yCXP/J2T/jHYkdS fJTBsmga1cuHYwdovQk2cq1qLsLzFk+zOFmh8Y7JXacT0DlDCgvGYJAvpx3/yQ2NgGKu yDETWyKouZVDYoL6MvvLvtcxblgUkyBXp+1x4eSKR1ztGPx1vCEia6LlKvzeGyXQO+MS PB/g== X-Gm-Message-State: AOAM531lQtuiwefTgXcx5naHljQLjpR3arhgMkYkhaa6NiaCr1VZF/1N kZmrIaaPuFKQX/39naCNDRlyAvtz9yQJT5rOtPerU0eHsg3H+qySmcpnXhpvJ2XuqcHZHGwe/Ib b7cTVffs= X-Received: by 2002:a05:6214:27e2:: with SMTP id jt2mr855763qvb.45.1644961220836; Tue, 15 Feb 2022 13:40:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRhz+3O+DltqwKLYJ6x9Zzaql890s0LVcAopOaB1C/3jG/MllrfXl2UGQgyTBmAWCfBOY85Q== X-Received: by 2002:a05:6214:27e2:: with SMTP id jt2mr855755qvb.45.1644961220550; Tue, 15 Feb 2022 13:40:20 -0800 (PST) Received: from t14s.localdomain (c-73-69-212-193.hsd1.ma.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id g11sm18422836qko.58.2022.02.15.13.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 13:40:19 -0800 (PST) Message-ID: <821e3f32fbe23e6eed134f9d7c93be6a47657150.camel@redhat.com> Subject: Re: Uninit warnings due to optimizing short-circuit conditionals From: David Malcolm To: Richard Biener , Julian Seward Cc: Mark Wielaard , GCC Development Date: Tue, 15 Feb 2022 16:40:18 -0500 In-Reply-To: References: <20220214155757.861877-1-dmalcolm@redhat.com> <71de3204e639eed5052ca9e6416334aba6b2d1c7.camel@klomp.org> <3bfbfbf02e2d17d45b4a91e5ea5f855e0a62e5f5.camel@klomp.org> User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Feb 2022 21:40:25 -0000 On Tue, 2022-02-15 at 14:28 +0100, Richard Biener wrote: > On Tue, Feb 15, 2022 at 2:00 PM Julian Seward > wrote: > > > > Sorry for the delayed response.  I've been paging this all back in. > > > > I first saw this problem when memcheck-ing Firefox as compiled by > > Clang, some > > years back.  Not long after GCC was also at it.  The transformation > > in > > question is (at the C level): > > > > A && B  ==>  B && A   if it can be proved that A > >                       is always false whenever B is undefined > >                       and (I assume) that B is provably exception- > > free > > > > where && means the standard lazy left-first C logical-AND.  I > > believe this > > might have become more prevalent due to ever-more aggressive > > inlining (at > > least for Firefox), which presented the compilers with greater > > opportunities > > to make the required proofs. > > Note GCC doesn't try to prove this, instead it reasons that when > B is undefined it takes an indeterminate value and if A is _not_ > always > false then the program would have invoked undefined behavior, so we > can disregard this possibility and assume B is not undefined.  So > either B is not undefined and everything is OK, or B is undefined but > then A must be always false. > > Note that when A is always false we may have transformed a valid > program (does not access B) into a program invoking undefined > behavior > (in C language terms).  We don't treat undefined uses as "very" > undefined > behavior but I do remember we've shot ourselves in the foot with this > transform - in this case we'd have to make the use of B determinate > somehow, something we cannot yet do.  So we'd want a transform > like > >  A && B ==> OK(B) && A > > where 'OK' sanitizes B in case it is undefined.  The error we can run > into > is that two of the uninit Bs can be equated to two different values, > breaking the B == B invariant (technically also OK, but not if it was > us > that introduced the undefinedness in the first place). > > Richard. Thanks everyone for the various insights. I've gone ahead and committed my workaround for the -fanalyzer uninit false positive to trunk (as r12-7251- g1e2fe6715a949f80c1204ae244baad3cd80ffaf0). Dave