aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-09-10 17:54:23 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-09-10 17:54:23 -0400
commitfa7b3a88dd5d7f6d18614eefc6cc0662e31bd451 (patch)
tree1db23d223744b676333237011f87a56e64f6818b
parent7a142b6bbf20c5ad54d11ea45e7a74ce02c510f0 (diff)
downloadpostgresql-fa7b3a88dd5d7f6d18614eefc6cc0662e31bd451.tar.gz
postgresql-fa7b3a88dd5d7f6d18614eefc6cc0662e31bd451.zip
Improve unreachability recognition in elog() macro.
Some experimentation with an older version of gcc showed that it is able to determine whether "if (elevel_ >= ERROR)" is compile-time constant if elevel_ is declared "const", but otherwise not so much. We had accounted for that in ereport() but were too miserly with braces to make it so in elog(). I don't know how many currently-interesting compilers have the same quirk, but in case it will save some code space, let's make sure that elog() is on the same footing as ereport() for this purpose. Back-patch to 9.3 where we introduced pg_unreachable() calls into elog/ereport.
-rw-r--r--src/include/utils/elog.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index f4ff03ec8a1..70dc365465c 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -206,12 +206,13 @@ extern int getinternalerrposition(void);
#else /* !HAVE__BUILTIN_CONSTANT_P */
#define elog(elevel, ...) \
do { \
- int elevel_; \
elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
- elevel_ = (elevel); \
- elog_finish(elevel_, __VA_ARGS__); \
- if (elevel_ >= ERROR) \
- pg_unreachable(); \
+ { \
+ const int elevel_ = (elevel); \
+ elog_finish(elevel_, __VA_ARGS__); \
+ if (elevel_ >= ERROR) \
+ pg_unreachable(); \
+ } \
} while(0)
#endif /* HAVE__BUILTIN_CONSTANT_P */
#else /* !HAVE__VA_ARGS */