Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eEdXB-0004dm-Ae for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2017 15:53:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eEdXA-0007X5-FV for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2017 15:53:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eEdXA-0007Wu-Aw for pgsql-bugs@lists.postgresql.org; Tue, 14 Nov 2017 15:53:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eEdX6-0001pb-Ms for pgsql-bugs@postgresql.org; Tue, 14 Nov 2017 15:53:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAEFrkKo018816; Tue, 14 Nov 2017 10:53:46 -0500 From: Tom Lane To: Michael Paquier cc: Dmitry Dolgov <9erthalion6@gmail.com>, Andres Freund , Peter Eisentraut , Vincent Lachenal , PostgreSQL mailing lists Subject: Re: [BUGS] BUG #14897: Segfault on statitics SQL request In-reply-to: References: <20171110185747.31519.28038@wrigleys.postgresql.org> <1415.1510340891@sss.pgh.pa.us> <5652.1510344738@sss.pgh.pa.us> <7710.1510346813@sss.pgh.pa.us> <10197.1510349123@sss.pgh.pa.us> <14075.1510352167@sss.pgh.pa.us> <17617.1510355215@sss.pgh.pa.us> <3192.1510508352@sss.pgh.pa.us> <10396.1510621709@sss.pgh.pa.us> <17615.1510630283@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Tue, 14 Nov 2017 14:20:25 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18814.1510674826.1@sss.pgh.pa.us> Date: Tue, 14 Nov 2017 10:53:46 -0500 Message-ID: <18815.1510674826@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > On Tue, Nov 14, 2017 at 12:31 PM, Tom Lane wrote: >> As I said before, I don't like moving the int128 typedefs into a section >> where they don't belong, but that's just cosmetic --- this is good enough >> for testing. > Section 3 could be moved after the section 4 listing the alignment > macros. It seems that it won't hurt to back-patch the refactoring as > well. After some further consideration of what's where in c.h, I propose that we redefine section 1 (hacks to cope with non-ANSI C compilers) as "compiler characteristics", and then move all of these items into it: "#ifdef PG_FORCE_DISABLE_INLINE" stanza all the pg_attribute_xxx() macros, also pg_noinline PG_USED_FOR_ASSERTS_ONLY maybe pg_unreachable(), although it's not insane to keep it in section 7 ditto for likely()/unlikely() If anyone's really hot to keep the "non-ANSI hacks" segregated from those, we could invent a "section 1.1" for that ... but I'd say that at least one of the stanzas that are in there now is unrelated to ANSI compatibility already. Having gotten pg_attribute_aligned in front of the int128 stanza, my vision for a full fix for the bug is: * Explicitly document somewhere that MAXALIGN ignores int128. * Have configure test for and define ALIGNOF_PG_INT128_TYPE if it defines PG_INT128_TYPE. * Set up the int128 stanza like this: #if defined(PG_INT128_TYPE) #if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF #define HAVE_INT128 1 typedef PG_INT128_TYPE int128 #if defined(pg_attribute_aligned) pg_attribute_aligned(MAXIMUM_ALIGNOF) #endif ; typedef unsigned PG_INT128_TYPE uint128 #if defined(pg_attribute_aligned) pg_attribute_aligned(MAXIMUM_ALIGNOF) #endif ; #endif #endif That is, even if configure finds an int128 type, we'll only use it if it fits or can be made to fit into our system-wide MAXALIGN assumption. * It'd be kind of nice to insert a StaticAssertStmt(alignof(int128) <= MAXIMUM_ALIGNOF) someplace to cross-check this, but as far as I can find we aren't relying on alignof() to exist, so I don't see a good way to do it. BTW, looking at the existing uses of pg_attribute_aligned along with this example, I can't help but think that this decision: /* * NB: aligned and packed are not given default definitions because they * affect code functionality; they *must* be implemented by the compiler * if they are to be used. */ was just useless pedantry. If we're going to ifdef around it everywhere the macro is of use, why not just #define it to empty? That would certainly make the above a lot easier to read. We could add a HAVE_PG_ATTRIBUTE_ALIGNED symbol for use in #if tests. Barring objections, I'll get on with making this happen. regards, tom lane