[parted-devel] [PATCH 05/24] libparted: Avoid warnings from GCC 8 -Wsuggest-attribute=pure
Brian C. Lane
bcl at redhat.com
Sat Nov 14 00:11:48 GMT 2020
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()
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.
GCC documentation on -Wsuggest-attribute=pure[1] notes about the
functions do not return normally. However, it's interpretation caused
confusions and discussed in GCC bugzilla[2] and Stack Overflow[3].
[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wsuggest-attribute_003d-462
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971
[3] https://stackoverflow.com/questions/41712635
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.
Signed-off-by: Shin'ichiro Kawasaki <kawasaki at juno.dti.ne.jp>
Signed-off-by: Brian C. Lane <bcl at redhat.com>
---
libparted/fs/r/fat/calc.c | 6 ++++++
libparted/fs/r/fat/clstdup.c | 5 +++++
libparted/fs/r/fat/table.c | 5 +++++
libparted/fs/r/hfs/cache.c | 5 +++++
4 files changed, 21 insertions(+)
diff --git a/libparted/fs/r/fat/calc.c b/libparted/fs/r/fat/calc.c
index e524007..7432a04 100644
--- a/libparted/fs/r/fat/calc.c
+++ b/libparted/fs/r/fat/calc.c
@@ -369,6 +369,9 @@ fat_is_sector_in_clusters (const PedFileSystem* fs, PedSector sector)
+ fs_info->cluster_sectors * fs_info->cluster_count;
}
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+
FatFragment
fat_cluster_to_frag (const PedFileSystem* fs, FatCluster cluster)
{
@@ -430,4 +433,7 @@ fat_sector_to_cluster (const PedFileSystem* fs, PedSector sector)
return (sector - fs_info->cluster_offset) / fs_info->cluster_sectors
+ 2;
}
+
+# pragma GCC diagnostic pop
+
#endif /* !DISCOVER_ONLY */
diff --git a/libparted/fs/r/fat/clstdup.c b/libparted/fs/r/fat/clstdup.c
index 7456f60..d71e7e1 100644
--- a/libparted/fs/r/fat/clstdup.c
+++ b/libparted/fs/r/fat/clstdup.c
@@ -124,6 +124,9 @@ fetch_fragments (FatOpContext* ctx)
* ctx->buffer_map [last] are occupied by fragments that need to be duplicated.
*****************************************************************************/
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+
/* finds the first fragment that is not going to get overwritten (that needs to
get read in) */
static FatFragment
@@ -166,6 +169,8 @@ get_last_underlay (const FatOpContext* ctx, int first, int last)
return -1;
}
+# pragma GCC diagnostic pop
+
/* "underlay" refers to the "static" fragments, that remain unchanged.
* when writing large chunks at a time, we don't want to clobber these,
* so we read them in, and write them back again. MUCH quicker that way.
diff --git a/libparted/fs/r/fat/table.c b/libparted/fs/r/fat/table.c
index fe8e040..d19aa3a 100644
--- a/libparted/fs/r/fat/table.c
+++ b/libparted/fs/r/fat/table.c
@@ -291,6 +291,9 @@ fat_table_set (FatTable* ft, FatCluster cluster, FatCluster value)
return 1;
}
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+
FatCluster
fat_table_get (const FatTable* ft, FatCluster cluster)
{
@@ -320,6 +323,8 @@ fat_table_get (const FatTable* ft, FatCluster cluster)
return 0;
}
+# pragma GCC diagnostic pop
+
FatCluster
fat_table_alloc_cluster (FatTable* ft)
{
diff --git a/libparted/fs/r/hfs/cache.c b/libparted/fs/r/hfs/cache.c
index 5e5b071..e15053b 100644
--- a/libparted/fs/r/hfs/cache.c
+++ b/libparted/fs/r/hfs/cache.c
@@ -173,6 +173,9 @@ hfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length,
return ext;
}
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+
HfsCPrivateExtent*
hfsc_cache_search_extent(HfsCPrivateCache* cache, uint32_t start)
{
@@ -188,6 +191,8 @@ hfsc_cache_search_extent(HfsCPrivateCache* cache, uint32_t start)
return ret;
}
+# pragma GCC diagnostic pop
+
/* Can't fail if extent begining at old_start exists */
/* Returns 0 if no such extent, or on error */
HfsCPrivateExtent*
--
2.26.2
More information about the parted-devel
mailing list