Message ID | 20221031114520.10518-1-jirislaby@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2262991wru; Mon, 31 Oct 2022 04:48:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QuW7O7/QdgHWKKBDs4l+1FzPpdE3XbDLBnm5wsB0YzF4EO/dnY2qnU6sVo/eHKTctn6we X-Received: by 2002:a17:907:968b:b0:78d:f5c2:70d8 with SMTP id hd11-20020a170907968b00b0078df5c270d8mr12163193ejc.564.1667216888223; Mon, 31 Oct 2022 04:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667216888; cv=none; d=google.com; s=arc-20160816; b=lMCcXXJ+8befmW/fLuaKen8leOTgPaBSAFmifa3T5ScxT+QdEGjnkiWKsGj2JJvrQk r+HSq5ws8xQmAv1w4r80ff4mon5VeXCRp88N6fwsJ1ylr7Ov/PP9JlikMrdEx650jePO 8ERouE43+jHAvgLAgnR9O3eUSX9TfZjsZgP5EynX+K5Kac+Ps99k6QEVMUm3fQNrM3F/ z0cjANMiH4NQ9M4s6m9/zFZbuzSRZfakQw8r6vvaiYIPULxgo9V63dwumci01jKazxi+ h7NmiayjYwEeWAaEKb/+EOhoaAPvNVBv1qGeyw5KX3/b1U+tDLiVHNVEWukSI3w1Nh1O 1sbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0iKJXqoHSlwS8vEZQq8a9M+jZZbmGeDzJGf+xlQtrOE=; b=Q88pMmfPRE1HGD0IlFNJ8azs+D8ledCJR5Ktjwhq7hoTl8sPCsUuuVKs93tKB5Mm8n 2xkDiM1Y7niR4nCdKmI2kKPnyu/creoXlpnEgRZaCY24wK/zlRnpQK5V7EcfDmETI19L q5EIgtqrnnjxHgUsS6AGFqJ1X0ocMRZy4FTfAflSnS0eDly/nOgNhUQSzvHsyb+sMmXT hqbfe1J2W2PNFJ0V/Cv5V7AswQIJxsz7+b1tkXHECedfN5aWE2ePKuRLm9r2z0oM6nkJ Xfa+EOEJc69ZehO0oOafI+hISvSniYF8kf1nP9ycIXSnZWU1hAuQFsBxdQsJ/OIFEV7h nEFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=di1R1BCG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a50eb0c000000b00461ebe2a168si6704877edp.447.2022.10.31.04.47.44; Mon, 31 Oct 2022 04:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=di1R1BCG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbiJaLqC (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Mon, 31 Oct 2022 07:46:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231204AbiJaLpk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Oct 2022 07:45:40 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD1CF023; Mon, 31 Oct 2022 04:45:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id AE1A0CE134C; Mon, 31 Oct 2022 11:45:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09213C433D6; Mon, 31 Oct 2022 11:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667216723; bh=/nzQwQ7t8fEd/Xbji8T5TlBeyziGmIQJxHg8N9W/ml4=; h=From:To:Cc:Subject:Date:From; b=di1R1BCGvDv5KIfYWJ/0WhYLVQzNM99ivj4PXRekT4VkQArg598dXS6df8fUPt/qy PL7JlHCF5TrQNlt3ISUO9gHqjDWWpnPw59eVNi+FnE3fdzrdJwgelZYr/afK5L3XED 1pzWTJ7nkI2/uAXIJxOcL0Dav5rcI9YuEo0A+RLi4JgST/jFmnjJP01UiUjrVDVT+P mVRYq+GU/7y1c+/YSLmuUlnkBzD0IB9LQH5DMOAhzOis2HHkm43zRFeUMhdJMxH5ST yhcLFqhAA7VpSOeTeuObjthPMQHzBdvW3rwzZFb8ml+x7C9qatEeJXaez50ykda6cH q+lcUjCfNPo/g== From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org> To: tj@kernel.org Cc: linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" <jirislaby@kernel.org>, Martin Liska <mliska@suse.cz>, Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>, cgroups@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH] block/blk-iocost (gcc13): cast enum members to int in prints Date: Mon, 31 Oct 2022 12:45:20 +0100 Message-Id: <20221031114520.10518-1-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748203615672295278?= X-GMAIL-MSGID: =?utf-8?q?1748203615672295278?= |
Series |
block/blk-iocost (gcc13): cast enum members to int in prints
|
|
Commit Message
Jiri Slaby
Oct. 31, 2022, 11:45 a.m. UTC
Since gcc13, each member of an enum has the same type as the enum [1]. And
that is inherited from its members. Provided:
VTIME_PER_SEC_SHIFT = 37,
VTIME_PER_SEC = 1LLU << VTIME_PER_SEC_SHIFT,
the named type is unsigned long.
This generates warnings with gcc-13:
block/blk-iocost.c: In function 'ioc_weight_prfill':
block/blk-iocost.c:3037:37: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int'
block/blk-iocost.c: In function 'ioc_weight_show':
block/blk-iocost.c:3047:34: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int'
Cast the enum members to int when printing them.
Alternatively, we can cast them to ulong (to silence gcc < 12) and use %lu.
Alternatively, we can move VTIME_PER_SEC away from the enum.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36113
Cc: Martin Liska <mliska@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: cgroups@vger.kernel.org
Cc: linux-block@vger.kernel.org
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
block/blk-iocost.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On Mon, Oct 31, 2022 at 12:45:20PM +0100, Jiri Slaby (SUSE) wrote: > Cast the enum members to int when printing them. > > Alternatively, we can cast them to ulong (to silence gcc < 12) and use %lu. > Alternatively, we can move VTIME_PER_SEC away from the enum. Yes, either split the enum or just use a define. But casts are a big code smell and should be avoided if there is a reasonable alternative.
On Mon, Oct 31, 2022 at 05:24:28AM -0700, Christoph Hellwig wrote: > On Mon, Oct 31, 2022 at 12:45:20PM +0100, Jiri Slaby (SUSE) wrote: > > Cast the enum members to int when printing them. > > > > Alternatively, we can cast them to ulong (to silence gcc < 12) and use %lu. > > Alternatively, we can move VTIME_PER_SEC away from the enum. > > Yes, either split the enum or just use a define. But casts are a big > code smell and should be avoided if there is a reasonable alternative. enums are so much better for debugging and other instrumentation stuff. The only requirement for the enum types is that they're big enough to express all the members and we can use whatever printf format letter which matches the type in use. The problem here is that the compiler behavior is different depending on the compiler version, which kinda sucks. I suppose the most reasonable thing to do here is just splitting them into separate enum definitions. Does anyone know how this behavior change came to be? Do we know whether clang is gonna be changed the same way? Thanks.
On 31. 10. 22, 18:57, Tejun Heo wrote: > On Mon, Oct 31, 2022 at 05:24:28AM -0700, Christoph Hellwig wrote: >> On Mon, Oct 31, 2022 at 12:45:20PM +0100, Jiri Slaby (SUSE) wrote: >>> Cast the enum members to int when printing them. >>> >>> Alternatively, we can cast them to ulong (to silence gcc < 12) and use %lu. >>> Alternatively, we can move VTIME_PER_SEC away from the enum. >> >> Yes, either split the enum or just use a define. But casts are a big >> code smell and should be avoided if there is a reasonable alternative. > > enums are so much better for debugging and other instrumentation stuff. The > only requirement for the enum types is that they're big enough to express > all the members and we can use whatever printf format letter which matches > the type in use. The problem here is that the compiler behavior is different > depending on the compiler version, which kinda sucks. Yes. The real problem is that using anything else then an INT_MIN <= x <= INT_MAX _constant_ in an enum is undefined in ANSI C < 2x (in particular, 1 << x is undefined too). gcc manual defines unsigned int on the top of that as defined too (so this holds for our -std=g*). > I suppose the most reasonable thing to do here is just splitting them into > separate enum definitions. Does anyone know how this behavior change came to > be? C2x which introduces un/signed long enums. See the bug I linked in the commit log: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36113 The change is also turned on in < C2x on purpose. AIUI, unless there is too much breakage. So we'd need to sort it out in (rather distant) future anyway (when we come up to -std=g2x). > Do we know whether clang is gonna be changed the same way? In C2x, Likely. In < C2x, dunno what'd be the default. thanks,
Hello, On Tue, Nov 01, 2022 at 06:46:56AM +0100, Jiri Slaby wrote: > Yes. The real problem is that using anything else then an INT_MIN <= x <= > INT_MAX _constant_ in an enum is undefined in ANSI C < 2x (in particular, 1 > << x is undefined too). gcc manual defines unsigned int on the top of that > as defined too (so this holds for our -std=g*). > > > I suppose the most reasonable thing to do here is just splitting them into > > separate enum definitions. Does anyone know how this behavior change came to > > be? > > C2x which introduces un/signed long enums. See the bug I linked in the > commit log: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36113 I see. So, it was an extension but the new standard is defined differently and we're gonna end up with that behavior. > The change is also turned on in < C2x on purpose. AIUI, unless there is too > much breakage. So we'd need to sort it out in (rather distant) future anyway > (when we come up to -std=g2x). The part that the new behavior applying to <C2x feels like an odd decision. I'm having a hard time seeing the upsides in doing so but maybe that's just me not knowing the area well enough. > > Do we know whether clang is gonna be changed the same way? > > In C2x, Likely. In < C2x, dunno what'd be the default. It looks like we can do one of the following two: * If gcc actually changes the behavior for <c2x, split the enums according to their sizes. This feels rather silly but I can't think of a better way to cater to divergent compiler behaviors. * If gcc doesn't change the behavior for <c2x, there's nothing to do for the time being. Later when we switch to -std=g2x, we can just change the format strings to use the now larger types. Does the above make sense? Thanks.
From: Tejun Heo > Sent: 01 November 2022 16:47 > > Hello, > > On Tue, Nov 01, 2022 at 06:46:56AM +0100, Jiri Slaby wrote: > > Yes. The real problem is that using anything else then an INT_MIN <= x <= > > INT_MAX _constant_ in an enum is undefined in ANSI C < 2x (in particular, 1 > > << x is undefined too). gcc manual defines unsigned int on the top of that > > as defined too (so this holds for our -std=g*). > > > > > I suppose the most reasonable thing to do here is just splitting them into > > > separate enum definitions. Does anyone know how this behavior change came to > > > be? > > > > C2x which introduces un/signed long enums. See the bug I linked in the > > commit log: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36113 > > I see. So, it was an extension but the new standard is defined differently > and we're gonna end up with that behavior. > > > The change is also turned on in < C2x on purpose. AIUI, unless there is too > > much breakage. So we'd need to sort it out in (rather distant) future anyway > > (when we come up to -std=g2x). > > The part that the new behavior applying to <C2x feels like an odd decision. > I'm having a hard time seeing the upsides in doing so but maybe that's just > me not knowing the area well enough. > > > > Do we know whether clang is gonna be changed the same way? > > > > In C2x, Likely. In < C2x, dunno what'd be the default. > > It looks like we can do one of the following two: > > * If gcc actually changes the behavior for <c2x, split the enums according > to their sizes. This feels rather silly but I can't think of a better way > to cater to divergent compiler behaviors. > > * If gcc doesn't change the behavior for <c2x, there's nothing to do for the > time being. Later when we switch to -std=g2x, we can just change the > format strings to use the now larger types. > > Does the above make sense? I think the enums have to be split. There will be other side effects of promoting the constants to 64bit that are much more difficult to detect than the warnings from printf. I'm also not sure whether the type is even consistent for 32bit and 64bit builds. Casts are (sort of) horrid. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Wed, Nov 02, 2022 at 08:35:34AM +0000, David Laight wrote: > I think the enums have to be split. > There will be other side effects of promoting the constants to 64bit > that are much more difficult to detect than the warnings from printf. idk, I think I can just add LLU to everything and it should be fine. > I'm also not sure whether the type is even consistent for 32bit > and 64bit builds. > Casts are (sort of) horrid. Yeah, I don't think casts are the solution either. Lemme add LLU to everything and see how it works. Thanks.
On Wed, Nov 02, 2022 at 06:27:46AM -1000, 'Tejun Heo' wrote: > On Wed, Nov 02, 2022 at 08:35:34AM +0000, David Laight wrote: > > I think the enums have to be split. > > There will be other side effects of promoting the constants to 64bit > > that are much more difficult to detect than the warnings from printf. > > idk, I think I can just add LLU to everything and it should be fine. > > > I'm also not sure whether the type is even consistent for 32bit > > and 64bit builds. > > Casts are (sort of) horrid. > > Yeah, I don't think casts are the solution either. Lemme add LLU to > everything and see how it works. So adding LLU to initializers don't make the specific enum's type follow suit. I guess type determination is really based on the value range. Oh man, what a mess. If we end up having to split the enum defs, that's what we'll do but this doesn't sense to me. It's one thing to make one time adjustment when we adopt -std=g2x. That's fine, but it makes no sense for the compiler to change type behavior underneath existing code bases in a way that prevents the same code to mean the same thing in adjacent and recent compiler versions. Even if gcc goes for that for whatever reason, there gotta be an option to keep the original behavior, right? If so, my suggestion is just sticking with the old behavior until we switch to --std=g2x and then make one time adjustment at that point. Thanks.
On 02. 11. 22, 17:43, 'Tejun Heo' wrote: > On Wed, Nov 02, 2022 at 06:27:46AM -1000, 'Tejun Heo' wrote: >> On Wed, Nov 02, 2022 at 08:35:34AM +0000, David Laight wrote: >>> I think the enums have to be split. >>> There will be other side effects of promoting the constants to 64bit >>> that are much more difficult to detect than the warnings from printf. >> >> idk, I think I can just add LLU to everything and it should be fine. >> >>> I'm also not sure whether the type is even consistent for 32bit >>> and 64bit builds. >>> Casts are (sort of) horrid. >> >> Yeah, I don't think casts are the solution either. Lemme add LLU to >> everything and see how it works. > > So adding LLU to initializers don't make the specific enum's type follow > suit. I guess type determination is really based on the value range. Oh man, > what a mess. > > If we end up having to split the enum defs, that's what we'll do but this > doesn't sense to me. It's one thing to make one time adjustment when we > adopt -std=g2x. That's fine, but it makes no sense for the compiler to > change type behavior underneath existing code bases in a way that prevents > the same code to mean the same thing in adjacent and recent compiler > versions. Even if gcc goes for that for whatever reason, there gotta be an > option to keep the original behavior, right? Unfortunately not, see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107405#c8 (linked also from the commit log). We'd use such an option if there were one. > If so, my suggestion is just sticking with the old behavior until we switch > to --std=g2x and then make one time adjustment at that point. So is the enum split OK under these circumstances? thanks,
On Mon, Dec 12, 2022 at 01:14:31PM +0100, Jiri Slaby wrote: > > If so, my suggestion is just sticking with the old behavior until we switch > > to --std=g2x and then make one time adjustment at that point. > > So is the enum split OK under these circumstances? Oh man, it's kinda crazy that the compiler is changing in a way that the same piece of code can't be compiled the same way across two adjoining versions of the same compiler. But, yeah, if that's what gcc is gonna do and splitting enums is the only way to be okay across the compiler versions, there isn't any other choice we can make. Thanks.
From: Tejun Heo <htejun@gmail.com> On Behalf Of 'Tejun Heo' > Sent: 12 December 2022 21:47 > To: Jiri Slaby <jirislaby@kernel.org> > Cc: David Laight <David.Laight@ACULAB.COM>; Christoph Hellwig <hch@infradead.org>; linux- > kernel@vger.kernel.org; Martin Liska <mliska@suse.cz>; Josef Bacik <josef@toxicpanda.com>; Jens Axboe > <axboe@kernel.dk>; cgroups@vger.kernel.org; linux-block@vger.kernel.org > Subject: Re: [PATCH] block/blk-iocost (gcc13): cast enum members to int in prints > > On Mon, Dec 12, 2022 at 01:14:31PM +0100, Jiri Slaby wrote: > > > If so, my suggestion is just sticking with the old behavior until we switch > > > to --std=g2x and then make one time adjustment at that point. > > > > So is the enum split OK under these circumstances? > > Oh man, it's kinda crazy that the compiler is changing in a way that the > same piece of code can't be compiled the same way across two adjoining > versions of the same compiler. But, yeah, if that's what gcc is gonna do and > splitting enums is the only way to be okay across the compiler versions, > there isn't any other choice we can make. It is also a silent code-breaker. Compile this for 32bit x86: enum { a = 1, b = ~0ull}; extern int foo(int, ...); int f(void) { return foo(0, a, 2); } gcc13 pushes an extra zero onto the stack between the 1 and 2. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On 13. 12. 22, 9:30, David Laight wrote: > From: Tejun Heo <htejun@gmail.com> On Behalf Of 'Tejun Heo' >> Sent: 12 December 2022 21:47 >> To: Jiri Slaby <jirislaby@kernel.org> >> Cc: David Laight <David.Laight@ACULAB.COM>; Christoph Hellwig <hch@infradead.org>; linux- >> kernel@vger.kernel.org; Martin Liska <mliska@suse.cz>; Josef Bacik <josef@toxicpanda.com>; Jens Axboe >> <axboe@kernel.dk>; cgroups@vger.kernel.org; linux-block@vger.kernel.org >> Subject: Re: [PATCH] block/blk-iocost (gcc13): cast enum members to int in prints >> >> On Mon, Dec 12, 2022 at 01:14:31PM +0100, Jiri Slaby wrote: >>>> If so, my suggestion is just sticking with the old behavior until we switch >>>> to --std=g2x and then make one time adjustment at that point. >>> >>> So is the enum split OK under these circumstances? >> >> Oh man, it's kinda crazy that the compiler is changing in a way that the >> same piece of code can't be compiled the same way across two adjoining >> versions of the same compiler. But, yeah, if that's what gcc is gonna do and >> splitting enums is the only way to be okay across the compiler versions, >> there isn't any other choice we can make. > > It is also a silent code-breaker. > Compile this for 32bit x86: > > enum { a = 1, b = ~0ull}; But having ull in an enum is undefined anyway. C99 allows only int constants. gnuC supports ulong expressions (IIRC). > extern int foo(int, ...); > int f(void) > { > return foo(0, a, 2); > } > > gcc13 pushes an extra zero onto the stack between the 1 and 2. So this is sort of "expected". thanks,
From: Jiri Slaby > Sent: 13 December 2022 11:15 > > On 13. 12. 22, 9:30, David Laight wrote: > > From: Tejun Heo <htejun@gmail.com> On Behalf Of 'Tejun Heo' > >> Sent: 12 December 2022 21:47 > >> To: Jiri Slaby <jirislaby@kernel.org> > >> Cc: David Laight <David.Laight@ACULAB.COM>; Christoph Hellwig <hch@infradead.org>; linux- > >> kernel@vger.kernel.org; Martin Liska <mliska@suse.cz>; Josef Bacik <josef@toxicpanda.com>; Jens > Axboe > >> <axboe@kernel.dk>; cgroups@vger.kernel.org; linux-block@vger.kernel.org > >> Subject: Re: [PATCH] block/blk-iocost (gcc13): cast enum members to int in prints > >> > >> On Mon, Dec 12, 2022 at 01:14:31PM +0100, Jiri Slaby wrote: > >>>> If so, my suggestion is just sticking with the old behavior until we switch > >>>> to --std=g2x and then make one time adjustment at that point. > >>> > >>> So is the enum split OK under these circumstances? > >> > >> Oh man, it's kinda crazy that the compiler is changing in a way that the > >> same piece of code can't be compiled the same way across two adjoining > >> versions of the same compiler. But, yeah, if that's what gcc is gonna do and > >> splitting enums is the only way to be okay across the compiler versions, > >> there isn't any other choice we can make. > > > > It is also a silent code-breaker. > > Compile this for 32bit x86: > > > > enum { a = 1, b = ~0ull}; > > But having ull in an enum is undefined anyway. C99 allows only int > constants. gnuC supports ulong expressions (IIRC). gcc supports 'long long' as well - 64bit on 32bit systems. In practical terms it really doesn't matter what C99 (or any other version) says, the important thing is that the compiler accepted it. > > extern int foo(int, ...); > > int f(void) > > { > > return foo(0, a, 2); > > } > > > > gcc13 pushes an extra zero onto the stack between the 1 and 2. > > So this is sort of "expected". For some definitions of "expected" :-) Note that it (probably) makes no actual difference to some architectures (like 64bit x86) where all varargs parameters are passed as 64bit. Extending a value to 64bits just makes the high bits well defined. (The high bits of stacked 32bit args are undefined.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On 13. 12. 22, 12:50, David Laight wrote: > From: Jiri Slaby >> Sent: 13 December 2022 11:15 >> >> On 13. 12. 22, 9:30, David Laight wrote: >>> From: Tejun Heo <htejun@gmail.com> On Behalf Of 'Tejun Heo' >>>> Sent: 12 December 2022 21:47 >>>> To: Jiri Slaby <jirislaby@kernel.org> >>>> Cc: David Laight <David.Laight@ACULAB.COM>; Christoph Hellwig <hch@infradead.org>; linux- >>>> kernel@vger.kernel.org; Martin Liska <mliska@suse.cz>; Josef Bacik <josef@toxicpanda.com>; Jens >> Axboe >>>> <axboe@kernel.dk>; cgroups@vger.kernel.org; linux-block@vger.kernel.org >>>> Subject: Re: [PATCH] block/blk-iocost (gcc13): cast enum members to int in prints >>>> >>>> On Mon, Dec 12, 2022 at 01:14:31PM +0100, Jiri Slaby wrote: >>>>>> If so, my suggestion is just sticking with the old behavior until we switch >>>>>> to --std=g2x and then make one time adjustment at that point. >>>>> >>>>> So is the enum split OK under these circumstances? >>>> >>>> Oh man, it's kinda crazy that the compiler is changing in a way that the >>>> same piece of code can't be compiled the same way across two adjoining >>>> versions of the same compiler. But, yeah, if that's what gcc is gonna do and >>>> splitting enums is the only way to be okay across the compiler versions, >>>> there isn't any other choice we can make. >>> >>> It is also a silent code-breaker. >>> Compile this for 32bit x86: >>> >>> enum { a = 1, b = ~0ull}; >> >> But having ull in an enum is undefined anyway. C99 allows only int >> constants. gnuC supports ulong expressions (IIRC). > > gcc supports 'long long' as well - 64bit on 32bit systems. Can you elaborate what's source of this? Gcc manual says this about enum values: The integer type compatible with each enumerated type (C90 6.5.2.2, C99 and C11 6.7.2.2). Normally, the type is unsigned int if there are no negative values in the enumeration, otherwise int. If ‘-fshort-enums’ is specified, ..., otherwise it is the first of unsigned char, unsigned short and unsigned int that can represent all the values. I.e. the documentation says uint is the highest possible enum value. C2x/g2x also supports ulong (that's what it is all about). But we don't do c2x quite yet. thanks,
From: Jiri Slaby <jirislaby@kernel.org> > Sent: 13 December 2022 12:05 > > On 13. 12. 22, 12:50, David Laight wrote: > > From: Jiri Slaby > >> Sent: 13 December 2022 11:15 > >> ... > >>>> Oh man, it's kinda crazy that the compiler is changing in a way that the > >>>> same piece of code can't be compiled the same way across two adjoining > >>>> versions of the same compiler. But, yeah, if that's what gcc is gonna do and > >>>> splitting enums is the only way to be okay across the compiler versions, > >>>> there isn't any other choice we can make. > >>> > >>> It is also a silent code-breaker. > >>> Compile this for 32bit x86: > >>> > >>> enum { a = 1, b = ~0ull}; > >> > >> But having ull in an enum is undefined anyway. C99 allows only int > >> constants. gnuC supports ulong expressions (IIRC). > > > > gcc supports 'long long' as well - 64bit on 32bit systems. > > Can you elaborate what's source of this? ... Experimentation, for example: https://godbolt.org/z/n4rnc7cKG David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c index f01359906c83..a257ba17183b 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3034,7 +3034,8 @@ static u64 ioc_weight_prfill(struct seq_file *sf, struct blkg_policy_data *pd, struct ioc_gq *iocg = pd_to_iocg(pd); if (dname && iocg->cfg_weight) - seq_printf(sf, "%s %u\n", dname, iocg->cfg_weight / WEIGHT_ONE); + seq_printf(sf, "%s %d\n", dname, + iocg->cfg_weight / (int)WEIGHT_ONE); return 0; } @@ -3044,7 +3045,8 @@ static int ioc_weight_show(struct seq_file *sf, void *v) struct blkcg *blkcg = css_to_blkcg(seq_css(sf)); struct ioc_cgrp *iocc = blkcg_to_iocc(blkcg); - seq_printf(sf, "default %u\n", iocc->dfl_weight / WEIGHT_ONE); + seq_printf(sf, "default %d\n", + iocc->dfl_weight / (int)WEIGHT_ONE); blkcg_print_blkgs(sf, blkcg, ioc_weight_prfill, &blkcg_policy_iocost, seq_cft(sf)->private, false); return 0;