[parted-devel] [PATCH 05/24] libparted: Avoid warnings from GCC 8 -Wsuggest-attribute=pure

Shin-ichiro KAWASAKI kawasaki at juno.dti.ne.jp
Sat Nov 21 00:50:52 GMT 2020


On 2020-11-21 07:22, Brian C. Lane wrote:
> On Mon, Nov 16, 2020 at 03:39:58PM -0500, Phillip Susi wrote:
>>
>> Brian C. Lane writes:
>>
>>> From: Shin'ichiro Kawasaki <kawasaki at juno.dti.ne.jp>
>>>
>>> GCC 8 suggests to add 'pure' attribute to a number of functions but the
>>> warnings might be false positive. The suggested functions have PED_ASSERT
>>> macro which may call abort() function. One of the functions
>>> fat_table_get() calls exit() function also. Once abort() or exit()
>>
>> If that is true then we need to remove that exit() call.  As a library,
>> libparted should not be calling exit().
> 
> I think we should wait until after this release. It's buried down in the
> fat resize code and appears to be there because it doesn't have a good
> way to indicate an error. It may require a change to the public API in
> order to clean it up.
> 
>>
>>> called, the program execution stops. It is controversial if the functions
>>> are pure or not, and consequence of compiler optimization with the pure
>>> attribute is not explicit.
>>
>> Doesn't "pure" mean that it does not modify any variables with static
>> storage duration, so the caller can assume that any variables it has
>> already loaded into registers that are preserved across the call do not
>> need to be reloaded?  If so, then it should be perfectly safe to assume
>> that abort() or exit() are pure.
> 
> I agree, the functions all only depend on what's passed to them for
> their return value and the assert decision so behavior should be exactly
> the same.

Okay, this discussion clarifies what is expected to the pure functions with 
assertions.

I confirmed Brian already added the pure attributes to the function in the 
branch. Thank you!

--
Best Regards,
Shin'ichiro Kawasaki

> 
>>> With this unclear situation, I suggest not to add _GL_ATTRIBUTE_PURE to
>>> the functions. Instead, I suggest to avoid the warning message using GCC
>>> pragma 'diagnostic ignored' pragma, which disables specific GCC warnings
>>> only for target functions.
>>
>> The pragma needs protected so that it is only used with gcc and not if
>> you are using a different compiler that does not understand that pragma.
> 
> I dropped that patch and added pure to those functions so that no longer
> matters.
> 
> Is anyone using llvm (or something else) to build parted? And is that
> something that we really want to encourage? Seems simpler if we just say
> 'use gcc'.
> 
> Brian
> 




More information about the parted-devel mailing list