Whamcloud - gitweb
LU-251 Fix gcc configure warnings
authorNed A. Bass <bass6@llnl.gov>
Thu, 21 Apr 2011 23:45:43 +0000 (16:45 -0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 9 May 2012 16:39:15 +0000 (12:39 -0400)
Newer versions of gcc are getting smart enough to detect the sloppy
syntax used for the autoconf tests.  It is now generating warnings for
unused or uninitialized variables.  Newer versions of gcc even have the
-Wunused-but-set-variable option set by default.  This isn't a problem
except when -Werror is set and they get promoted to an error.  In this
case the autoconf test will return an incorrect result which will result
in a build failure or runtime error later on.

To handle this I'm tightening up many of the autoconf tests to
explicitly mark variables as unused to suppress the gcc warning.  Tests
emitting uninitialized variable errors are updated to initialize
pointers to NULL, and some variables are converted to pointers to
accomodate this.  'Argument makes integer from pointer without a cast'
errors were fixed by passing 0 for the offending argument in cases where
we are not explicitly testing the argument type.  0 is accepted as both
an integer and a pointer.

Change-Id: Idaa04b04308e3cd994b0d802a5ee1eb5c90f9be6
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-on: http://review.whamcloud.com/478
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/autoconf/lustre-libcfs.m4
lnet/autoconf/lustre-lnet.m4
lustre/autoconf/lustre-core.m4

index be9a858..b4b89d0 100644 (file)
@@ -101,7 +101,8 @@ AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
 LB_LINUX_TRY_COMPILE([
         #include <linux/slab.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/slab.h>
 ],[
-       int i = kmem_cache_destroy(NULL);
+       int i __attribute__ ((unused));
+       i = kmem_cache_destroy(NULL);
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
@@ -118,7 +119,7 @@ AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
 LB_LINUX_TRY_COMPILE([
        #include <linux/workqueue.h>
 ],[
 LB_LINUX_TRY_COMPILE([
        #include <linux/workqueue.h>
 ],[
-       struct work_struct work;
+       struct work_struct work __attribute__ ((unused));
 
        INIT_WORK(&work, NULL, NULL);
 ],[
 
        INIT_WORK(&work, NULL, NULL);
 ],[
@@ -137,7 +138,7 @@ AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
 LB_LINUX_TRY_COMPILE([
         #include <linux/sysctl.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/sysctl.h>
 ],[
-       return register_sysctl_table(NULL,0);
+       register_sysctl_table(NULL,0);
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
@@ -220,7 +221,8 @@ AC_DEFUN([LIBCFS_NETWORK_NAMESPACE],
 LB_LINUX_TRY_COMPILE([
         #include <net/net_namespace.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <net/net_namespace.h>
 ],[
-        struct net *net = &init_net;
+        struct net *net __attribute__ ((unused));
+        net = &init_net;
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_INIT_NET, 1,
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_INIT_NET, 1,
@@ -310,8 +312,8 @@ AC_DEFUN([LIBCFS_SEM_COUNT],
 LB_LINUX_TRY_COMPILE([
         #include <asm/semaphore.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <asm/semaphore.h>
 ],[
-       struct semaphore s;
-       
+       struct semaphore s __attribute__ ((unused));
+
        atomic_read(&s.count);
 ],[
         AC_MSG_RESULT(yes)
        atomic_read(&s.count);
 ],[
         AC_MSG_RESULT(yes)
@@ -413,7 +415,8 @@ AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK],
 LB_LINUX_TRY_COMPILE([
         #include <linux/compat.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/compat.h>
 ],[
-        int i = is_compat_task();
+        int i __attribute__ ((unused));
+        i = is_compat_task();
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
index 3ac6dab..3966bcf 100644 (file)
@@ -418,12 +418,12 @@ else
                        #include <rdma/ib_verbs.h>
                        #include <rdma/ib_fmr_pool.h>
                ],[
                        #include <rdma/ib_verbs.h>
                        #include <rdma/ib_fmr_pool.h>
                ],[
-                       struct rdma_cm_id          *cm_id;
-                       struct rdma_conn_param      conn_param;
-                       struct ib_device_attr       device_attr;
-                       struct ib_qp_attr           qp_attr;
-                       struct ib_pool_fmr          pool_fmr;
-                       enum   ib_cm_rej_reason     rej_reason;
+                       struct rdma_cm_id      *cm_idi __attribute__ ((unused));
+                       struct rdma_conn_param  conn_param __attribute__ ((unused));
+                       struct ib_device_attr   device_attr __attribute__ ((unused));
+                       struct ib_qp_attr       qp_attr __attribute__ ((unused));
+                       struct ib_pool_fmr      pool_fmr __attribute__ ((unused));
+                       enum   ib_cm_rej_reason rej_reason __attribute__ ((unused));
 
                        rdma_destroy_id(NULL);
                ],[
 
                        rdma_destroy_id(NULL);
                ],[
@@ -551,7 +551,7 @@ LB_LINUX_TRY_COMPILE([
         size_t *lenp = NULL;
         loff_t *ppos = NULL;
 
         size_t *lenp = NULL;
         loff_t *ppos = NULL;
 
-        proc_handler *proc_handler;
+        proc_handler *proc_handler = NULL;
         proc_handler(table, write, buffer, lenp, ppos);
 
 ],[
         proc_handler(table, write, buffer, lenp, ppos);
 
 ],[
index 838f37e..38d3fa0 100644 (file)
@@ -494,17 +494,16 @@ LB_LINUX_TRY_COMPILE([
 #
 # kernel 2.6.13+ ->follow_link returns a cookie
 #
 #
 # kernel 2.6.13+ ->follow_link returns a cookie
 #
-
 AC_DEFUN([LC_COOKIE_FOLLOW_LINK],
 [AC_MSG_CHECKING([if inode_operations->follow_link returns a cookie])
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
         #include <linux/namei.h>
 ],[
 AC_DEFUN([LC_COOKIE_FOLLOW_LINK],
 [AC_MSG_CHECKING([if inode_operations->follow_link returns a cookie])
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
         #include <linux/namei.h>
 ],[
-        struct dentry dentry;
+        struct dentry *dentry = NULL;
         struct nameidata nd;
 
         struct nameidata nd;
 
-        dentry.d_inode->i_op->put_link(&dentry, &nd, NULL);
+        dentry->d_inode->i_op->put_link(dentry, &nd, NULL);
 ],[
         AC_DEFINE(HAVE_COOKIE_FOLLOW_LINK, 1, [inode_operations->follow_link returns a cookie])
         AC_MSG_RESULT([yes])
 ],[
         AC_DEFINE(HAVE_COOKIE_FOLLOW_LINK, 1, [inode_operations->follow_link returns a cookie])
         AC_MSG_RESULT([yes])
@@ -586,9 +585,9 @@ AC_DEFUN([LC_S_TIME_GRAN],
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
-       struct super_block sb;
+        struct super_block *sb = NULL;
 
 
-        return sb.s_time_gran;
+        return sb->s_time_gran;
 ],[
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_S_TIME_GRAN, 1, [super block has s_time_gran member])
 ],[
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_S_TIME_GRAN, 1, [super block has s_time_gran member])
@@ -664,12 +663,9 @@ AC_DEFUN([LC_SECURITY_PLUG],
 [AC_MSG_CHECKING([If kernel has security plug support])
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 [AC_MSG_CHECKING([If kernel has security plug support])
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
+        #include <linux/stddef.h>
 ],[
 ],[
-        struct dentry   *dentry;
-        struct vfsmount *mnt;
-        struct iattr    *iattr;
-
-        notify_change(dentry, mnt, iattr);
+        notify_change(NULL, NULL, NULL);
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_SECURITY_PLUG, 1,
 ],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_SECURITY_PLUG, 1,
@@ -802,7 +798,7 @@ LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
         struct file_operations *fops = NULL;
         #include <linux/fs.h>
 ],[
         struct file_operations *fops = NULL;
-        fl_owner_t id;
+        fl_owner_t id = NULL;
         int i;
 
         i = fops->flush(NULL, id);
         int i;
 
         i = fops->flush(NULL, id);
@@ -1058,7 +1054,7 @@ LB_LINUX_TRY_COMPILE([
         #include <linux/err.h>
         #include <linux/crypto.h>
 ],[
         #include <linux/err.h>
         #include <linux/crypto.h>
 ],[
-        struct hash_desc foo;
+        struct hash_desc foo __attribute__ ((unused));
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_STRUCT_HASH_DESC, 1, [kernel has struct hash_desc])
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_STRUCT_HASH_DESC, 1, [kernel has struct hash_desc])
@@ -1076,7 +1072,7 @@ LB_LINUX_TRY_COMPILE([
         #include <linux/err.h>
         #include <linux/crypto.h>
 ],[
         #include <linux/err.h>
         #include <linux/crypto.h>
 ],[
-        struct blkcipher_desc foo;
+        struct blkcipher_desc foo __attribute__ ((unused));
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_STRUCT_BLKCIPHER_DESC, 1, [kernel has struct blkcipher_desc])
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_STRUCT_BLKCIPHER_DESC, 1, [kernel has struct blkcipher_desc])
@@ -1093,7 +1089,8 @@ AC_DEFUN([LC_FS_RENAME_DOES_D_MOVE],
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
-        int v = FS_RENAME_DOES_D_MOVE;
+        int v __attribute__ ((unused));
+        v = FS_RENAME_DOES_D_MOVE;
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_FS_RENAME_DOES_D_MOVE, 1, [kernel has FS_RENAME_DOES_D_MOVE flag])
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_FS_RENAME_DOES_D_MOVE, 1, [kernel has FS_RENAME_DOES_D_MOVE flag])
@@ -1110,7 +1107,8 @@ AC_DEFUN([LC_UNREGISTER_BLKDEV_RETURN_INT],
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
-        int i = unregister_blkdev(0,NULL);
+        int i __attribute__ ((unused));
+        i = unregister_blkdev(0,NULL);
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_UNREGISTER_BLKDEV_RETURN_INT, 1,
 ],[
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_UNREGISTER_BLKDEV_RETURN_INT, 1,
@@ -1337,7 +1335,9 @@ AC_DEFUN([LC_INODE_PERMISION_2ARGS],
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
 LB_LINUX_TRY_COMPILE([
         #include <linux/fs.h>
 ],[
-        struct inode *inode;
+        struct inode *inode __attribute__ ((unused));
+
+        inode = NULL;
         inode->i_op->permission(NULL, 0);
 ],[
         AC_DEFINE(HAVE_INODE_PERMISION_2ARGS, 1,
         inode->i_op->permission(NULL, 0);
 ],[
         AC_DEFINE(HAVE_INODE_PERMISION_2ARGS, 1,
@@ -1411,9 +1411,10 @@ AC_DEFINE(HAVE_EXPORT_INODE_PERMISSION, 1,
 AC_DEFUN([LC_QUOTA_ON_5ARGS],
 [AC_MSG_CHECKING([quota_on needs 5 parameters])
 LB_LINUX_TRY_COMPILE([
 AC_DEFUN([LC_QUOTA_ON_5ARGS],
 [AC_MSG_CHECKING([quota_on needs 5 parameters])
 LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
         #include <linux/quota.h>
 ],[
         #include <linux/quota.h>
 ],[
-        struct quotactl_ops *qop;
+        struct quotactl_ops *qop = NULL;
         qop->quota_on(NULL, 0, 0, NULL, 0);
 ],[
         AC_DEFINE(HAVE_QUOTA_ON_5ARGS, 1,
         qop->quota_on(NULL, 0, 0, NULL, 0);
 ],[
         AC_DEFINE(HAVE_QUOTA_ON_5ARGS, 1,
@@ -1428,9 +1429,10 @@ LB_LINUX_TRY_COMPILE([
 AC_DEFUN([LC_QUOTA_OFF_3ARGS],
 [AC_MSG_CHECKING([quota_off needs 3 parameters])
 LB_LINUX_TRY_COMPILE([
 AC_DEFUN([LC_QUOTA_OFF_3ARGS],
 [AC_MSG_CHECKING([quota_off needs 3 parameters])
 LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
         #include <linux/quota.h>
 ],[
         #include <linux/quota.h>
 ],[
-        struct quotactl_ops *qop;
+        struct quotactl_ops *qop = NULL;
         qop->quota_off(NULL, 0, 0);
 ],[
         AC_DEFINE(HAVE_QUOTA_OFF_3ARGS, 1,
         qop->quota_off(NULL, 0, 0);
 ],[
         AC_DEFINE(HAVE_QUOTA_OFF_3ARGS, 1,