From f64b567cf96e78e43e82bdb4309c004a9c30bb50 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Wed, 16 Dec 2009 09:36:59 +0100 Subject: [PATCH] Fix some warnings that creep up when compiling without INVARIANTS. * Add a __debugvar define to which is empty when INVARIANTS is set (default) and __attribute__((unused)) when INVARIANTS is not set. * Use __debugvar in the declaration of variables which are only used in a KASSERT or KKASSERT to avoid 'unused variable' warnings. Suggested-by: aggelos Reported-by: Joel K. Petterson Dragonfly-bug: --- sys/kern/kern_lock.c | 4 ++-- sys/kern/kern_sig.c | 2 +- sys/kern/lwkt_thread.c | 9 ++++++--- sys/kern/vfs_cache.c | 2 +- sys/kern/vfs_syscalls.c | 4 ++-- sys/platform/pc32/i386/pmap.c | 2 +- sys/sys/systm.h | 2 ++ sys/vfs/hammer/hammer_object.c | 2 +- sys/vfs/hammer/hammer_subs.c | 4 ++-- sys/vfs/nfs/nfs_vnops.c | 2 +- 10 files changed, 19 insertions(+), 14 deletions(-) diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index f205adbd02..f73b2399e0 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -433,7 +433,7 @@ debuglockmgr(struct lock *lkp, u_int flags, void lockmgr_kernproc(struct lock *lp) { - struct thread *td = curthread; + struct thread *td __debugvar = curthread; if (lp->lk_lockholder != LK_KERNTHREAD) { KASSERT(lp->lk_lockholder == td, @@ -470,7 +470,7 @@ lockmgr_setexclusive_interlocked(struct lock *lkp) void lockmgr_clrexclusive_interlocked(struct lock *lkp) { - thread_t td = curthread; + thread_t td __debugvar = curthread; int dowakeup = 0; KKASSERT((lkp->lk_flags & LK_HAVE_EXCL) && lkp->lk_exclusivecount == 1 diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 8248bed692..60abb3fbf5 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1256,7 +1256,7 @@ lwp_signotify(struct lwp *lp) signotify(); } else if (lp->lwp_stat == LSRUN) { struct thread *td = lp->lwp_thread; - struct proc *p = lp->lwp_proc; + struct proc *p __debugvar = lp->lwp_proc; KASSERT(td != NULL, ("pid %d/%d NULL lwp_thread stat %d flags %08x/%08x", diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index 959549cc89..5111082fcb 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -87,8 +87,8 @@ static __int64_t switch_count = 0; static __int64_t preempt_hit = 0; static __int64_t preempt_miss = 0; static __int64_t preempt_weird = 0; -static __int64_t token_contention_count = 0; -static __int64_t mplock_contention_count = 0; +static __int64_t token_contention_count __debugvar = 0; +static __int64_t mplock_contention_count __debugvar = 0; static int lwkt_use_spin_port; #ifdef SMP static int chain_mplock = 0; @@ -781,7 +781,10 @@ using_idle_thread: if (td != ntd) { ++switch_count; #ifdef __x86_64__ - KKASSERT(jg_tos_ok(ntd)); + { + int tos_ok __debugvar = jg_tos_ok(ntd); + KKASSERT(tos_ok); + } #endif KTR_LOG(ctxsw_sw, td, ntd); td->td_switch(ntd); diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 17a051b386..55984d62fc 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -493,7 +493,7 @@ static void _cache_unlock(struct namecache *ncp) { - thread_t td = curthread; + thread_t td __debugvar = curthread; KKASSERT(ncp->nc_refs > 0); KKASSERT(ncp->nc_exlocks > 0); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index c4dfa2d540..6f4616c9ac 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -570,7 +570,7 @@ int sys_unmount(struct unmount_args *uap) { struct thread *td = curthread; - struct proc *p = td->td_proc; + struct proc *p __debugvar = td->td_proc; struct mount *mp = NULL; struct nlookupdata nd; int error; @@ -1738,7 +1738,7 @@ kern_chroot(struct nchandle *nch) int sys_chroot(struct chroot_args *uap) { - struct thread *td = curthread; + struct thread *td __debugvar = curthread; struct nlookupdata nd; int error; diff --git a/sys/platform/pc32/i386/pmap.c b/sys/platform/pc32/i386/pmap.c index f1753c3c79..53cc386363 100644 --- a/sys/platform/pc32/i386/pmap.c +++ b/sys/platform/pc32/i386/pmap.c @@ -592,7 +592,7 @@ static unsigned * get_ptbase(pmap_t pmap) { unsigned frame = (unsigned) pmap->pm_pdir[PTDPTDI] & PG_FRAME; - struct globaldata *gd = mycpu; + struct globaldata *gd __debugvar = mycpu; /* are we current address space or kernel? */ if (pmap == &kernel_pmap || frame == (((unsigned) PTDpde) & PG_FRAME)) { diff --git a/sys/sys/systm.h b/sys/sys/systm.h index e4e1806b50..46028d72b6 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -108,9 +108,11 @@ extern vm_paddr_t Maxmem; /* Highest physical memory address in system */ #define KKASSERT(exp) do { if (__predict_false(!(exp))) \ panic("assertion: %s in %s", \ #exp, __func__); } while (0) +#define __debugvar #else #define KASSERT(exp,msg) #define KKASSERT(exp) +#define __debugvar __attribute__((__unused__)) #endif #define CTASSERT(x) _CTASSERT(x, __LINE__) diff --git a/sys/vfs/hammer/hammer_object.c b/sys/vfs/hammer/hammer_object.c index 2237b7d5a6..b947084766 100644 --- a/sys/vfs/hammer/hammer_object.c +++ b/sys/vfs/hammer/hammer_object.c @@ -1518,7 +1518,7 @@ _hammer_ip_reseek(hammer_cursor_t cursor) int hammer_ip_first(hammer_cursor_t cursor) { - hammer_inode_t ip = cursor->ip; + hammer_inode_t ip __debugvar = cursor->ip; int error; KKASSERT(ip != NULL); diff --git a/sys/vfs/hammer/hammer_subs.c b/sys/vfs/hammer/hammer_subs.c index e365e81318..83d844021f 100644 --- a/sys/vfs/hammer/hammer_subs.c +++ b/sys/vfs/hammer/hammer_subs.c @@ -245,7 +245,7 @@ hammer_lock_upgrade(struct hammer_lock *lock) void hammer_lock_downgrade(struct hammer_lock *lock) { - thread_t td = curthread; + thread_t td __debugvar = curthread; u_int lv; u_int nlv; @@ -272,7 +272,7 @@ hammer_lock_downgrade(struct hammer_lock *lock) void hammer_unlock(struct hammer_lock *lock) { - thread_t td = curthread; + thread_t td __debugvar = curthread; u_int lv; u_int nlv; diff --git a/sys/vfs/nfs/nfs_vnops.c b/sys/vfs/nfs/nfs_vnops.c index 8732980e84..92f2f16059 100644 --- a/sys/vfs/nfs/nfs_vnops.c +++ b/sys/vfs/nfs/nfs_vnops.c @@ -2969,7 +2969,7 @@ nfs_strategy(struct vop_strategy_args *ap) { struct bio *bio = ap->a_bio; struct bio *nbio; - struct buf *bp = bio->bio_buf; + struct buf *bp __debugvar = bio->bio_buf; struct thread *td; int error; -- 2.41.0