From 69a38692cc3d9066f2750577cfdcbe5f6e02d2a5 Mon Sep 17 00:00:00 2001 From: Jakub Wartak Date: Tue, 7 May 2024 09:23:41 +0200 Subject: [PATCH v1] Tweak ereport so that it generates proper addresses for .cold branches Without this some ereport() could cause confusion when used with backtrace_functions as they would point to wrong addresses and thus to wrong functions being visible in logfile. --- src/include/utils/elog.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 054dd2bf62..f4f6e8d42d 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -145,8 +145,11 @@ struct Node; errstart_cold(elevel, domain) : \ errstart(elevel, domain)) \ __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \ - if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \ + if (__builtin_constant_p(elevel) && (elevel) >= ERROR) { \ + volatile char fix_backtrace_addr; \ + (void) fix_backtrace_addr; \ pg_unreachable(); \ + } \ } while(0) #else /* !HAVE__BUILTIN_CONSTANT_P */ #define ereport_domain(elevel, domain, ...) \ @@ -155,8 +158,11 @@ struct Node; pg_prevent_errno_in_scope(); \ if (errstart(elevel_, domain)) \ __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \ - if (elevel_ >= ERROR) \ + if (elevel_ >= ERROR) {\ + volatile char fix_backtrace_addr; \ + (void) fix_backtrace_addr; \ pg_unreachable(); \ + } \ } while(0) #endif /* HAVE__BUILTIN_CONSTANT_P */ -- 2.30.2