Skip to content

Commit 71450d7

Browse files
committed
Teach compiler that ereport(>=ERROR) does not return
When elevel >= ERROR, we add an abort() call to the ereport() macro to give the compiler a hint that the ereport() expansion will not return, but the abort() isn't actually reached because the longjmp happens in errfinish(). Because the effect of ereport() varies with the elevel, we cannot use standard compiler attributes such as noreturn for this.
1 parent ffdd5a0 commit 71450d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/include/utils/elog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@
100100
* and have errstart insert the default text domain. Modules can either use
101101
* ereport_domain() directly, or preferably they can override the TEXTDOMAIN
102102
* macro.
103+
*
104+
* When elevel >= ERROR, we add an abort() call to give the compiler a hint
105+
* that the ereport() expansion will not return, but the abort() isn't actually
106+
* reached because the longjmp happens in errfinish().
103107
*----------
104108
*/
105109
#define ereport_domain(elevel, domain, rest) \
106110
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
107-
(errfinish rest) : (void) 0)
111+
(errfinish rest) : (void) 0), \
112+
((elevel) >= ERROR ? abort() : (void) 0)
108113

109114
#define ereport(elevel, rest) \
110115
ereport_domain(elevel, TEXTDOMAIN, rest)

0 commit comments

Comments
 (0)