Whamcloud - gitweb
Fix compile error and warnings for old gcc versions
authorLi Dongyang <dongyangli@ddn.com>
Sat, 14 Jul 2018 00:42:48 +0000 (18:42 -0600)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 15 Jul 2018 00:46:30 +0000 (20:46 -0400)
-Wimplicit-fallthrough option was added in gcc7 and
-Wpedantic was added in gcc4.8, while #pragma GCC diagnostic
support was not available until gcc4.6

We got following warnings:
../lib/ext2fs/fiemap.h:35: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
../lib/ext2fs/fiemap.h:36: warning: unknown option after ‘#pragma GCC diagnostic’ kind
../lib/ext2fs/fiemap.h:38: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’

and error:
filefrag.c: In function ‘main’:
filefrag.c:577: error: #pragma GCC diagnostic not allowed inside functions
filefrag.c:578: error: #pragma GCC diagnostic not allowed inside functions
filefrag.c:595: error: #pragma GCC diagnostic not allowed inside functions

when compiling latest e2fsprogs with a gcc older than 4.6
e.g. on CentOS 6.9

Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/set_fields.c
e2fsck/problem.c
lib/ext2fs/ext4_acl.h
lib/ext2fs/fiemap.h
lib/ext2fs/hashmap.h
lib/ext2fs/mmp.c
lib/ext2fs/unix_io.c
lib/uuid/gen_uuid.c
misc/e2undo.c
misc/filefrag.c
misc/fuse2fs.c

index 6594906..e1e23a5 100644 (file)
@@ -75,8 +75,10 @@ static errcode_t parse_gd_csum(struct field_set_info *info, char *field, char *a
 static errcode_t parse_mmp_clear(struct field_set_info *info, char *field,
                                 char *arg);
 
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
 
 static struct field_set_info super_fields[] = {
        { "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
@@ -289,7 +291,9 @@ static struct field_set_info mmp_fields[] = {
        { "checksum", &set_mmp.mmp_checksum, NULL, 4, parse_uint },
        { 0, 0, 0, 0 }
 };
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic pop
+#endif
 
 #ifdef UNITTEST
 
index a0a3cfe..47321e0 100644 (file)
@@ -99,8 +99,10 @@ static const char *preen_msg[] = {
        "",                     /* 20 */
 };
 
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
 
 static struct e2fsck_problem problem_table[] = {
 
@@ -2086,7 +2088,9 @@ static struct latch_descr pr_latch_info[] = {
        { PR_LATCH_OPTIMIZE_EXT, PR_1E_OPTIMIZE_EXT_HEADER, PR_1E_OPTIMIZE_EXT_END },
        { -1, 0, 0 },
 };
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic pop
+#endif
 
 static struct e2fsck_problem *find_problem(problem_t code)
 {
index 1f5245d..8d4d974 100644 (file)
@@ -50,9 +50,13 @@ typedef struct {
 
 typedef struct {
         __le32                  a_version;
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
         posix_acl_xattr_entry   a_entries[0];
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic pop
+#endif
 } posix_acl_xattr_header;
 
index 5c851b2..0d1072a 100644 (file)
@@ -31,10 +31,14 @@ struct fiemap {
        __u32 fm_mapped_extents;/* number of extents that were mapped (out) */
        __u32 fm_extent_count;  /* size of fm_extents array (in) */
        __u32 fm_reserved;
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
        struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic pop
+#endif
 };
 
 #if defined(__linux__) && !defined(FS_IOC_FIEMAP)
index be1e8a7..228f439 100644 (file)
@@ -17,10 +17,14 @@ struct ext2fs_hashmap {
                struct ext2fs_hashmap_entry *next;
                struct ext2fs_hashmap_entry *list_next;
                struct ext2fs_hashmap_entry *list_prev;
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
        } *entries[0];
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic pop
+#endif
 };
 
 struct ext2fs_hashmap *ext2fs_hashmap_create(
index 0cf0d0d..2da935e 100644 (file)
 #define O_DIRECT 0
 #endif
 
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #ifndef CONFIG_MMP
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 #endif
+#endif
 
 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 {
@@ -465,4 +467,6 @@ mmp_error:
        return EXT2_ET_OP_NOT_SUPPORTED;
 #endif
 }
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic pop
+#endif
index 18a2e5f..7a4c9bf 100644 (file)
@@ -1127,8 +1127,10 @@ unimplemented:
 }
 
 /* parameters might not be used if OS doesn't support zeroout */
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
 static errcode_t unix_zeroout(io_channel channel, unsigned long long block,
                              unsigned long long count)
 {
@@ -1195,7 +1197,9 @@ err:
 unimplemented:
        return EXT2_ET_UNIMPLEMENTED;
 }
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic pop
+#endif
 
 static struct struct_io_manager struct_unix_manager = {
        .magic          = EXT2_ET_MAGIC_IO_MANAGER,
index 43ecc8a..0198363 100644 (file)
@@ -484,10 +484,12 @@ static void close_all_fds(void)
 }
 #endif /* defined(USE_UUIDD) && defined(HAVE_SYS_UN_H) */
 
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #if !defined(USE_UUIDD) || !defined(HAVE_SYS_UN_H)
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 #endif
+#endif
 /*
  * Try using the uuidd daemon to generate the UUID
  *
@@ -570,7 +572,9 @@ fail:
 #endif
        return -1;
 }
+#if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic pop
+#endif
 
 void uuid__generate_time(uuid_t out, int *num)
 {
index 0593738..71991e0 100644 (file)
@@ -81,10 +81,14 @@ struct undo_key_block {
        __le32 magic;           /* KEYBLOCK_MAGIC number */
        __le32 crc;             /* block checksum */
        __le64 reserved;        /* zero */
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
        struct undo_key keys[0];        /* keys, which come immediately after */
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic pop
+#endif
 };
 
 struct undo_key_info {
index 7f1c5bf..56f84ed 100644 (file)
@@ -535,8 +535,10 @@ int main(int argc, char**argv)
                                char *end;
                                blocksize = strtoul(optarg, &end, 0);
                                if (end) {
+#if __GNUC_PREREQ (7, 0)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
                                        switch (end[0]) {
                                        case 'g':
                                        case 'G':
@@ -553,7 +555,9 @@ int main(int argc, char**argv)
                                        default:
                                                break;
                                        }
+#if __GNUC_PREREQ (7, 0)
 #pragma GCC diagnostic pop
+#endif
                                }
                        } else { /* Allow -b without argument for compat. Remove
                                  * this eventually so "-b {blocksize}" works */
index 056d34e..5c73895 100644 (file)
@@ -118,10 +118,14 @@ typedef struct {
 
 typedef struct {
        u_int32_t       a_version;
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
        acl_ea_entry    a_entries[0];
+#if __GNUC_PREREQ (4, 8)
 #pragma GCC diagnostic pop
+#endif
 } acl_ea_header;
 
 static inline size_t acl_ea_size(int count)