Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f2717c7

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 ddc8893 commit f2717c7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/include/utils/elog.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ extern int getinternalerrposition(void);
206206
#else /* !HAVE__BUILTIN_CONSTANT_P */
207207
#define elog(elevel, ...) \
208208
do { \
209-
int elevel_; \
210209
elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
211-
elevel_ = (elevel); \
212-
elog_finish(elevel_, __VA_ARGS__); \
213-
if (elevel_ >= ERROR) \
214-
pg_unreachable(); \
210+
{ \
211+
const int elevel_ = (elevel); \
212+
elog_finish(elevel_, __VA_ARGS__); \
213+
if (elevel_ >= ERROR) \
214+
pg_unreachable(); \
215+
} \
215216
} while(0)
216217
#endif /* HAVE__BUILTIN_CONSTANT_P */
217218
#else /* !HAVE__VA_ARGS */

0 commit comments

Comments
 (0)