warning: comparison of integer expressions of different signedness related to simd.h

Started by Pavel Stehuleover 3 years ago6 messageshackers
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

I got fresh warnings when I build an extension

In file included from
/usr/local/pgsql/master/include/server/mb/pg_wchar.h:22,
from src/format.c:17:
/usr/local/pgsql/master/include/server/port/simd.h: In function
‘vector8_has’:
/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning:
comparison of integer expressions of different signedness: ‘int’ and ‘long
unsigned int’ [-Wsign-compare]
168 | for (int i = 0; i < sizeof(Vector8); i++)
| ^
/usr/local/pgsql/master/include/server/port/simd.h: In function
‘vector8_has_le’:
/usr/local/pgsql/master/include/server/port/simd.h:219:27: warning:
comparison of integer expressions of different signedness: ‘int’ and ‘long
unsigned int’ [-Wsign-compare]
219 | for (int i = 0; i < sizeof(Vector8); i++)
| ^

[pavel@localhost plpgsql_check]$ uname -a
Linux localhost.localdomain 5.18.19-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC
Sun Aug 21 15:52:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[pavel@localhost plpgsql_check]$ gcc --version
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-1)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Regards

Pavel

#2John Naylor
john.naylor@enterprisedb.com
In reply to: Pavel Stehule (#1)
Re: warning: comparison of integer expressions of different signedness related to simd.h

On Sat, Sep 3, 2022 at 12:30 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hi

I got fresh warnings when I build an extension

In file included from /usr/local/pgsql/master/include/server/mb/pg_wchar.h:22,
from src/format.c:17:
/usr/local/pgsql/master/include/server/port/simd.h: In function ‘vector8_has’:
/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
168 | for (int i = 0; i < sizeof(Vector8); i++)
| ^

"int" should probably be "Size" -- does that remove the warning?

--
John Naylor
EDB: http://www.enterprisedb.com

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: John Naylor (#2)
Re: warning: comparison of integer expressions of different signedness related to simd.h

so 3. 9. 2022 v 7:50 odesílatel John Naylor <john.naylor@enterprisedb.com>
napsal:

On Sat, Sep 3, 2022 at 12:30 PM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

I got fresh warnings when I build an extension

In file included from

/usr/local/pgsql/master/include/server/mb/pg_wchar.h:22,

from src/format.c:17:
/usr/local/pgsql/master/include/server/port/simd.h: In function

‘vector8_has’:

/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning:

comparison of integer expressions of different signedness: ‘int’ and ‘long
unsigned int’ [-Wsign-compare]

168 | for (int i = 0; i < sizeof(Vector8); i++)
| ^

"int" should probably be "Size" -- does that remove the warning?

yes, it removes warnings

Pavel

Show quoted text

--
John Naylor
EDB: http://www.enterprisedb.com

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: John Naylor (#2)
Re: warning: comparison of integer expressions of different signedness related to simd.h

John Naylor <john.naylor@enterprisedb.com> writes:

On Sat, Sep 3, 2022 at 12:30 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:

/usr/local/pgsql/master/include/server/port/simd.h: In function ‘vector8_has’:
/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
168 | for (int i = 0; i < sizeof(Vector8); i++)

"int" should probably be "Size" -- does that remove the warning?

Agreed, should be Size or size_t, or else cast the sizeof() result.
But I wonder why none of the buildfarm is showing such a warning.

regards, tom lane

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#4)
Re: warning: comparison of integer expressions of different signedness related to simd.h

so 3. 9. 2022 v 7:57 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

John Naylor <john.naylor@enterprisedb.com> writes:

On Sat, Sep 3, 2022 at 12:30 PM Pavel Stehule <pavel.stehule@gmail.com>

wrote:

/usr/local/pgsql/master/include/server/port/simd.h: In function

‘vector8_has’:

/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning:

comparison of integer expressions of different signedness: ‘int’ and ‘long
unsigned int’ [-Wsign-compare]

168 | for (int i = 0; i < sizeof(Vector8); i++)

"int" should probably be "Size" -- does that remove the warning?

Agreed, should be Size or size_t, or else cast the sizeof() result.
But I wonder why none of the buildfarm is showing such a warning.

I got this warning when I compiled plgsql_check against master with enabled
asserts

https://github.com/okbob/plpgsql_check

In file included from
/usr/local/pgsql/master/include/server/mb/pg_wchar.h:22,
from src/format.c:17:
/usr/local/pgsql/master/include/server/port/simd.h: In function
‘vector8_has_le’:
/usr/local/pgsql/master/include/server/port/simd.h:219:27: warning:
comparison of integer expressions of different signedness: ‘int’ and ‘long
unsigned int’ [-Wsign-compare]
219 | for (int i = 0; i < sizeof(Vector8); i++)
| ^

Show quoted text

regards, tom lane

#6John Naylor
john.naylor@enterprisedb.com
In reply to: Tom Lane (#4)
Re: warning: comparison of integer expressions of different signedness related to simd.h

On Sat, Sep 3, 2022 at 12:57 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

John Naylor <john.naylor@enterprisedb.com> writes:

On Sat, Sep 3, 2022 at 12:30 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:

/usr/local/pgsql/master/include/server/port/simd.h: In function ‘vector8_has’:
/usr/local/pgsql/master/include/server/port/simd.h:168:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
168 | for (int i = 0; i < sizeof(Vector8); i++)

"int" should probably be "Size" -- does that remove the warning?

Agreed, should be Size or size_t, or else cast the sizeof() result.
But I wonder why none of the buildfarm is showing such a warning.

If I add -Wsign-compare to CPPFLAGS, I get dozens of warnings all over
the place. It's probably unreasonable for extensions to expect to
compile cleanly with warnings that the core server doesn't use, but
this header is clearly wrong and easy to remedy, so I've pushed a
patch.

--
John Naylor
EDB: http://www.enterprisedb.com