From 90f7063bf51b1c8d159a72ae962988e57bf777b5 Mon Sep 17 00:00:00 2001 From: "Ned A. Bass" Date: Thu, 21 Apr 2011 16:45:43 -0700 Subject: [PATCH] LU-251 Fix gcc configure warnings 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 Signed-off-by: Brian Behlendorf Reviewed-on: http://review.whamcloud.com/478 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 17 ++++++++++------- lnet/autoconf/lustre-lnet.m4 | 14 +++++++------- lustre/autoconf/lustre-core.m4 | 38 ++++++++++++++++++++------------------ 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index be9a858..b4b89d0 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -101,7 +101,8 @@ AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT], LB_LINUX_TRY_COMPILE([ #include ],[ - 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, @@ -118,7 +119,7 @@ AC_DEFUN([LIBCFS_3ARGS_INIT_WORK], LB_LINUX_TRY_COMPILE([ #include ],[ - struct work_struct work; + struct work_struct work __attribute__ ((unused)); INIT_WORK(&work, NULL, NULL); ],[ @@ -137,7 +138,7 @@ AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL], LB_LINUX_TRY_COMPILE([ #include ],[ - return register_sysctl_table(NULL,0); + register_sysctl_table(NULL,0); ],[ 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 ],[ - struct net *net = &init_net; + struct net *net __attribute__ ((unused)); + net = &init_net; ],[ AC_MSG_RESULT(yes) AC_DEFINE(HAVE_INIT_NET, 1, @@ -310,8 +312,8 @@ AC_DEFUN([LIBCFS_SEM_COUNT], LB_LINUX_TRY_COMPILE([ #include ],[ - struct semaphore s; - + struct semaphore s __attribute__ ((unused)); + atomic_read(&s.count); ],[ AC_MSG_RESULT(yes) @@ -413,7 +415,8 @@ AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK], LB_LINUX_TRY_COMPILE([ #include ],[ - 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]) diff --git a/lnet/autoconf/lustre-lnet.m4 b/lnet/autoconf/lustre-lnet.m4 index 3ac6dab..3966bcf 100644 --- a/lnet/autoconf/lustre-lnet.m4 +++ b/lnet/autoconf/lustre-lnet.m4 @@ -418,12 +418,12 @@ else #include #include ],[ - 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); ],[ @@ -551,7 +551,7 @@ LB_LINUX_TRY_COMPILE([ size_t *lenp = NULL; loff_t *ppos = NULL; - proc_handler *proc_handler; + proc_handler *proc_handler = NULL; proc_handler(table, write, buffer, lenp, ppos); ],[ diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 838f37e..38d3fa0 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -494,17 +494,16 @@ LB_LINUX_TRY_COMPILE([ # # 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 #include ],[ - struct dentry dentry; + struct dentry *dentry = NULL; 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]) @@ -586,9 +585,9 @@ AC_DEFUN([LC_S_TIME_GRAN], LB_LINUX_TRY_COMPILE([ #include ],[ - 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]) @@ -664,12 +663,9 @@ AC_DEFUN([LC_SECURITY_PLUG], [AC_MSG_CHECKING([If kernel has security plug support]) LB_LINUX_TRY_COMPILE([ #include + #include ],[ - 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, @@ -802,7 +798,7 @@ LB_LINUX_TRY_COMPILE([ #include ],[ struct file_operations *fops = NULL; - fl_owner_t id; + fl_owner_t id = NULL; int i; i = fops->flush(NULL, id); @@ -1058,7 +1054,7 @@ LB_LINUX_TRY_COMPILE([ #include #include ],[ - 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]) @@ -1076,7 +1072,7 @@ LB_LINUX_TRY_COMPILE([ #include #include ],[ - 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]) @@ -1093,7 +1089,8 @@ AC_DEFUN([LC_FS_RENAME_DOES_D_MOVE], LB_LINUX_TRY_COMPILE([ #include ],[ - 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]) @@ -1110,7 +1107,8 @@ AC_DEFUN([LC_UNREGISTER_BLKDEV_RETURN_INT], LB_LINUX_TRY_COMPILE([ #include ],[ - 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, @@ -1337,7 +1335,9 @@ AC_DEFUN([LC_INODE_PERMISION_2ARGS], LB_LINUX_TRY_COMPILE([ #include ],[ - struct inode *inode; + struct inode *inode __attribute__ ((unused)); + + inode = NULL; 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([ + #include #include ],[ - struct quotactl_ops *qop; + struct quotactl_ops *qop = NULL; 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([ + #include #include ],[ - struct quotactl_ops *qop; + struct quotactl_ops *qop = NULL; qop->quota_off(NULL, 0, 0); ],[ AC_DEFINE(HAVE_QUOTA_OFF_3ARGS, 1, -- 1.8.3.1