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 264D53858D1E for ; Thu, 18 Aug 2022 12:21:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 264D53858D1E Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-318-o8uGHh58O4i_qoufCGoeLg-1; Thu, 18 Aug 2022 08:21:55 -0400 X-MC-Unique: o8uGHh58O4i_qoufCGoeLg-1 Received: by mail-wm1-f70.google.com with SMTP id c64-20020a1c3543000000b003a61987ffb3so878575wma.6 for ; Thu, 18 Aug 2022 05:21:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc; bh=5NEaioO2Uw6yvwIpLhE5dmdEk5cmdTg0Srl0DsKMLw0=; b=7eaGU7wm9mLUX7pIa707OvUSkLWwsmw9U9Utqw6iMdFYOP+GfltzC9hSNd1BtC01gN JmuHvhHUMW00Ma6E0U28adEy31jLOiGFy/sdyIVdPv+fLnGc4rydpiN9pqlZRh5gmO+/ sLEZluMhYJb9bXzkQqVRatNnmoz4oAaV+QMm3TEXiukW+eymsQqCZI+57x5sTFq3hLrJ a4o3sjU1WXCwEdciUsy0Y07rWQB6o4/fhpRM6B9LQD1eR+MG+dsjvzSGB/AMdDkeAW1/ TrG8LY0wOE4AAEtDrai7bFn+W7kCuyUqLjVBlmxev6ekr1boyQ6OXQGuZmBugYUcecZ4 le1A== X-Gm-Message-State: ACgBeo0kjogQTCi5BOa25Pqip1rVKYZR3XJ/gt1RxuK2Un8zBqxTx2ps NdJCCBCbqdr6M4JauNBfDQinBOmTfbGxPjEnZ5/1Z7xkWYCeJLrD9OBR+kISCCEC7oDro4BqoJU wz7HELvB91MkR2pM1+Q== X-Received: by 2002:a05:600c:3556:b0:3a6:220e:6242 with SMTP id i22-20020a05600c355600b003a6220e6242mr2185671wmq.145.1660825314662; Thu, 18 Aug 2022 05:21:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XgJQzrRdtLFr7G7ngTLZLNEOocuzhJs2t4Szu1G8ziXz4UcnTdtym83i1af/HPlQ7rSXzVA== X-Received: by 2002:a05:600c:3556:b0:3a6:220e:6242 with SMTP id i22-20020a05600c355600b003a6220e6242mr2185658wmq.145.1660825314385; Thu, 18 Aug 2022 05:21:54 -0700 (PDT) Received: from t14s.localdomain ([86.111.173.6]) by smtp.gmail.com with ESMTPSA id p3-20020a05600c358300b003a607e395ebsm6835796wmq.9.2022.08.18.05.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 05:21:53 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2] analyzer: warn on the use of floating-points operands in the size argument [PR106181] From: David Malcolm To: Tim Lange , gcc-patches@gcc.gnu.org Date: Thu, 18 Aug 2022 13:21:52 +0100 In-Reply-To: <20220818094414.19488-1-mail@tim-lange.me> References: <20220815123525.49172-1-mail@tim-lange.me> <20220818094414.19488-1-mail@tim-lange.me> User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 12:22:02 -0000 On Thu, 2022-08-18 at 11:44 +0200, Tim Lange wrote: > Hi, >=20 > this is the revised version of my patch. I had trouble to get your > point regarding the float_visitor: >=20 > > If the constant is seen first, then the non-constant won't be > > favored > > (though perhaps binary ops get canonicalized so that constants are > > on > > the RHS?). >=20 > Only the assignment of m_result in visit_constant_svalue is guarded > by > =C2=A0!m_result, while the other two are not. So, there are two > possibilities: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A01. A constant is seen fir= st and then assigned to m_result. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A01.1. A non-constant float operand is seen later and > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 overwrites m_result. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A01.2. There's no non-constant float operand, thus th= e > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 constant is the actual flo= ating-point operand > and > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 is kept inside m_result. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A02. A non-constant is seen= first, then m_result might be > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 overwritten = with another non-constant later but never > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 with a const= ant. > Do I have a flaw in my thinking? (But they do seem to get > canonicalized, > so that shouldn't matter) I think I was confused here, and that you're right. Sorry about that. >=20 > > How about: > > =C2=A0-Wanalyzer-imprecise-float-arithmetic > > =C2=A0-Wanalyzer-imprecise-fp-arithmetic > > instead?=C2=A0 (ideas welcome) >=20 > I've chosen the second. I mostly tried to avoid float because it is > also > a reserved keyword in many languages and I wanted to avoid confusion > (might be overthinking that). Fair enough. >=20 > - Tim >=20 > This patch fixes the ICE reported in PR106181 and adds a new warning > to > the analyzer complaining about the use of floating-point operands. >=20 > Regrtested on Linux x86_64. Thanks; the patch looks good for trunk. Dave