Whamcloud - gitweb
LU-1436 debug: return the original type in RETURN
authorHongchao Zhang <hongchao.zhang@whamcloud.com>
Wed, 11 Jul 2012 07:20:20 +0000 (15:20 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 30 Jul 2012 16:57:06 +0000 (12:57 -0400)
in RETURN, the bit length of rc could be 32 or 64, and it also could
be pointer type, the conversion betweens pointer and integer type
will trigger compile warning related to type casting, then define an
static variable of typeof(rc), and avoid the stack usage ATM.

Signed-off-by: Hongchao Zhang <hongchao.zhang@whamcloud.com>
Change-Id: I7f3a54438dfe1f294168691718c4db8116f68de4
Reviewed-on: http://review.whamcloud.com/3072
Tested-by: Hudson
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs_debug.h

index 4a97f4f..4306a89 100644 (file)
@@ -300,17 +300,38 @@ do {                                                                    \
 #if defined(__GNUC__)
 
 long libcfs_log_return(struct libcfs_debug_msg_data *, long rc);
-#define RETURN(rc)                                                      \
-do {                                                                    \
-        EXIT_NESTING;                                                   \
-        if (cfs_cdebug_show(D_TRACE, DEBUG_SUBSYSTEM)) {                \
-                LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_TRACE, NULL);     \
-                return (typeof(rc))libcfs_log_return(&msgdata,          \
-                                                     (long)(rc));       \
-        }                                                               \
-                                                                        \
-        return (rc);                                                    \
+#if BITS_PER_LONG > 32
+#define RETURN(rc)                                                     \
+do {                                                                   \
+       EXIT_NESTING;                                                   \
+       if (cfs_cdebug_show(D_TRACE, DEBUG_SUBSYSTEM)) {                \
+                LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_TRACE, NULL);    \
+                return (typeof(rc))libcfs_log_return(&msgdata,         \
+                                                     (long)(rc));      \
+       }                                                               \
+                                                                       \
+       return (rc);                                                    \
 } while (0)
+#else /* BITS_PER_LONG == 32 */
+/* We need an on-stack variable, because we cannot case a 32-bit pointer
+ * directly to (long long) without generating a complier warning/error, yet
+ * casting directly to (long) will truncate 64-bit return values. The log
+ * values will print as 32-bit values, but they always have been. LU-1436
+ */
+#define RETURN(rc)                                                     \
+do {                                                                   \
+       EXIT_NESTING;                                                   \
+       if (cfs_cdebug_show(D_TRACE, DEBUG_SUBSYSTEM)) {                \
+               typeof(rc) __rc = (rc);                                 \
+               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_TRACE, NULL);     \
+               libcfs_log_return(&msgdata, (long_ptr_t)__rc);          \
+               return __rc;                                            \
+       }                                                               \
+                                                                       \
+       return (rc);                                                    \
+} while (0)
+#endif /* BITS_PER_LONG > 32 */
+
 #elif defined(_MSC_VER)
 #define RETURN(rc)                                                      \
 do {                                                                    \