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.129.124]) by sourceware.org (Postfix) with ESMTPS id 111D6382F0A5 for ; Tue, 30 Aug 2022 14:56:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 111D6382F0A5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661871381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5cJnln1jn5vno7WUqRJhuapp+M8xDb7cwgwXZr6gyog=; b=U5sGZiI9UkyHAxKP4gdozQriyHZpOPBtYmXWTeOIfeDfwzt1codLGXf4SqVdelUU6VqI3Q cN+ccOv19KIY5GMpjY1jagMB+d4e+J5pCxpmSTc1n3aPlGHWaJiOtX+ioKceBqBqsye2ls XwkJvuZaOXlpc3PwH+fQJnr5t3mmM5Y= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-361-EzKnq-WnP--o43HIv4yAjQ-1; Tue, 30 Aug 2022 10:56:18 -0400 X-MC-Unique: EzKnq-WnP--o43HIv4yAjQ-1 Received: by mail-qv1-f69.google.com with SMTP id a1-20020a0ccdc1000000b00498f818cc40so4996880qvn.8 for ; Tue, 30 Aug 2022 07:56:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc; bh=5cJnln1jn5vno7WUqRJhuapp+M8xDb7cwgwXZr6gyog=; b=l8dp4JJZ5s3vLxaORTs3ZBGJRZldM4bUvNuZFq6bbKb19P2l6PVzeHzNuHCCb0Xbav nCMTLCiWhyLixk4ucbCuPElh/YnIcF3qQFMCiVOmYbEjkSa1MbhJMErou/0wgv4+Gkj3 2i7QmGgWH9u8MD/xOhSvm3Q+lsvjPlM5RwnBH5MIfkmNkVIBM7Yj1vgrHPt/HOMbgDzW aKwWgdtBzuptiptsvQjGiDqv/wXNrc6i4dvpv8kp9xizpjTIBEk6S66rwcXrOjQi5nfi j+Y9E4yzgUAIsE7XIRGFwki3NA29DpdS59+cLZ6YNHbJPq4rd479qDBHWKgv3m+XxeqU rxGw== X-Gm-Message-State: ACgBeo3xryrTc3LKP/RotvwuzyNoiVSNyRmqw9cWejyZmrmxhleEzt0W rL2h89RptVbOYj36eHTZbBWr+ZziMECUXoiFerrCgHU4U1n93z/53lXJqDIJYXLBJDqg26Q5+up ZCGKIWiD+J2UiK/gXMg== X-Received: by 2002:a05:620a:4714:b0:6bb:49e8:e628 with SMTP id bs20-20020a05620a471400b006bb49e8e628mr12472803qkb.455.1661871378036; Tue, 30 Aug 2022 07:56:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR4IFwtoMWbN9loj97SopTher3aAQkbwjjfUns8BuelJVk92q9EQrviSGIDKld+IPUUIIqwhGQ== X-Received: by 2002:a05:620a:4714:b0:6bb:49e8:e628 with SMTP id bs20-20020a05620a471400b006bb49e8e628mr12472786qkb.455.1661871377801; Tue, 30 Aug 2022 07:56:17 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::e531]) by smtp.gmail.com with ESMTPSA id y6-20020a05620a25c600b006b9c355ed75sm8251524qko.70.2022.08.30.07.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 07:56:17 -0700 (PDT) Date: Tue, 30 Aug 2022 10:56:15 -0400 From: Marek Polacek To: Frolov Daniil Cc: gcc-patches@gcc.gnu.org Subject: Re: -Wformat-overflow handling for %b and %B directives in C2X standard Message-ID: References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.6 (2022-06-05) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Aug 15, 2022 at 07:42:39PM +0300, Frolov Daniil wrote: > вт, 12 апр. 2022 г. в 00:56, Marek Polacek : > > > > > On Thu, Apr 07, 2022 at 02:10:48AM +0500, Frolov Daniil wrote: > > > Hello! Thanks for your feedback. I've tried to take into account your > > > comments. New patch applied to the letter. > > > > Thanks. > > > > > The only thing I have not removed is the check_std_c2x () function. From my > > > point of view -Wformat-overflow shouldn't be thrown if the standard < C2X. > > > So it's protection for false triggering. > > > > Sorry but I still think that is the wrong behavior. If you want to warn > > about C2X constructs in pre-C2X modes, use -Wpedantic. But if you want > > to use %b/%B as an extension in older dialects, that's OK too, so I don't > > know why users would want -Wformat-overflow disabled in that case. But > > perhaps other people disagree with me. > > > Hi! Sorry for the late reply. If we want to look at it as on extension > then I am agreed with you. > Removed this function in new patch. Thanks, the patch looks good to me (I have one comment though), but I can't approve it. > @@ -1229,6 +1231,10 @@ format_integer (const directive &dir, tree arg, pointer_query &ptr_qry) > case 'u': > base = 10; > break; > + case 'b': > + case 'B': > + base = 2; > + break; > case 'o': > base = 8; > break; > @@ -1348,13 +1354,12 @@ format_integer (const directive &dir, tree arg, pointer_query &ptr_qry) > } > > res.range.unlikely = res.range.max; > + unsigned adj = (sign | maybebase) + (base == 2 || base == 16); We have this same line here and ... > /* Bump up the counters if WIDTH is greater than LEN. */ > - res.adjust_for_width_or_precision (dir.width, dirtype, base, > - (sign | maybebase) + (base == 16)); > + res.adjust_for_width_or_precision (dir.width, dirtype, base, adj); > /* Bump up the counters again if PRECision is greater still. */ > - res.adjust_for_width_or_precision (dir.prec, dirtype, base, > - (sign | maybebase) + (base == 16)); > + res.adjust_for_width_or_precision (dir.prec, dirtype, base, adj); > > return res; > } > @@ -1503,17 +1508,16 @@ format_integer (const directive &dir, tree arg, pointer_query &ptr_qry) > if (res.range.min == 1) > res.range.likely += base == 8 ? 1 : 2; > else if (res.range.min == 2 > - && base == 16 > + && (base == 16 || base == 2) > && (dir.width[0] == 2 || dir.prec[0] == 2)) > ++res.range.likely; > } > } > > + unsigned adj = (sign | maybebase) + (base == 2 || base == 16); ... here, but sign, maybebase, and base couldn't have changed meanwhile. So can we compute 'adj' just once after we've determined the base and sign, and make it const? And I think that if 'maybebase' is never changed in the function, it ought to be made const as well. Thanks, Marek