On 10/8/25 1:13 PM, Kevin Traynor wrote:
> On 08/10/2025 10:34, Ilya Maximets wrote:
>> The attribute was added in GCC 4.9.  Older versions complain:
>>
>>   lib/util.h:164:1:
>>     warning: 'returns_nonnull' attribute directive ignored [-Wattributes]
>>      OVS_RETURNS_NONNULL void *xmalloc(size_t) MALLOC_LIKE;
>>      ^
>>
>> Fixes: ed738eca39ef ("util: Annotate function that will never return NULL.")
>> Reported-at: 
>> https://mail.openvswitch.org/pipermail/ovs-discuss/2025-September/053800.html
>> Reported-by: Brendan Doyle <[email protected]>
>> Signed-off-by: Ilya Maximets <[email protected]>
>> ---
>>  include/openvswitch/compiler.h | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h
>> index ecb91801c..bd30369a7 100644
>> --- a/include/openvswitch/compiler.h
>> +++ b/include/openvswitch/compiler.h
>> @@ -26,6 +26,9 @@
>>  #ifndef __has_extension
>>    #define __has_extension(x) 0
>>  #endif
>> +#ifndef __has_attribute
>> +  #define __has_attribute(x) 0
>> +#endif
>>  
>>  /* To make OVS_NO_RETURN portable across gcc/clang and MSVC, it should be
>>   * added at the beginning of the function declaration. */
>> @@ -37,7 +40,10 @@
>>  #define OVS_NO_RETURN
>>  #endif
>>  
>> -#if __GNUC__ && !__CHECKER__
>> +#ifdef __CHECKER__
>> +#define OVS_RETURNS_NONNULL
>> +#elif ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) \
>> +        || __has_attribute(returns_nonnull))
>>  #define OVS_RETURNS_NONNULL __attribute__((returns_nonnull))
>>  #else
>>  #define OVS_RETURNS_NONNULL
> 
> nit: you could combine to only have one empty #define, but it might be
> more readable as is anyway, so

Yeah, I split the condition on purpose, it's a bit too complex otherwise.

> 
> Acked-by: Kevin Traynor <[email protected]>

Thanks, Kevin and Eelco!

Applied and backported down to 3.3.

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to