In builds without --enable-cassert (I guess not many developers use
those a lot), there are quite a few unused variable warnings.  These
usually hold some intermediate result that the assert checks later.  I
see that in some places our code already uses #ifdef
USE_ASSERT_CHECKING, presumably to hide similar issues.  But in most
cases using this would significantly butcher the code.  I found that
adding __attribute__((unused)) is cleaner.  Attached is a patch that
cleans up all the warnings I encountered.
diff --git i/src/backend/access/hash/hashovfl.c w/src/backend/access/hash/hashovfl.c
index 130c296..d4329fb 100644
--- i/src/backend/access/hash/hashovfl.c
+++ w/src/backend/access/hash/hashovfl.c
@@ -391,7 +391,9 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
 	uint32		ovflbitno;
 	int32		bitmappage,
 				bitmapbit;
+#ifdef USE_ASSERT_CHECKING
 	Bucket		bucket;
+#endif
 
 	/* Get information from the doomed page */
 	_hash_checkpage(rel, ovflbuf, LH_OVERFLOW_PAGE);
@@ -400,7 +402,9 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
 	ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
 	nextblkno = ovflopaque->hasho_nextblkno;
 	prevblkno = ovflopaque->hasho_prevblkno;
+#ifdef USE_ASSERT_CHECKING
 	bucket = ovflopaque->hasho_bucket;
+#endif
 
 	/*
 	 * Zero the page for debugging's sake; then write and release it. (Note:
diff --git i/src/backend/executor/execCurrent.c w/src/backend/executor/execCurrent.c
index b07161f..2a59fc6 100644
--- i/src/backend/executor/execCurrent.c
+++ w/src/backend/executor/execCurrent.c
@@ -151,7 +151,7 @@ execCurrentOf(CurrentOfExpr *cexpr,
 	{
 		ScanState  *scanstate;
 		bool		lisnull;
-		Oid			tuple_tableoid;
+		Oid			tuple_tableoid __attribute__((unused));
 		ItemPointer tuple_tid;
 
 		/*
diff --git i/src/backend/executor/nodeMaterial.c w/src/backend/executor/nodeMaterial.c
index b320b54..4ab660e 100644
--- i/src/backend/executor/nodeMaterial.c
+++ w/src/backend/executor/nodeMaterial.c
@@ -66,7 +66,7 @@ ExecMaterial(MaterialState *node)
 			 * Allocate a second read pointer to serve as the mark. We know it
 			 * must have index 1, so needn't store that.
 			 */
-			int			ptrno;
+			int			ptrno __attribute__((unused));
 
 			ptrno = tuplestore_alloc_read_pointer(tuplestorestate,
 												  node->eflags);
diff --git i/src/backend/executor/nodeSetOp.c w/src/backend/executor/nodeSetOp.c
index 7fa5730..c6a88a8 100644
--- i/src/backend/executor/nodeSetOp.c
+++ w/src/backend/executor/nodeSetOp.c
@@ -344,7 +344,7 @@ setop_fill_hash_table(SetOpState *setopstate)
 	SetOp	   *node = (SetOp *) setopstate->ps.plan;
 	PlanState  *outerPlan;
 	int			firstFlag;
-	bool		in_first_rel;
+	bool		in_first_rel __attribute__((unused));
 
 	/*
 	 * get state info from node
diff --git i/src/backend/executor/nodeWorktablescan.c w/src/backend/executor/nodeWorktablescan.c
index e2f3dd4..e72d1cb 100644
--- i/src/backend/executor/nodeWorktablescan.c
+++ w/src/backend/executor/nodeWorktablescan.c
@@ -30,7 +30,7 @@ static TupleTableSlot *
 WorkTableScanNext(WorkTableScanState *node)
 {
 	TupleTableSlot *slot;
-	EState	   *estate;
+	EState	   *estate __attribute__((unused));
 	Tuplestorestate *tuplestorestate;
 
 	/*
diff --git i/src/backend/libpq/be-fsstubs.c w/src/backend/libpq/be-fsstubs.c
index b864c86..1bf765c 100644
--- i/src/backend/libpq/be-fsstubs.c
+++ w/src/backend/libpq/be-fsstubs.c
@@ -378,7 +378,7 @@ lo_import_internal(text *filename, Oid lobjOid)
 {
 	File		fd;
 	int			nbytes,
-				tmp;
+				tmp __attribute__((unused));
 	char		buf[BUFSIZE];
 	char		fnamebuf[MAXPGPATH];
 	LargeObjectDesc *lobj;
diff --git i/src/backend/libpq/pqcomm.c w/src/backend/libpq/pqcomm.c
index 35812f4..df41d60 100644
--- i/src/backend/libpq/pqcomm.c
+++ w/src/backend/libpq/pqcomm.c
@@ -1373,7 +1373,7 @@ fail:
 void
 pq_putmessage_noblock(char msgtype, const char *s, size_t len)
 {
-	int			res;
+	int			res __attribute__((unused));
 	int			required;
 
 	/*
diff --git i/src/backend/optimizer/path/costsize.c w/src/backend/optimizer/path/costsize.c
index e1c070e..fd16cb1 100644
--- i/src/backend/optimizer/path/costsize.c
+++ w/src/backend/optimizer/path/costsize.c
@@ -3245,7 +3245,7 @@ void
 set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
 {
 	PlannerInfo *subroot = rel->subroot;
-	RangeTblEntry *rte;
+	RangeTblEntry *rte __attribute__((unused));
 	ListCell   *lc;
 
 	/* Should only be applied to base relations that are subqueries */
diff --git i/src/backend/optimizer/plan/createplan.c w/src/backend/optimizer/plan/createplan.c
index e41d2a6..7dccf7d 100644
--- i/src/backend/optimizer/plan/createplan.c
+++ w/src/backend/optimizer/plan/createplan.c
@@ -1820,7 +1820,7 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
 	ForeignScan *scan_plan;
 	RelOptInfo *rel = best_path->path.parent;
 	Index		scan_relid = rel->relid;
-	RangeTblEntry *rte;
+	RangeTblEntry *rte __attribute__((unused));
 	bool		fsSystemCol;
 	int			i;
 
diff --git i/src/backend/parser/analyze.c w/src/backend/parser/analyze.c
index be6e93e..d1b9d4e 100644
--- i/src/backend/parser/analyze.c
+++ w/src/backend/parser/analyze.c
@@ -1530,7 +1530,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
 		/* Process leaf SELECT */
 		Query	   *selectQuery;
 		char		selectName[32];
-		RangeTblEntry *rte;
+		RangeTblEntry *rte __attribute__((unused));
 		RangeTblRef *rtr;
 		ListCell   *tl;
 
diff --git i/src/backend/storage/file/fd.c w/src/backend/storage/file/fd.c
index 43bc43a..5021cdc 100644
--- i/src/backend/storage/file/fd.c
+++ w/src/backend/storage/file/fd.c
@@ -684,7 +684,7 @@ LruInsert(File file)
 		/* seek to the right position */
 		if (vfdP->seekPos != (off_t) 0)
 		{
-			off_t		returnValue;
+			off_t		returnValue __attribute__((unused));
 
 			returnValue = lseek(vfdP->fd, vfdP->seekPos, SEEK_SET);
 			Assert(returnValue != (off_t) -1);
diff --git i/src/backend/storage/lmgr/predicate.c w/src/backend/storage/lmgr/predicate.c
index 821328b..839ed9b 100644
--- i/src/backend/storage/lmgr/predicate.c
+++ w/src/backend/storage/lmgr/predicate.c
@@ -2013,7 +2013,7 @@ RestoreScratchTarget(bool lockheld)
 static void
 RemoveTargetIfNoLongerUsed(PREDICATELOCKTARGET *target, uint32 targettaghash)
 {
-	PREDICATELOCKTARGET *rmtarget;
+	PREDICATELOCKTARGET *rmtarget __attribute__((unused));
 
 	Assert(LWLockHeldByMe(SerializablePredicateLockListLock));
 
@@ -2074,7 +2074,7 @@ DeleteChildTargetLocks(const PREDICATELOCKTARGETTAG *newtargettag)
 		{
 			uint32		oldtargettaghash;
 			LWLockId	partitionLock;
-			PREDICATELOCK *rmpredlock;
+			PREDICATELOCK *rmpredlock __attribute__((unused));
 
 			oldtargettaghash = PredicateLockTargetTagHashCode(&oldtargettag);
 			partitionLock = PredicateLockHashPartitionLock(oldtargettaghash);
@@ -2227,7 +2227,7 @@ DecrementParentLocks(const PREDICATELOCKTARGETTAG *targettag)
 	{
 		uint32		targettaghash;
 		LOCALPREDICATELOCK *parentlock,
-				   *rmlock;
+				   *rmlock __attribute__((unused));
 
 		parenttag = nexttag;
 		targettaghash = PredicateLockTargetTagHashCode(&parenttag);
diff --git i/src/backend/storage/lmgr/proc.c w/src/backend/storage/lmgr/proc.c
index dcf1928..6927fe6 100644
--- i/src/backend/storage/lmgr/proc.c
+++ w/src/backend/storage/lmgr/proc.c
@@ -807,7 +807,7 @@ static void
 AuxiliaryProcKill(int code, Datum arg)
 {
 	int			proctype = DatumGetInt32(arg);
-	PGPROC	   *auxproc;
+	PGPROC	   *auxproc __attribute__((unused));
 
 	Assert(proctype >= 0 && proctype < NUM_AUXILIARY_PROCS);
 
diff --git i/src/backend/utils/adt/selfuncs.c w/src/backend/utils/adt/selfuncs.c
index da638f8..cc11363 100644
--- i/src/backend/utils/adt/selfuncs.c
+++ w/src/backend/utils/adt/selfuncs.c
@@ -3771,7 +3771,7 @@ convert_string_datum(Datum value, Oid typid)
 	{
 		char	   *xfrmstr;
 		size_t		xfrmlen;
-		size_t		xfrmlen2;
+		size_t		xfrmlen2 __attribute__((unused));
 
 		/*
 		 * Note: originally we guessed at a suitable output buffer size, and
@@ -6281,7 +6281,7 @@ btcostestimate(PG_FUNCTION_ARGS)
 		RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcc);
 		Expr	   *clause;
 		Node	   *leftop,
-				   *rightop;
+				   *rightop __attribute__((unused));
 		Oid			clause_op;
 		int			op_strategy;
 		bool		is_null_op = false;
diff --git i/src/bin/psql/psqlscan.l w/src/bin/psql/psqlscan.l
index a27bcd1..0f69f54 100644
--- i/src/bin/psql/psqlscan.l
+++ w/src/bin/psql/psqlscan.l
@@ -1474,7 +1474,7 @@ psql_scan_slash_option(PsqlScanState state,
 					   bool semicolon)
 {
 	PQExpBufferData mybuf;
-	int			lexresult;
+	int			lexresult __attribute__((unused));
 	char		local_quote;
 
 	/* Must be scanning already */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to