Tom Lane wrote:
Heikki Linnakangas <[EMAIL PROTECTED]> writes:
Hmm. It looks like I get that warning on my laptop as well. I tracked it down to these two places:

Line 209:
while (ptr - GETARR(trg) < ARRNELEM(trg))
{
        text       *item = (text *) palloc(VARHDRSZ + 3);
        
        SET_VARSIZE(item, VARHDRSZ + 3);
        CPTRGM(VARDATA(item), ptr);
        d[ptr - GETARR(trg)] = PointerGetDatum(item);
        ptr++;
}

I'll betcha the compiler is trying to optimize the repeated calculations
of "ptr - GETARR(trg)" into a separate variable that it increments along
with ptr.  Maybe it is getting it wrong, or maybe the assembler is just
confused.  Does the warning go away if you dial down the -O level?

FWIW, this patch makes the warnings go away, and makes the code a little bit more readable as well. It would be nice to understand why exactly it's complaining, though.

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com
Index: trgm_op.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/contrib/pg_trgm/trgm_op.c,v
retrieving revision 1.8
diff -c -r1.8 trgm_op.c
*** trgm_op.c	28 Feb 2007 22:44:38 -0000	1.8
--- trgm_op.c	12 Jul 2007 22:28:43 -0000
***************
*** 194,212 ****
  	Datum	   *d;
  	ArrayType  *a;
  	trgm	   *ptr;
  
  	trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
  	d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
  
! 	ptr = GETARR(trg);
! 	while (ptr - GETARR(trg) < ARRNELEM(trg))
  	{
  		text	   *item = (text *) palloc(VARHDRSZ + 3);
  
  		SET_VARSIZE(item, VARHDRSZ + 3);
  		CPTRGM(VARDATA(item), ptr);
! 		d[ptr - GETARR(trg)] = PointerGetDatum(item);
! 		ptr++;
  	}
  
  	a = construct_array(
--- 194,211 ----
  	Datum	   *d;
  	ArrayType  *a;
  	trgm	   *ptr;
+ 	int			i;
  
  	trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
  	d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
  
! 	for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
  	{
  		text	   *item = (text *) palloc(VARHDRSZ + 3);
  
  		SET_VARSIZE(item, VARHDRSZ + 3);
  		CPTRGM(VARDATA(item), ptr);
! 		d[i] = PointerGetDatum(item);
  	}
  
  	a = construct_array(
***************
*** 218,229 ****
  						'i'
  		);
  
! 	ptr = GETARR(trg);
! 	while (ptr - GETARR(trg) < ARRNELEM(trg))
! 	{
! 		pfree(DatumGetPointer(d[ptr - GETARR(trg)]));
! 		ptr++;
! 	}
  
  	pfree(d);
  	pfree(trg);
--- 217,224 ----
  						'i'
  		);
  
! 	for (i = 0; i < ARRNELEM(trg); i++)
! 		pfree(DatumGetPointer(d[i]));
  
  	pfree(d);
  	pfree(trg);
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to