pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
gcc 12.1.0 warning
10+ messages / 5 participants
[nested] [flat]

Commits from this thread:
  2024-07-15 47ecbfdfcc 69bdee12e4 9d3a2b3cdf 3006fd8e6e 11441ad48d 212b0262d6 ff3cae4875  Fix bad indentation introduced in 43cd30bcd1c
  2024-07-15 9b047cc0b2 43cd30bcd1 b9f3db23b7 2ad3b9350f 2cf9bda76c 92f02c39c0 ee89c4fa4b  Fix type confusion in guc_var_compare()
* gcc 12.1.0 warning
@ 2022-05-06 14:34  Erik Rijkers <er@xs4all.nl>
  0 siblings, 2 replies; 10+ messages in thread

From: Erik Rijkers @ 2022-05-06 14:34 UTC (permalink / raw)
  To: pgsql-hackers@lists.postgresql.org

Hi,

Not sure if these compiler-mutterings are worth reporting but I guess 
we're trying to get a silent compile.

System: Debian 4.9.303-1 (2022-03-07) x86_64 GNU/Linux
Compiling with gcc 12.1.0 causes the below 'warning' and 'note'.
Compiling with --enable-cassert --enable-debug  is silent, no warnings)

In function ‘guc_var_compare’,
     inlined from ‘bsearch’ at 
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:33:23,
     inlined from ‘find_option’ at guc.c:5649:35:
guc.c:5736:38: warning: array subscript ‘const struct config_generic[0]’ 
is partly outside array bounds of ‘const char[8]’ [-Warray-bounds]
  5736 |         return guc_name_compare(confa->name, confb->name);
       |                                 ~~~~~^~~~~~

guc.c: In function ‘find_option’:
guc.c:5636:25: note: object ‘name’ of size 8
  5636 | find_option(const char *name, bool create_placeholders, bool 
skip_errors,
       |             ~~~~~~~~~~~~^~~~

(Compiling with gcc 6.3.0 does not complain.)

Below are the two configure lines, FWIW.


Erik Rijkers


# cassert-build: no warning/note
./configure \
--prefix=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD \
--bindir=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD/bin \
--libdir=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD/lib \
--with-pgport=6515 --quiet --enable-depend \
--enable-cassert --enable-debug \
--with-openssl --with-perl --with-libxml --with-libxslt --with-zlib \
--enable-tap-tests --with-extra-version=_0506_HEAD_701d --with-lz4


# normal build: causes warning/note:
./configure \
--prefix=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD \
--bindir=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD/bin.fast \
--libdir=/home/aardvark/pg_stuff/pg_installations/pgsql.HEAD/lib.fast \
--with-pgport=6515 --quiet --enable-depend \
--with-openssl --with-perl --with-libxml --with-libxslt --with-zlib \
--enable-tap-tests --with-extra-version=_0506_HEAD_701d --with-lz4






^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2022-05-06 14:46  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Erik Rijkers <er@xs4all.nl>
  1 sibling, 0 replies; 10+ messages in thread

From: Tom Lane @ 2022-05-06 14:46 UTC (permalink / raw)
  To: Erik Rijkers <er@xs4all.nl>; +Cc: pgsql-hackers@lists.postgresql.org

Erik Rijkers <er@xs4all.nl> writes:
> Not sure if these compiler-mutterings are worth reporting but I guess 
> we're trying to get a silent compile.

> System: Debian 4.9.303-1 (2022-03-07) x86_64 GNU/Linux
> Compiling with gcc 12.1.0 causes the below 'warning' and 'note'.
> Compiling with --enable-cassert --enable-debug  is silent, no warnings)

> In function ‘guc_var_compare’,
>      inlined from ‘bsearch’ at 
> /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:33:23,
>      inlined from ‘find_option’ at guc.c:5649:35:
> guc.c:5736:38: warning: array subscript ‘const struct config_generic[0]’ 
> is partly outside array bounds of ‘const char[8]’ [-Warray-bounds]
>   5736 |         return guc_name_compare(confa->name, confb->name);
>        |                                 ~~~~~^~~~~~

I'd call that a compiler bug.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2023-10-27 10:09  Nazir Bilal Yavuz <byavuz81@gmail.com>
  parent: Erik Rijkers <er@xs4all.nl>
  1 sibling, 1 reply; 10+ messages in thread

