Skip to content

spa: avoid type narrowing warning #11336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2020
Merged

Conversation

rlibby
Copy link
Contributor

@rlibby rlibby commented Dec 13, 2020

Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386). Define spa_did to be
pointer-size instead. For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Signed-off-by: Ryan Libby [email protected]

Motivation and Context

Part of a small set of changes for building with gcc on FreeBSD.

This addresses an issue with the amd64 gcc build on FreeBSD. When gcc builds the spa module for i386 it emits the following warning due to the size difference between uint64_t and pthread_t:

Building /usr/obj/gcc6/usr/src/freebsd/amd64.amd64/obj-lib32/cddl/lib/libzpool/spa.o
In file included from /usr/src/freebsd/sys/contrib/openzfs/module/zfs/spa.c:45:0:
/usr/src/freebsd/sys/contrib/openzfs/module/zfs/spa.c: In function 'spa_deactivate':
/usr/src/freebsd/sys/contrib/openzfs/include/sys/zfs_context.h:235:37: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
 #define thread_join(t) pthread_join((pthread_t)(t), NULL)
                                     ^
/usr/src/freebsd/sys/contrib/openzfs/module/zfs/spa.c:1388:3: note: in expansion of macro 'thread_join'
   thread_join(spa->spa_did);
   ^~~~~~~~~~~

Description

The solution here is to define spa_did as uintptr_t, which will match pointer size, avoiding the warning. In fact, for now, spa_did is never assigned non-zero because the code is ifdef'd out. Even in the ifdef'd code, it is never assigned a pthread_t, but only a kernel thread id. Perhaps this may change in the future. Regardless, neither a kernel thread id nor a pthread_t should be larger than uintptr_t.

How Has This Been Tested?

Compile tested in the downstream FreeBSD build with gcc and clang.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386).  Define spa_did to be
pointer-size instead.  For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Signed-off-by: Ryan Libby <[email protected]>
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Dec 14, 2020
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Dec 15, 2020
@behlendorf behlendorf merged commit 956f940 into openzfs:master Dec 15, 2020
ghost pushed a commit to zfsonfreebsd/ZoF that referenced this pull request Dec 23, 2020
Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386).  Define spa_did to be
pointer-size instead.  For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Libby <[email protected]>
Closes openzfs#11336
behlendorf pushed a commit that referenced this pull request Dec 23, 2020
Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386).  Define spa_did to be
pointer-size instead.  For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Libby <[email protected]>
Closes #11336
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386).  Define spa_did to be
pointer-size instead.  For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Libby <[email protected]>
Closes openzfs#11336
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
Building the spa module for i386 caused gcc to emit
-Wint-to-pointer-cast "cast to pointer from integer of different size"
because spa.spa_did was uint64_t but pthread_join (via thread_join in
spa_deactivate) takes a pointer (32-bit on i386).  Define spa_did to be
pointer-size instead.  For now spa_did is in fact never non-zero and the
thread_join could instead be ifdef'd out, but changing the size of
spa_did may be more useful for the future.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Libby <[email protected]>
Closes openzfs#11336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants