[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] xen: Use auto as per C23


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 15 Aug 2025 11:36:09 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, "consulting @ bugseng . com" <consulting@xxxxxxxxxxx>
  • Delivery-date: Fri, 15 Aug 2025 09:36:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 15.08.2025 10:33, Nicola Vetrini wrote:
> On 2025-08-15 10:17, Andrew Cooper wrote:
>> On 15/08/2025 8:20 am, Nicola Vetrini wrote:
>>> On 2025-08-15 00:25, Andrew Cooper wrote:
>>>> In macros it is common to declare local variables using typeof(param)
>>>> in order
>>>> to ensure that side effects are only evaluated once.  A consequence
>>>> of this is
>>>> double textural expansion of the parameter, which can get out of hand
>>>> very
>>>> quickly with nested macros.
>>>>
>>>> In C23, the auto keyword has been repurposed to perform type 
>>>> inference.
>>>>
>>>> A GCC extension, __auto_type, is now avaialble in the new toolchain
>>>> baseline
>>>> and avoids the double textural expansion.
>>>>
>>>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>>
>>> Reviewed-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
>>
>> Thankyou.
>>
>>>>
>>>> diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
>>>> index 88bf26bc5109..38ef5d82ad95 100644
>>>> --- a/xen/include/xen/compiler.h
>>>> +++ b/xen/include/xen/compiler.h
>>>> @@ -64,6 +64,20 @@
>>>>  # define asm_inline asm
>>>>  #endif
>>>>
>>>> +/*
>>>> + * In C23, the auto keyword has been repurposed to perform type
>>>> inference.
>>>> + *
>>>> + * This behaviour is available via the __auto_type extension in
>>>> supported
>>>> + * toolchains.
>>>> + *
>>>> + *
>>>> https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Auto-Type.html
>>>> + * https://clang.llvm.org/docs/LanguageExtensions.html#auto-type
>>>> + */
>>>> +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
>>>> +/* SAF-3-safe MISRA C Rule 20.4: Giving the keyword it's C23
>>>> meaning. */
>>>> +#define auto __auto_type
>>>> +#endif
>>>> +
>>>
>>> A more detailed explanation should live in deviations.rst under this
>>> bullet point
>>>
>>>    * - R20.4
>>>      - The override of the keyword \"inline\" in xen/compiler.h is
>>> present so
>>>        that section contents checks pass when the compiler chooses not 
>>> to
>>>        inline a particular function.
>>>      - Comment-based deviation.
>>>
>>> as described in the SAF entry:
>>>
>>>         {
>>>             "id": "SAF-3-safe",
>>>             "analyser": {
>>>                 "eclair": "MC3A2.R20.4"
>>>             },
>>>             "name": "MC3A2.R20.4: allow the definition of a macro with
>>> the same name as a keyword in some special cases",
>>>             "text": "The definition of a macro with the same name as a
>>> keyword can be useful in certain configurations to improve the
>>> guarantees that can be provided by Xen. See docs/misra/deviations.rst
>>> for a precise rationale for all such cases."
>>>         },
>>
>> Ah right.  What about this:
>>
>> "Xen does not use the \"auto\" keyword as a storage qualifier.  The
>> override of the keyword \"auto\" in xen/compiler.h is to give it it's
>> C23 behaviour of type inference."
>>
>> ?
> 
> Seems good to me. Maybe this should be spelled out in ./CODING_STYLE as 
> well, so that newcomers don't trip over this?

I'm not sure newcomers would look there, but in the absence of any better
place that's perhaps indeed where to mention this.

I am, however, still not quite sure if we're doing ourselves a favor with
the re-purposing of auto (while not using C23 in general). It'll certainly
hit me as unexpected, for some time, to see uses of the keyword. It simply
has been for too long that it had its earlier meaning (of very limited use).

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.