GCC-12 is flagging a comparison with the following diagnostic:
src/afs/afs_vcache.c:3161:25: error: the comparison will always
evaluate as ‘false’ for the address of ‘v’ will never be NULL
[-Werror=address]
3161 | AFSTOV(avc) == NULL || vType(avc) == VDIR ||
| ^~
When the vcache structure does not have the vnode embedded the expansion
of the AFSTOV macro results in:
((avc)->v)
which tests contents of a 'v'.
When the vcache structure does have the vnode embedded, the expansion of
the macro results in:
(&(avc)->v)
which tests the address of 'v', which will never be NULL in this case.
Update afs.h to add a new define 'AFS_VCACHE_EMBEDDED_VNODE' when the
vcache structure contains an embedded vnode structure. Restructure the
preprocessor statements for the AFSTOV definition
Avoid testing AFSTOV(x) against NULL when AFS_VCACHE_EMBEDDED_VNODE is
defined.
The diagnostic is changed from a warning to an error when configured
with --enable-checking.
Change-Id: Ib72647fa23e5a7ecd96772b04c6ef76540f44535
Reviewed-on: https://gerrit.openafs.org/14956
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
#define VTOAFS(v) ((struct vcache *)(v)->v_data)
#define AFSTOV(vc) ((vc)->v)
#else
+#define AFS_VCACHE_EMBEDDED_VNODE
#define VTOAFS(V) ((struct vcache *)(V))
#define AFSTOV(V) (&(V)->v)
#endif
* !(avc->nextfree) && !avc->vlruq.next => (FreeVCList == avc->nextfree)
*/
struct vcache {
-#if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_SUN511_ENV) || (defined(AFS_LINUX_ENV) && !defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE))
- struct vnode *v;
-#else
+#if defined(AFS_VCACHE_EMBEDDED_VNODE)
struct vnode v; /* Has reference count in v.v_count */
+#else
+ struct vnode *v;
#endif
struct afs_q vlruq; /* lru q next and prev */
#if !defined(AFS_LINUX_ENV)
if (do_dnlc) {
if ((avc->f.fid.Fid.Vnode & 1) ||
- AFSTOV(avc) == NULL || vType(avc) == VDIR ||
+#if !defined(AFS_VCACHE_EMBEDDED_VNODE)
+ AFSTOV(avc) == NULL ||
+#endif
+ vType(avc) == VDIR ||
(avc->f.states & CForeign)) {
/* This vcache is (or could be) a directory. */
osi_dnlc_purgedp(avc);