spgist rangetypes compiler warning (gcc 7.2.0)

Started by Tomas Vondraabout 8 years ago3 messages
#1Tomas Vondra
tomas.vondra@2ndquadrant.com
1 attachment(s)

Hi,

while compiling on gcc 7.2.0 (on ARM), I got this warning:

rangetypes_spgist.c: In function 'spg_range_quad_inner_consistent':
rangetypes_spgist.c:559:29: warning: comparison between pointer and
zero character constant [-Wpointer-compare]
if (in->traversalValue != (Datum) 0)
^~
rangetypes_spgist.c:559:10: note: did you mean to dereference the
pointer?
if (in->traversalValue != (Datum) 0)
^

I believe we should simply treat the traversalValue as pointer, and
change the condition to

if (in->traversalValue)

Patch attached.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Fix-compiler-warning-when-comparing-traversalValue.patchtext/x-patch; name=0001-Fix-compiler-warning-when-comparing-traversalValue.patchDownload
From 3b0528e9b56b9ff2dec4c3670d78ad9018224065 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Sat, 18 Nov 2017 20:25:02 +0100
Subject: [PATCH] Fix compiler warning when comparing traversalValue

On gcc 7.2.0, comparing pointer to (Datum)0 produces a warning. Treat
it as a simple pointer to fix that.
---
 src/backend/utils/adt/rangetypes_spgist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/rangetypes_spgist.c b/src/backend/utils/adt/rangetypes_spgist.c
index d934105..27fbf66 100644
--- a/src/backend/utils/adt/rangetypes_spgist.c
+++ b/src/backend/utils/adt/rangetypes_spgist.c
@@ -556,7 +556,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
 					 * for lower or upper bounds to be adjacent. Deserialize
 					 * previous centroid range if present for checking this.
 					 */
-					if (in->traversalValue != (Datum) 0)
+					if (in->traversalValue)
 					{
 						prevCentroid = DatumGetRangeTypeP(in->traversalValue);
 						range_deserialize(typcache, prevCentroid,
-- 
2.9.5

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tomas Vondra (#1)
Re: spgist rangetypes compiler warning (gcc 7.2.0)

Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:

while compiling on gcc 7.2.0 (on ARM), I got this warning:

rangetypes_spgist.c: In function 'spg_range_quad_inner_consistent':
rangetypes_spgist.c:559:29: warning: comparison between pointer and
zero character constant [-Wpointer-compare]
if (in->traversalValue != (Datum) 0)
^~

Huh. I wonder why 7.2.1 on Fedora isn't producing that warning.

I believe we should simply treat the traversalValue as pointer, and
change the condition to
if (in->traversalValue)

Agreed, especially since it's done like that in spgscan.c and
geo_spgist.c.

regards, tom lane

#3Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: spgist rangetypes compiler warning (gcc 7.2.0)

On 11/18/2017 10:40 PM, Tom Lane wrote:

Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:

while compiling on gcc 7.2.0 (on ARM), I got this warning:

rangetypes_spgist.c: In function 'spg_range_quad_inner_consistent':
rangetypes_spgist.c:559:29: warning: comparison between pointer and
zero character constant [-Wpointer-compare]
if (in->traversalValue != (Datum) 0)
^~

Huh. I wonder why 7.2.1 on Fedora isn't producing that warning.

Not sure. Maybe Ubuntu uses different flags (on ARM)? This is what I get
from 'gcc -v' on the machine:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/7/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
7.2.0-8ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=arm-linux-gnueabihf- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --libdir=/usr/lib
--enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-libitm --disable-libquadmath --enable-plugin
--enable-default-pie --with-system-zlib --with-target-system-zlib
--enable-objc-gc=auto --enable-multiarch --enable-multilib
--disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16
--with-float=hard --with-mode=thumb --disable-werror --enable-multilib
--enable-checking=release --build=arm-linux-gnueabihf
--host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 7.2.0 (Ubuntu/Linaro 7.2.0-8ubuntu3)

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services