pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-committers@postgresql.org
Cc: Michael Paquier <michael.paquier@gmail.com>
Subject: Re: pgsql: Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.
Date: Fri, 20 Feb 2015 16:39:14 +0100
Message-ID: <20150220153914.GC12653@awork2.anarazel.de> (raw)
In-Reply-To: <E1YOfse-0003eE-Jq@gemulon.postgresql.org>
References: <E1YOfse-0003eE-Jq@gemulon.postgresql.org>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

On 2015-02-20 05:12:00 +0000, Tom Lane wrote:
> Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.
> 
> Replace some bogus "x[1]" declarations with "x[FLEXIBLE_ARRAY_MEMBER]".
> Aside from being more self-documenting, this should help prevent bogus
> warnings from static code analyzers and perhaps compiler misoptimizations.
> 
> This patch is just a down payment on eliminating the whole problem, but
> it gets rid of a lot of easy-to-fix cases.
> 
> Note that the main problem with doing this is that one must no longer rely
> on computing sizeof(the containing struct), since the result would be
> compiler-dependent.  Instead use offsetof(struct, lastfield).  Autoconf
> also warns against spelling that offsetof(struct, lastfield[0]).
> 
> Michael Paquier, review and additional fixes by me.

This triggers a large number of warnings with my preexisting clang 3.6 settings...

In file included from /home/andres/src/postgresql/src/backend/postmaster/pgstat.c:40:
/home/andres/src/postgresql/src/include/catalog/pg_proc.h:61:12: warning: 'proargtypes' may not be nested in a struct due to flexible array
      member [-Wflexible-array-extensions]
        oidvector       proargtypes;    /* parameter types (excludes OUT params) */
                        ^
In file included from /home/andres/src/postgresql/src/backend/executor/execQual.c:40:
In file included from /home/andres/src/postgresql/src/include/access/nbtree.h:21:
/home/andres/src/postgresql/src/include/catalog/pg_index.h:48:13: warning: 'indkey' may not be nested in a struct due to flexible array
      member [-Wflexible-array-extensions]
        int2vector      indkey;                 /* column numbers of indexed cols, or 0 */
and many more.

Now, -Wflexible-array-extensions is IIRC not a standard option and I
only got it because I use -Weverything and disable the crazy stuff. So
maybe it's not worth worrying about. I'll just include
-Wno-flexible-array-extensions for now.

But I thought it's worth mentioning that at least one person went
through the trouble of adding a warning about this ;). I can't really
agree in this case because indkey still is the, as far the compiler can
see, last element of a struct, even if there's nesting.

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



view thread (9+ messages)  latest in thread

Message-ID: <20150220153914.GC12653@awork2.anarazel.de>
Permalink:  ../20150220153914.GC12653@awork2.anarazel.de/
Also on:    postgresql.org/message-id/20150220153914.GC12653@awork2.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@2ndquadrant.com, tgl@sss.pgh.pa.us, michael.paquier@gmail.com
  Subject: Re: pgsql: Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.
  In-Reply-To: <20150220153914.GC12653@awork2.anarazel.de>
  References: <E1YOfse-0003eE-Jq@gemulon.postgresql.org> <20150220153914.GC12653@awork2.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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