From nobody Wed Aug 26 17:23:21 2026 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hVWhF40Hvz6qNm9; Wed, 26 Aug 2026 17:23:25 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hVWhF1dMRz3syJ; Wed, 26 Aug 2026 17:23:25 +0000 (UTC) (envelope-from glebius@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787765005; 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: in-reply-to:in-reply-to:references:references; bh=s/bXL/mHYK6WmEkijNMEo0RjYXJgy189gEjh0z8zyiE=; b=p6922v1+wrIKMvUf1xkMw3+kWOlzXttNUKOTEe0CFgbVP8Gj+YyJi6uwapD3BuZSMS1s2f VcvfwlvIq0aS1vwpl577Dq55xRUv+z77W+dsn26EBwk9AdP7h/O7PnRrSipwboL0nAsoMY 7TKWnxN8UrsP539kzv5tNtsHJG3GbavozNMyS1icoZBjxkBYF4Q8d6VbtHBqxTwXtWpOqw LJC61OGPQCGUWaRelvJw0J/EnC/vb3wf3F+mmtVouxji7EUGma7n/GIJBQJZ5TKQZsgVU2 gm48BWFFPZI8/FFlEdo5UQnKm42atUATaFMd53gF1I1GVQ33buaiUm7CJFmrYA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787765005; a=rsa-sha256; cv=none; b=wLbwHVS7zLmN+WD9vF5es/21U49fGj9HYakYHE2ZDKCYqBgnL9sZ5AuJ4JCDYZuSPyvbyA iU+atgN2AG3S/raGDO2MrvYKNd/8HwhhiUFRpeE/DpnmDGvGq1B3Z9a/vKy1fEY7m68VDb qgd08zGns/FhY43v30xcDg3uvmnDloH96Na/lr0Pj9NFANIjVuxtVrL/MFBzUbwZKeVr2y Cm1RHnHSjarXrvizIclqvmA9bJ9wXa4Rnm2xYwt+s9PsuOMG2cl7++A5VbI4C5JOpdjVvP XMd2yJU2d5tnrDzwrrVeCehZgLCtxYMNJ0OCFiUtDvHLUey/0p9AkqyEfsiS/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787765005; 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: in-reply-to:in-reply-to:references:references; bh=s/bXL/mHYK6WmEkijNMEo0RjYXJgy189gEjh0z8zyiE=; b=eUHBLjoL+xO1F6Hc8lgpjqksu60j3VWDAEEqGRP/Jy4IJdvJjta9IYbp166aa/1NkJFIdg f8RurfzB2Q+FYamB66/BVEJiWQHHnAZMTnNq93WFCrwGZObhqldteN0/44U3HGH6oNxHoD A894Jtwb7vM1W9IerXmKoHKO6Q3u3BZi2CkMhlNpkfvLepsjXSYzBMWhZZDY/0v2IOQ91D dSRIOrA3bolHus9N9ajh2yEDYyUkW0xxQEQDMeRc5+InI90sp/3cTFIwE+Btc8xAyTABPR BRKynl1UOl4a3vYIYEv0F7hkiylDbbw77VH22Z81ExClozk5pLMPEYfdHM8Sqg== Received: from cell.glebi.us (glebi.us [162.251.186.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: glebius) by smtp.freebsd.org (Postfix) with ESMTPSA id 4hVWhD2RlZzQQm; Wed, 26 Aug 2026 17:23:24 +0000 (UTC) (envelope-from glebius@freebsd.org) Date: Wed, 26 Aug 2026 10:23:21 -0700 From: Gleb Smirnoff To: John Baldwin Cc: current@freebsd.org, hackers@freebsd.org Subject: Re: enabling -Werror=assign-enum for kernel Message-ID: References: <0e34f0c6-b41a-49d3-9c41-3ec84ea2e0be@FreeBSD.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0e34f0c6-b41a-49d3-9c41-3ec84ea2e0be@FreeBSD.org> John, On Wed, Aug 26, 2026 at 01:15:27PM -0400, John Baldwin wrote: J> > J> Note that C++ doesn't allow this at the language level. When I converted ctld to J> > J> C++ I had to adjust some enums to be simple #define's instead in the ctl headers. J> > J> > Noted. I can't make a judgement if it is a smart restriction by C++ or not. J> > In our case using enums as flags is common and handy and Werror=assign-enum in J> > combination with __attribute__((flag_enum)) will make this use fortified J> > against mistakes. J> J> Mostly my point is that over time we may be forced to convert away from enums to J> plain constants if more of the base system starts using C++ anyway. At least for J> enums exposed to userspace. But if C++ doesn't allow flag enums in principle, then they just can't go into userspace headers, no matter how we compile the kernel. Basically we already are there, and enabling Werror=assign-enum for kernel won't change anything, will it? J> > Question: what is our policy of adding attributes into code? The convetion is J> > that compilers warn and don't fail on unknown attributes, so adding them as J> > bare words definitely works. I personally prefer to avoid use of preprocessor J> > when it is possible, so I'm for adding the __attribute__((flag_enum)) as is. J> > However, few people who compile with gcc may be unhappy about lots of warnings. J> > The best practice to shut these warning is: J> > J> > #ifndef __flag_enum J> > #ifdef __clang__ J> > #define __flag_enum __attribute__((flag_enum)) J> > #else J> > #define __flag_enum J> > #endif J> > #endif J> > J> > This would require us use FreeBSD-specific keyword in the code. Which one is J> > the preferred way to move forward? J> J> Normally we define a new wrapper in so that the only #ifdef's are in J> that header, and the rest of the code uses the wrapper macro unconditionally. So your answer is that I need to add the above to and rewrite my branch to use a defined keyword instead of __attribute__((flag_enum))? What would be the keyword? __flag_enum or any other spelling? J> > J> > This seems like a nice enforcement of a good code. I already found a few J> > J> > hamrless bugs with it and one in e1000 that could be a real bug. It also J> > J> > highlights some sketchy code that better be refactored. J> > J> > J> > J> > I have a branch where LINT is compilable with -Werror=assign-enum: J> > J> > J> > J> > https://github.com/freebsd/freebsd-src/compare/main...glebius:FreeBSD:Werror%3Dassign-enum J> > J> > J> > J> > There are basically three parts that require work: J> > J> > J> > J> > 1) The most common violators are SYSINIT(9)s that use (SI_SUB_FOO + 1) as J> > J> > argument. I have posted a pack of reviews to cover that. J> > J> J> > J> So I think this is probably sensible for SI_SUB_* to define new values. I J> > J> worry about SI_ORDER_*. Possibly we should use plain #define's for SI_ORDER_* J> > J> instead of an enum if we aren't already. I wonder if you ran into any cases J> > J> where we use an SI_ORDER_* value that is an expression? J> > J> > Nope. Everything in SYSINIT(9) that was violating Werror=assign-enum is J> > already in main, except ipfw. One bit left is ipfw's sysinits, which I left J> > for later, since I wanted more changes to it. J> > J> > I don't agree we should use plain #define for SI_ORDER_*. The current code J> > combined with Werror=assign-enum will enforce intentionality and thoughtfulness J> > when adding new sysinits. Would prevent quick adhoc additions in the "works J> > for me" style. J> J> At some point 'SI_ORDER_' isn't really more readable than J> just using an integer. In particular for offsets relative to SI_ORDER_FIRST. J> Today we probably don't have more than SI_ORDER_THIRD, but something like J> SI_ORDER_FOUR_HUNDRED_FIFTY_SEVENTH would be a mouthful compared to J> 'SI_ORDER_FIRST + 456'. For SI_SUB_* the names are generally descriptive of J> some subsystem, but SI_ORDER are inherently a range of explicitly numbered values J> along with a few special cases such as SI_ORDER_ANY/LAST. The special cases J> make sense as names. The numeric range makes less sense as names. However, if J> we all fit fine today with just SI_ORDER_THIRD then it's probably ok. I worried J> we might have a broader range than just FIRST/SECOND/THIRD. So far we are good with FIRST/SECOND/THIRD. IMHO, if we really really want to improve SYSINIT substantially, not just fix daily problems, we should unironically use rcorder(8) as kernel compilation tool. -- Gleb Smirnoff