From: Nazir Bilal Yavuz @ 2023-10-27 10:09 UTC (permalink / raw)
  To: Erik Rijkers <er@xs4all.nl>; +Cc: pgsql-hackers@lists.postgresql.org, Andres Freund <andres@anarazel.de>; Thomas Munro <thomas.munro@gmail.com>

Hi,

On Fri, 27 Oct 2023 at 12:34, Erik Rijkers <er@xs4all.nl> wrote:
>
> Hi,
>
> Not sure if these compiler-mutterings are worth reporting but I guess
> we're trying to get a silent compile.
>
> System: Debian 4.9.303-1 (2022-03-07) x86_64 GNU/Linux
> Compiling with gcc 12.1.0 causes the below 'warning' and 'note'.
> Compiling with --enable-cassert --enable-debug  is silent, no warnings)
>
> In function ‘guc_var_compare’,
>      inlined from ‘bsearch’ at
> /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:33:23,
>      inlined from ‘find_option’ at guc.c:5649:35:
> guc.c:5736:38: warning: array subscript ‘const struct config_generic[0]’
> is partly outside array bounds of ‘const char[8]’ [-Warray-bounds]
>   5736 |         return guc_name_compare(confa->name, confb->name);
>        |                                 ~~~~~^~~~~~
>
> guc.c: In function ‘find_option’:
> guc.c:5636:25: note: object ‘name’ of size 8
>   5636 | find_option(const char *name, bool create_placeholders, bool
> skip_errors,
>        |             ~~~~~~~~~~~~^~~~
>
> (Compiling with gcc 6.3.0 does not complain.)

I was testing 'upgrading CI Debian images to bookworm'. I tested the
bookworm on REL_15, REL_16 and upstream. REL_16 and upstream finished
successfully but the CompilerWarnings task failed on REL_15 with the
same error.

gcc version: 12.2.0

CI Run: https://cirrus-ci.com/task/6151742664998912

Regards,
Nazir Bilal Yavuz
Microsoft





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-04-13 02:25  Andres Freund <andres@anarazel.de>
  parent: Nazir Bilal Yavuz <byavuz81@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Andres Freund @ 2024-04-13 02:25 UTC (permalink / raw)
  To: Nazir Bilal Yavuz <byavuz81@gmail.com>; +Cc: Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

Hi,

On 2023-10-27 13:09:01 +0300, Nazir Bilal Yavuz wrote:
> I was testing 'upgrading CI Debian images to bookworm'. I tested the
> bookworm on REL_15, REL_16 and upstream. REL_16 and upstream finished
> successfully but the CompilerWarnings task failed on REL_15 with the
> same error.

Is that still the case?  I briefly tried to repro this outside of CI and
couldn't reproduce the warning.

I'd really like to upgrade the CI images, it doesn't seem great to continue
using oldstable.


> gcc version: 12.2.0
> 
> CI Run: https://cirrus-ci.com/task/6151742664998912

Unfortunately the logs aren't accessible anymore, so I can't check the precise
patch level of the compiler and/or the precise invocation used.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-04-15 08:25  Nazir Bilal Yavuz <byavuz81@gmail.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 10+ messages in thread

From: Nazir Bilal Yavuz @ 2024-04-15 08:25 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

Hi,

On Sat, 13 Apr 2024 at 05:25, Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> On 2023-10-27 13:09:01 +0300, Nazir Bilal Yavuz wrote:
> > I was testing 'upgrading CI Debian images to bookworm'. I tested the
> > bookworm on REL_15, REL_16 and upstream. REL_16 and upstream finished
> > successfully but the CompilerWarnings task failed on REL_15 with the
> > same error.
>
> Is that still the case?  I briefly tried to repro this outside of CI and
> couldn't reproduce the warning.
>
> I'd really like to upgrade the CI images, it doesn't seem great to continue
> using oldstable.
>
>
> > gcc version: 12.2.0
> >
> > CI Run: https://cirrus-ci.com/task/6151742664998912
>
> Unfortunately the logs aren't accessible anymore, so I can't check the precise
> patch level of the compiler and/or the precise invocation used.

I am able to reproduce this. I regenerated the debian bookworm image
and ran CI on REL_15_STABLE with this image.

CI Run: https://cirrus-ci.com/task/4978799442395136

--

Regards,
Nazir Bilal Yavuz
Microsoft





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-04-23 16:59  Andres Freund <andres@anarazel.de>
  parent: Nazir Bilal Yavuz <byavuz81@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Andres Freund @ 2024-04-23 16:59 UTC (permalink / raw)
  To: Nazir Bilal Yavuz <byavuz81@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

Hi,

On 2024-04-15 11:25:05 +0300, Nazir Bilal Yavuz wrote:
> I am able to reproduce this. I regenerated the debian bookworm image
> and ran CI on REL_15_STABLE with this image.
> 
> CI Run: https://cirrus-ci.com/task/4978799442395136

Hm, not sure why I wasn't able to repro - now I can.

It actually seems like a legitimate warning: The caller allocates the key as

static struct config_generic *
find_option(const char *name, bool create_placeholders, bool skip_errors,
			int elevel)
{
	const char **key = &name;

and then does
	res = (struct config_generic **) bsearch((void *) &key,
											 (void *) guc_variables,
											 num_guc_variables,
											 sizeof(struct config_generic *),
											 guc_var_compare);

while guc_var_compare() assume it's being passed a full config_generic:

static int
guc_var_compare(const void *a, const void *b)
{
	const struct config_generic *confa = *(struct config_generic *const *) a;
	const struct config_generic *confb = *(struct config_generic *const *) b;
	return guc_name_compare(confa->name, confb->name);
}


which several versions of gcc then complain about:

In function ‘guc_var_compare’,
    inlined from ‘bsearch’ at /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:33:23,
    inlined from ‘find_option’ at /home/andres/src/postgresql-15/src/backend/utils/misc/guc.c:5640:35:
/home/andres/src/postgresql-15/src/backend/utils/misc/guc.c:5727:38: warning: array subscript ‘const struct config_generic[0]’ is partly outside array bounds of ‘const char[8]’ [-Warray-bounds=]
 5727 |         return guc_name_compare(confa->name, confb->name);
      |                                 ~~~~~^~~~~~
/home/andres/src/postgresql-15/src/backend/utils/misc/guc.c: In function ‘find_option’:
/home/andres/src/postgresql-15/src/backend/utils/misc/guc.c:5627:25: note: object ‘name’ of size 8
 5627 | find_option(const char *name, bool create_placeholders, bool skip_errors,


Which seems entirely legitimate. ISTM that guc_var_compare() ought to only
cast the pointers to the key type, i.e. char *.  And incidentally that does
prevent the warning.

The reason it doesn't happen in newer versions of postgres is that we aren't
using guc_var_compare() in the relevant places anymore...

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-05-10 09:13  Nazir Bilal Yavuz <byavuz81@gmail.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 10+ messages in thread

From: Nazir Bilal Yavuz @ 2024-05-10 09:13 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

Hi,

On Tue, 23 Apr 2024 at 19:59, Andres Freund <andres@anarazel.de> wrote:
>
>
> Which seems entirely legitimate. ISTM that guc_var_compare() ought to only
> cast the pointers to the key type, i.e. char *.  And incidentally that does
> prevent the warning.
>
> The reason it doesn't happen in newer versions of postgres is that we aren't
> using guc_var_compare() in the relevant places anymore...

The fix is attached. It cleanly applies from REL_15_STABLE to
REL_12_STABLE, fixes the warnings and the tests pass.

-- 
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

v1-0001-Fix-Warray-bounds-warning-in-guc_var_compare-func.patch (text/x-patch, 1.5K) download From 588c99f5c402fc41414702133636e5a51f9e3470 Mon Sep 17 00:00:00 2001 From: Nazir Bilal Yavuz <byavuz81@gmail.com> Date: Fri, 10 May 2024 10:43:45 +0300 Subject: [PATCH v1] Fix -Warray-bounds warning in guc_var_compare() function There are a couple of places that guc_var_compare() function takes 'const char ***' type and then casts it to the 'const struct config_generic *' type. This triggers '-Warray-bounds' warning. So, instead cast them to the 'const char *' type. Author: Nazir Bilal Yavuz <byavuz81@gmail.com> Reported-by: Erik Rijkers <er@xs4all.nl> Suggested-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/a74a1a0d-0fd2-3649-5224-4f754e8f91aa%40xs4all.nl --- src/backend/utils/misc/guc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c410ba532d2..eec97dea659 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -5721,10 +5721,10 @@ find_option(const char *name, bool create_placeholders, bool skip_errors, static int guc_var_compare(const void *a, const void *b) { - const struct config_generic *confa = *(struct config_generic *const *) a; - const struct config_generic *confb = *(struct config_generic *const *) b; + const char *confa_name = **(char **const *) a; + const char *confb_name = **(char **const *) b; - return guc_name_compare(confa->name, confb->name); + return guc_name_compare(confa_name, confb_name); } /* -- 2.43.0
^ permalink raw reply [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-07-15 16:41  Andres Freund <andres@anarazel.de>
  parent: Nazir Bilal Yavuz <byavuz81@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Andres Freund @ 2024-07-15 16:41 UTC (permalink / raw)
  To: Nazir Bilal Yavuz <byavuz81@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

Hi,

On 2024-05-10 12:13:21 +0300, Nazir Bilal Yavuz wrote:
> On Tue, 23 Apr 2024 at 19:59, Andres Freund <andres@anarazel.de> wrote:
> >
> >
> > Which seems entirely legitimate. ISTM that guc_var_compare() ought to only
> > cast the pointers to the key type, i.e. char *.  And incidentally that does
> > prevent the warning.
> >
> > The reason it doesn't happen in newer versions of postgres is that we aren't
> > using guc_var_compare() in the relevant places anymore...
> 
> The fix is attached. It cleanly applies from REL_15_STABLE to
> REL_12_STABLE, fixes the warnings and the tests pass.

Thanks! I've applied it to all branches - while it's not required to avoid a
warning in newer versions, it's still not correct as it was...

Greetings,

Andres





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-07-15 17:14  Nathan Bossart <nathandbossart@gmail.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 10+ messages in thread

From: Nathan Bossart @ 2024-07-15 17:14 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Nazir Bilal Yavuz <byavuz81@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

On Mon, Jul 15, 2024 at 09:41:55AM -0700, Andres Freund wrote:
> On 2024-05-10 12:13:21 +0300, Nazir Bilal Yavuz wrote:
>> The fix is attached. It cleanly applies from REL_15_STABLE to
>> REL_12_STABLE, fixes the warnings and the tests pass.
> 
> Thanks! I've applied it to all branches - while it's not required to avoid a
> warning in newer versions, it's still not correct as it was...

nitpick: pgindent thinks one of the spaces is unnecessary.

inline patch 1: src/backend/utils/misc/guc.c (+2/-2 lines) download inline-1.patchdiff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index a043d529ef..b0947a4cf1 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1289,8 +1289,8 @@ find_option(const char *name, bool create_placeholders, bool skip_errors, static int guc_var_compare(const void *a, const void *b) { - const char *namea = **(const char ** const *) a; - const char *nameb = **(const char ** const *) b; + const char *namea = **(const char **const *) a; + const char *nameb = **(const char **const *) b; return guc_name_compare(namea, nameb); }
-- nathan ^ permalink raw reply [nested|flat] 10+ messages in thread

* Re: gcc 12.1.0 warning
@ 2024-07-15 20:36  Andres Freund <andres@anarazel.de>
  parent: Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2024-07-15 20:36 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Nazir Bilal Yavuz <byavuz81@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Erik Rijkers <er@xs4all.nl>; pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>

On 2024-07-15 12:14:47 -0500, Nathan Bossart wrote:
> On Mon, Jul 15, 2024 at 09:41:55AM -0700, Andres Freund wrote:
> > On 2024-05-10 12:13:21 +0300, Nazir Bilal Yavuz wrote:
> >> The fix is attached. It cleanly applies from REL_15_STABLE to
> >> REL_12_STABLE, fixes the warnings and the tests pass.
> > 
> > Thanks! I've applied it to all branches - while it's not required to avoid a
> > warning in newer versions, it's still not correct as it was...
> 
> nitpick: pgindent thinks one of the spaces is unnecessary.

Ugh. Sorry for that, will take a look at fixing that :(





^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2024-07-15 20:36 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:34 gcc 12.1.0 warning Erik Rijkers <er@xs4all.nl>
2022-05-06 14:46 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-10-27 10:09 ` Nazir Bilal Yavuz <byavuz81@gmail.com>
2024-04-13 02:25   ` Andres Freund <andres@anarazel.de>
2024-04-15 08:25     ` Nazir Bilal Yavuz <byavuz81@gmail.com>
2024-04-23 16:59       ` Andres Freund <andres@anarazel.de>
2024-05-10 09:13         ` Nazir Bilal Yavuz <byavuz81@gmail.com>
2024-07-15 16:41           ` Andres Freund <andres@anarazel.de>
2024-07-15 17:14             ` Nathan Bossart <nathandbossart@gmail.com>
2024-07-15 20:36               ` Andres Freund <andres@anarazel.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox