Skip to content

Commit 43ef6ab

Browse files
committed
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.
1 parent bca6eeb commit 43ef6ab

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/include/utils/elog.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ extern int getinternalerrposition(void);
216216
#else /* !HAVE__BUILTIN_CONSTANT_P */
217217
#define elog(elevel, ...) \
218218
do { \
219-
int elevel_; \
220219
elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
221-
elevel_ = (elevel); \
222-
elog_finish(elevel_, __VA_ARGS__); \
223-
if (elevel_ >= ERROR) \
224-
pg_unreachable(); \
220+
{ \
221+
const int elevel_ = (elevel); \
222+
elog_finish(elevel_, __VA_ARGS__); \
223+
if (elevel_ >= ERROR) \
224+
pg_unreachable(); \
225+
} \
225226
} while(0)
226227
#endif /* HAVE__BUILTIN_CONSTANT_P */
227228
#else /* !HAVE__VA_ARGS */

0 commit comments

Comments
 (0)