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

Phillip Susi phill at thesusis.net
Mon Nov 16 20:39:58 GMT 2020


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().

> 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.

> 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.




More information about the parted-devel mailing list