postgresql/src/include
Tom Lane b853eb9718 Improve handling of ereport(ERROR) and elog(ERROR).
In commit 71450d7fd6, we added code to inform
suitably-intelligent compilers that ereport() doesn't return if the elevel
is ERROR or higher.  This patch extends that to elog(), and also fixes a
double-evaluation hazard that the previous commit created in ereport(),
as well as reducing the emitted code size.

The elog() improvement requires the compiler to support __VA_ARGS__, which
should be available in just about anything nowadays since it's required by
C99.  But our minimum language baseline is still C89, so add a configure
test for that.

The previous commit assumed that ereport's elevel could be evaluated twice,
which isn't terribly safe --- there are already counterexamples in xlog.c.
On compilers that have __builtin_constant_p, we can use that to protect the
second test, since there's no possible optimization gain if the compiler
doesn't know the value of elevel.  Otherwise, use a local variable inside
the macros to prevent double evaluation.  The local-variable solution is
inferior because (a) it leads to useless code being emitted when elevel
isn't constant, and (b) it increases the optimization level needed for the
compiler to recognize that subsequent code is unreachable.  But it seems
better than not teaching non-gcc compilers about unreachability at all.

Lastly, if the compiler has __builtin_unreachable(), we can use that
instead of abort(), resulting in a noticeable code savings since no
function call is actually emitted.  However, it seems wise to do this only
in non-assert builds.  In an assert build, continue to use abort(), so that
the behavior will be predictable and debuggable if the "impossible"
happens.

These changes involve making the ereport and elog macros emit do-while
statement blocks not just expressions, which forces small changes in
a few call sites.

Andres Freund, Tom Lane, Heikki Linnakangas
2013-01-13 18:40:09 -05:00
..
access Redesign the planner's handling of index-descent cost estimation. 2013-01-11 12:56:58 -05:00
bootstrap Update copyrights for 2013 2013-01-01 17:15:01 -05:00
catalog Update copyrights for 2013 2013-01-01 17:15:01 -05:00
commands Update copyrights for 2013 2013-01-01 17:15:01 -05:00
datatype Update copyrights for 2013 2013-01-01 17:15:01 -05:00
executor Invent a "one-shot" variant of CachedPlans for better performance. 2013-01-04 17:42:19 -05:00
foreign Update copyrights for 2013 2013-01-01 17:15:01 -05:00
lib Update copyrights for 2013 2013-01-01 17:15:01 -05:00
libpq Update copyrights for 2013 2013-01-01 17:15:01 -05:00
mb Update copyrights for 2013 2013-01-01 17:15:01 -05:00
nodes Redesign the planner's handling of index-descent cost estimation. 2013-01-11 12:56:58 -05:00
optimizer Update copyrights for 2013 2013-01-01 17:15:01 -05:00
parser Update copyrights for 2013 2013-01-01 17:15:01 -05:00
port Add URLs to document why DLLIMPORT is needed on Windows. 2012-11-07 15:01:25 -05:00
portability Update copyrights for 2013 2013-01-01 17:15:01 -05:00
postmaster Fix background workers for EXEC_BACKEND 2013-01-02 12:01:14 -03:00
regex Re-implement extraction of fixed prefixes from regular expressions. 2012-07-10 14:54:37 -04:00
replication Update copyrights for 2013 2013-01-01 17:15:01 -05:00
rewrite Update copyrights for 2013 2013-01-01 17:15:01 -05:00
snowball Update copyrights for 2013 2013-01-01 17:15:01 -05:00
storage Update copyrights for 2013 2013-01-01 17:15:01 -05:00
tcop Update copyrights for 2013 2013-01-01 17:15:01 -05:00
tsearch Update copyrights for 2013 2013-01-01 17:15:01 -05:00
utils Improve handling of ereport(ERROR) and elog(ERROR). 2013-01-13 18:40:09 -05:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Improve handling of ereport(ERROR) and elog(ERROR). 2013-01-13 18:40:09 -05:00
fmgr.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
funcapi.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
getaddrinfo.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
getopt_long.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Makefile Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
miscadmin.h Make sure MaxBackends is always set 2013-01-02 14:39:11 -03:00
pg_config.h.in Improve handling of ereport(ERROR) and elog(ERROR). 2013-01-13 18:40:09 -05:00
pg_config.h.win32 Improve handling of ereport(ERROR) and elog(ERROR). 2013-01-13 18:40:09 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
pg_trace.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
pgstat.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
pgtar.h Move tar function headers to pgtar.h 2013-01-02 20:34:08 +01:00
pgtime.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
port.h Centralize single quote escaping in src/port/quotes.c 2013-01-05 15:40:19 +01:00
postgres.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
postgres_ext.h Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
postgres_fe.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
rusagestub.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
windowapi.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00