From 1c85012cbb00cb9dc7216d98a6ffd056b2f3c3c7 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 28 Dec 2024 11:00:24 +0100 Subject: [PATCH 1/4] pg_noreturn to replace pg_attribute_noreturn() We want to support a "noreturn" decoration on more compilers besides just GCC-compatible ones, but for that we need to move the decoration in front of the function declaration instead of either behind it or wherever, which is the current style afforded by GCC-style attributes. Also rename the macro to "pg_noreturn" to be similar to the C11 standard "noreturn", and also because it's not necessarily an attribute anymore. pg_noreturn is now supported on all compilers that support C11 (using _Noreturn), as well as GCC-compatible ones (using __attribute__, as before), as well as MSVC (using __declspec). (When PostgreSQL requires C11, the latter two variants can be dropped.) Now, all supported compilers effectively support pg_noreturn, so the extra code for !HAVE_PG_ATTRIBUTE_NORETURN can be dropped. This also fixes a possible problem if third-party code includes stdnoreturn.h, because then the current definition of #define pg_attribute_noreturn() __attribute__((noreturn)) would cause an error. Note that the C standard does not support a noreturn attribute on function pointer types. So we have to drop these here. There are only two instances at this time, so it's not a big loss. --- contrib/dblink/dblink.c | 6 ++-- contrib/pgcrypto/px.h | 2 +- src/backend/access/transam/xlogrecovery.c | 3 +- src/backend/backup/basebackup_incremental.c | 6 ++-- src/backend/postmaster/autovacuum.c | 2 +- src/backend/postmaster/launch_backend.c | 2 +- src/backend/postmaster/postmaster.c | 2 +- src/backend/replication/logical/tablesync.c | 3 +- src/backend/replication/walsender.c | 2 +- src/backend/utils/adt/ri_triggers.c | 8 ++--- src/backend/utils/fmgr/dfmgr.c | 4 +-- src/backend/utils/hash/dynahash.c | 2 +- src/backend/utils/mmgr/slab.c | 2 +- src/bin/pg_combinebackup/load_manifest.c | 6 ++-- src/bin/pg_dump/pg_backup_utils.h | 2 +- src/bin/pg_upgrade/pg_upgrade.h | 2 +- src/bin/pg_verifybackup/pg_verifybackup.c | 6 ++-- src/bin/pg_verifybackup/pg_verifybackup.h | 4 +-- src/bin/pgbench/pgbench.h | 12 ++++---- src/include/bootstrap/bootstrap.h | 4 +-- src/include/c.h | 30 ++++++++++++------- src/include/commands/defrem.h | 2 +- src/include/common/parse_manifest.h | 3 +- src/include/mb/pg_wchar.h | 6 ++-- src/include/parser/parse_relation.h | 6 ++-- src/include/parser/scanner.h | 2 +- src/include/postmaster/autovacuum.h | 4 +-- src/include/postmaster/bgworker_internals.h | 2 +- src/include/postmaster/bgwriter.h | 4 +-- src/include/postmaster/pgarch.h | 2 +- src/include/postmaster/postmaster.h | 4 +-- src/include/postmaster/startup.h | 2 +- src/include/postmaster/syslogger.h | 2 +- src/include/postmaster/walsummarizer.h | 2 +- src/include/postmaster/walwriter.h | 2 +- src/include/replication/slotsync.h | 2 +- src/include/replication/walreceiver.h | 2 +- src/include/replication/walsender_private.h | 2 +- src/include/storage/ipc.h | 2 +- src/include/storage/lock.h | 2 +- src/include/tcop/backend_startup.h | 2 +- src/include/tcop/tcopprot.h | 12 ++++---- src/include/utils/elog.h | 13 ++------ src/include/utils/float.h | 6 ++-- src/include/utils/help_config.h | 2 +- src/include/utils/memutils_internal.h | 4 +-- src/interfaces/ecpg/preproc/preproc_extern.h | 2 +- src/pl/plpgsql/src/plpgsql.h | 2 +- .../modules/libpq_pipeline/libpq_pipeline.c | 5 ++-- src/test/modules/test_shm_mq/test_shm_mq.h | 2 +- src/test/modules/worker_spi/worker_spi.c | 2 +- src/timezone/zic.c | 4 +-- src/tools/pg_bsd_indent/err.h | 8 ++--- 53 files changed, 111 insertions(+), 116 deletions(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index c1c82eb4dd8..c4d5bc79986 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -160,8 +160,7 @@ xpstrdup(const char *in) return pstrdup(in); } -static void -pg_attribute_noreturn() +pg_noreturn static void dblink_res_internalerror(PGconn *conn, PGresult *res, const char *p2) { char *msg = pchomp(PQerrorMessage(conn)); @@ -170,8 +169,7 @@ dblink_res_internalerror(PGconn *conn, PGresult *res, const char *p2) elog(ERROR, "%s: %s", p2, msg); } -static void -pg_attribute_noreturn() +pg_noreturn static void dblink_conn_not_avail(const char *conname) { if (conname) diff --git a/contrib/pgcrypto/px.h b/contrib/pgcrypto/px.h index 471bb4ec727..45332fcddb6 100644 --- a/contrib/pgcrypto/px.h +++ b/contrib/pgcrypto/px.h @@ -173,7 +173,7 @@ int px_find_hmac(const char *name, PX_HMAC **res); int px_find_cipher(const char *name, PX_Cipher **res); int px_find_combo(const char *name, PX_Combo **res); -void px_THROW_ERROR(int err) pg_attribute_noreturn(); +pg_noreturn void px_THROW_ERROR(int err); const char *px_strerror(int err); const char *px_resolve_alias(const PX_Alias *list, const char *name); diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index c6994b78282..d94b73b6a25 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -4763,8 +4763,7 @@ check_primary_slot_name(char **newval, void **extra, GucSource source) * that we have odd behaviors such as unexpected GUC ordering dependencies. */ -static void -pg_attribute_noreturn() +pg_noreturn static void error_multiple_recovery_targets(void) { ereport(ERROR, diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c index 87cc1b96cbc..18c21dbea2a 100644 --- a/src/backend/backup/basebackup_incremental.c +++ b/src/backend/backup/basebackup_incremental.c @@ -139,9 +139,9 @@ static void manifest_process_wal_range(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn); -static void manifest_report_error(JsonManifestParseContext *context, - const char *fmt,...) - pg_attribute_printf(2, 3) pg_attribute_noreturn(); +pg_noreturn static void manifest_report_error(JsonManifestParseContext *context, + const char *fmt,...) + pg_attribute_printf(2, 3); static int compare_block_numbers(const void *a, const void *b); /* diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 8078eeef62e..54b662ffd13 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -315,7 +315,7 @@ int AutovacuumLauncherPid = 0; static Oid do_start_worker(void); static void HandleAutoVacLauncherInterrupts(void); -static void AutoVacLauncherShutdown(void) pg_attribute_noreturn(); +pg_noreturn static void AutoVacLauncherShutdown(void); static void launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval *nap); static void launch_worker(TimestampTz now); diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index 1f2d829ec5a..6059f56f2a2 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -171,7 +171,7 @@ static pid_t internal_forkexec(const char *child_kind, int child_slot, typedef struct { const char *name; - void (*main_fn) (char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); + void (*main_fn) (char *startup_data, size_t startup_data_len); bool shmem_attach; } child_process_kind; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 6f849ffbcb5..ae233d76649 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -412,7 +412,7 @@ static void LogChildExit(int lev, const char *procname, int pid, int exitstatus); static void PostmasterStateMachine(void); -static void ExitPostmaster(int status) pg_attribute_noreturn(); +pg_noreturn static void ExitPostmaster(int status); static int ServerLoop(void); static int BackendStartup(ClientSocket *client_sock); static void report_fork_failure_to_client(ClientSocket *client_sock, int errnum); diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 7c8a0e9cfeb..40393f8d364 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -139,8 +139,7 @@ static StringInfo copybuf = NULL; /* * Exit routine for synchronization worker. */ -static void -pg_attribute_noreturn() +pg_noreturn static void finish_sync_worker(void) { /* diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index dc25dd6af91..aca4473af69 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -237,7 +237,7 @@ typedef void (*WalSndSendDataCallback) (void); static void WalSndLoop(WalSndSendDataCallback send_data); static void InitWalSenderSlot(void); static void WalSndKill(int code, Datum arg); -static void WalSndShutdown(void) pg_attribute_noreturn(); +pg_noreturn static void WalSndShutdown(void); static void XLogSendPhysical(void); static void XLogSendLogical(void); static void WalSndDone(WalSndSendDataCallback send_data); diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 093a3f1b66b..d29ed047d28 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -233,10 +233,10 @@ static bool ri_PerformCheck(const RI_ConstraintInfo *riinfo, static void ri_ExtractValues(Relation rel, TupleTableSlot *slot, const RI_ConstraintInfo *riinfo, bool rel_is_pk, Datum *vals, char *nulls); -static void ri_ReportViolation(const RI_ConstraintInfo *riinfo, - Relation pk_rel, Relation fk_rel, - TupleTableSlot *violatorslot, TupleDesc tupdesc, - int queryno, bool is_restrict, bool partgone) pg_attribute_noreturn(); +pg_noreturn static void ri_ReportViolation(const RI_ConstraintInfo *riinfo, + Relation pk_rel, Relation fk_rel, + TupleTableSlot *violatorslot, TupleDesc tupdesc, + int queryno, bool is_restrict, bool partgone); /* diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index 8b7807472fd..0592ed637ee 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -67,8 +67,8 @@ static DynamicFileList *file_tail = NULL; char *Dynamic_library_path; static void *internal_load_library(const char *libname); -static void incompatible_module_error(const char *libname, - const Pg_magic_struct *module_magic_data) pg_attribute_noreturn(); +pg_noreturn static void incompatible_module_error(const char *libname, + const Pg_magic_struct *module_magic_data); static char *expand_dynamic_library_name(const char *name); static void check_restricted_library_name(const char *name); static char *substitute_libpath_macro(const char *name); diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index 493eae4f4b0..8aa0c50b07c 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -272,7 +272,7 @@ static HASHBUCKET get_hash_entry(HTAB *hashp, int freelist_idx); static void hdefault(HTAB *hashp); static int choose_nelem_alloc(Size entrysize); static bool init_htab(HTAB *hashp, long nelem); -static void hash_corrupted(HTAB *hashp) pg_attribute_noreturn(); +pg_noreturn static void hash_corrupted(HTAB *hashp); static uint32 hash_initial_lookup(HTAB *hashp, uint32 hashvalue, HASHBUCKET **bucketptr); static long next_pow2_long(long num); diff --git a/src/backend/utils/mmgr/slab.c b/src/backend/utils/mmgr/slab.c index 3e15d59683f..bf8b841caa4 100644 --- a/src/backend/utils/mmgr/slab.c +++ b/src/backend/utils/mmgr/slab.c @@ -601,8 +601,8 @@ SlabAllocFromNewBlock(MemoryContext context, Size size, int flags) * want to avoid that. */ pg_noinline +pg_noreturn static void -pg_attribute_noreturn() SlabAllocInvalidSize(MemoryContext context, Size size) { SlabContext *slab = (SlabContext *) context; diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c index 54adb5a41d2..9c60bee17bf 100644 --- a/src/bin/pg_combinebackup/load_manifest.c +++ b/src/bin/pg_combinebackup/load_manifest.c @@ -68,9 +68,9 @@ static void combinebackup_per_wal_range_cb(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn); -static void report_manifest_error(JsonManifestParseContext *context, - const char *fmt,...) - pg_attribute_printf(2, 3) pg_attribute_noreturn(); +pg_noreturn static void report_manifest_error(JsonManifestParseContext *context, + const char *fmt,...) + pg_attribute_printf(2, 3); /* * Load backup_manifest files from an array of backups and produces an array diff --git a/src/bin/pg_dump/pg_backup_utils.h b/src/bin/pg_dump/pg_backup_utils.h index f2677839e30..470e9a0c9af 100644 --- a/src/bin/pg_dump/pg_backup_utils.h +++ b/src/bin/pg_dump/pg_backup_utils.h @@ -29,7 +29,7 @@ extern const char *progname; extern void set_dump_section(const char *arg, int *dumpSections); extern void on_exit_nicely(on_exit_nicely_callback function, void *arg); -extern void exit_nicely(int code) pg_attribute_noreturn(); +pg_noreturn extern void exit_nicely(int code); /* In pg_dump, we modify pg_fatal to call exit_nicely instead of exit */ #undef pg_fatal diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h index 53f693c2d4b..26451578981 100644 --- a/src/bin/pg_upgrade/pg_upgrade.h +++ b/src/bin/pg_upgrade/pg_upgrade.h @@ -471,7 +471,7 @@ int get_user_info(char **user_name_p); void check_ok(void); void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3); void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3); -void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2) pg_attribute_noreturn(); +pg_noreturn void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2); void end_progress_output(void); void cleanup_output_dirs(void); void prep_status(const char *fmt,...) pg_attribute_printf(1, 2); diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c index 0719cb89783..e4f4f8e6d39 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -69,9 +69,9 @@ static void verifybackup_per_wal_range_cb(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn); -static void report_manifest_error(JsonManifestParseContext *context, - const char *fmt,...) - pg_attribute_printf(2, 3) pg_attribute_noreturn(); +pg_noreturn static void report_manifest_error(JsonManifestParseContext *context, + const char *fmt,...) + pg_attribute_printf(2, 3); static void verify_tar_backup(verifier_context *context, DIR *dir); static void verify_plain_backup_directory(verifier_context *context, diff --git a/src/bin/pg_verifybackup/pg_verifybackup.h b/src/bin/pg_verifybackup/pg_verifybackup.h index 2f864fb0f3f..7da31d90fea 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.h +++ b/src/bin/pg_verifybackup/pg_verifybackup.h @@ -98,8 +98,8 @@ typedef struct verifier_context extern void report_backup_error(verifier_context *context, const char *pg_restrict fmt,...) pg_attribute_printf(2, 3); -extern void report_fatal_error(const char *pg_restrict fmt,...) - pg_attribute_printf(1, 2) pg_attribute_noreturn(); +pg_noreturn extern void report_fatal_error(const char *pg_restrict fmt,...) + pg_attribute_printf(1, 2); extern bool should_ignore_relpath(verifier_context *context, const char *relpath); diff --git a/src/bin/pgbench/pgbench.h b/src/bin/pgbench/pgbench.h index 177f218c223..83565a9f1b0 100644 --- a/src/bin/pgbench/pgbench.h +++ b/src/bin/pgbench/pgbench.h @@ -142,9 +142,9 @@ extern PgBenchExpr *expr_parse_result; extern int expr_yyparse(yyscan_t yyscanner); extern int expr_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner); -extern void expr_yyerror(yyscan_t yyscanner, const char *message) pg_attribute_noreturn(); -extern void expr_yyerror_more(yyscan_t yyscanner, const char *message, - const char *more) pg_attribute_noreturn(); +pg_noreturn extern void expr_yyerror(yyscan_t yyscanner, const char *message); +pg_noreturn extern void expr_yyerror_more(yyscan_t yyscanner, const char *message, + const char *more); extern bool expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, int *offset); extern yyscan_t expr_scanner_init(PsqlScanState state, @@ -157,9 +157,9 @@ extern char *expr_scanner_get_substring(PsqlScanState state, bool chomp); extern int expr_scanner_get_lineno(PsqlScanState state, int offset); -extern void syntax_error(const char *source, int lineno, const char *line, - const char *command, const char *msg, - const char *more, int column) pg_attribute_noreturn(); +pg_noreturn extern void syntax_error(const char *source, int lineno, const char *line, + const char *command, const char *msg, + const char *more, int column); extern bool strtoint64(const char *str, bool errorOK, int64 *result); extern bool strtodouble(const char *str, bool errorOK, double *dv); diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h index 33035d4ed82..39e50ec79da 100644 --- a/src/include/bootstrap/bootstrap.h +++ b/src/include/bootstrap/bootstrap.h @@ -33,7 +33,7 @@ extern PGDLLIMPORT Form_pg_attribute attrtypes[MAXATTR]; extern PGDLLIMPORT int numattr; -extern void BootstrapModeMain(int argc, char *argv[], bool check_only) pg_attribute_noreturn(); +pg_noreturn extern void BootstrapModeMain(int argc, char *argv[], bool check_only); extern void closerel(char *relname); extern void boot_openrel(char *relname); @@ -64,6 +64,6 @@ typedef void *yyscan_t; extern int boot_yyparse(yyscan_t yyscanner); extern int boot_yylex_init(yyscan_t *yyscannerp); extern int boot_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner); -extern void boot_yyerror(yyscan_t yyscanner, const char *message) pg_attribute_noreturn(); +pg_noreturn extern void boot_yyerror(yyscan_t yyscanner, const char *message); #endif /* BOOTSTRAP_H */ diff --git a/src/include/c.h b/src/include/c.h index 13bb39fdef3..eee2f476cb7 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -142,6 +142,22 @@ #define pg_nodiscard #endif +/* + * pg_noreturn corresponds to the C11 noreturn/_Noreturn function specifier. + * We can't use the standard name "noreturn" because some third-party code + * uses __attribute__((noreturn)) in headers, which would get confused if + * "noreturn" is defined to "_Noreturn", as is done by . + */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define pg_noreturn _Noreturn +#elif defined(__GNUC__) +#define pg_noreturn __attribute__((noreturn)) +#elif defined(_MSC_VER) +#define pg_noreturn __declspec(noreturn) +#else +#define pg_noreturn +#endif + /* * This macro will disable address safety instrumentation for a function * when running with "-fsanitize=address". Think twice before using this! @@ -210,30 +226,24 @@ #define pg_attribute_printf(f,a) #endif -/* GCC and Sunpro support aligned, packed and noreturn */ +/* GCC and Sunpro support aligned and packed */ #if defined(__GNUC__) || defined(__SUNPRO_C) #define pg_attribute_aligned(a) __attribute__((aligned(a))) -#define pg_attribute_noreturn() __attribute__((noreturn)) #define pg_attribute_packed() __attribute__((packed)) -#define HAVE_PG_ATTRIBUTE_NORETURN 1 #elif defined(_MSC_VER) /* - * MSVC supports aligned. noreturn is also possible but in MSVC it is - * declared before the definition while pg_attribute_noreturn() macro - * is currently used after the definition. + * MSVC supports aligned. * * Packing is also possible but only by wrapping the entire struct definition * which doesn't fit into our current macro declarations. */ #define pg_attribute_aligned(a) __declspec(align(a)) -#define pg_attribute_noreturn() #else /* * NB: aligned and packed are not given default definitions because they * affect code functionality; they *must* be implemented by the compiler * if they are to be used. */ -#define pg_attribute_noreturn() #endif /* @@ -855,8 +865,8 @@ typedef NameData *Name; * we should declare it as long as !FRONTEND. */ #ifndef FRONTEND -extern void ExceptionalCondition(const char *conditionName, - const char *fileName, int lineNumber) pg_attribute_noreturn(); +pg_noreturn extern void ExceptionalCondition(const char *conditionName, + const char *fileName, int lineNumber); #endif /* diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index 5fd095ea177..2e3fdda72fa 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -160,6 +160,6 @@ extern List *defGetQualifiedName(DefElem *def); extern TypeName *defGetTypeName(DefElem *def); extern int defGetTypeLength(DefElem *def); extern List *defGetStringList(DefElem *def); -extern void errorConflictingDefElem(DefElem *defel, ParseState *pstate) pg_attribute_noreturn(); +pg_noreturn extern void errorConflictingDefElem(DefElem *defel, ParseState *pstate); #endif /* DEFREM_H */ diff --git a/src/include/common/parse_manifest.h b/src/include/common/parse_manifest.h index 607db25a3a6..e7a3ce750e9 100644 --- a/src/include/common/parse_manifest.h +++ b/src/include/common/parse_manifest.h @@ -34,8 +34,7 @@ typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext * TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn); typedef void (*json_manifest_error_callback) (JsonManifestParseContext *, - const char *fmt,...) pg_attribute_printf(2, 3) - pg_attribute_noreturn(); + const char *fmt,...) pg_attribute_printf(2, 3); struct JsonManifestParseContext { diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h index 249cd18a357..dc23b903b07 100644 --- a/src/include/mb/pg_wchar.h +++ b/src/include/mb/pg_wchar.h @@ -767,9 +767,9 @@ extern void check_encoding_conversion_args(int src_encoding, int expected_src_encoding, int expected_dest_encoding); -extern void report_invalid_encoding(int encoding, const char *mbstr, int len) pg_attribute_noreturn(); -extern void report_untranslatable_char(int src_encoding, int dest_encoding, - const char *mbstr, int len) pg_attribute_noreturn(); +pg_noreturn extern void report_invalid_encoding(int encoding, const char *mbstr, int len); +pg_noreturn extern void report_untranslatable_char(int src_encoding, int dest_encoding, + const char *mbstr, int len); extern int local2local(const unsigned char *l, unsigned char *p, int len, int src_encoding, int dest_encoding, diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h index 91fd8e243b5..5b3461a65fe 100644 --- a/src/include/parser/parse_relation.h +++ b/src/include/parser/parse_relation.h @@ -110,9 +110,9 @@ extern bool isLockedRefname(ParseState *pstate, const char *refname); extern void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace); -extern void errorMissingRTE(ParseState *pstate, RangeVar *relation) pg_attribute_noreturn(); -extern void errorMissingColumn(ParseState *pstate, - const char *relname, const char *colname, int location) pg_attribute_noreturn(); +pg_noreturn extern void errorMissingRTE(ParseState *pstate, RangeVar *relation); +pg_noreturn extern void errorMissingColumn(ParseState *pstate, + const char *relname, const char *colname, int location); extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars); diff --git a/src/include/parser/scanner.h b/src/include/parser/scanner.h index d6293b1e878..ee42650fa08 100644 --- a/src/include/parser/scanner.h +++ b/src/include/parser/scanner.h @@ -145,6 +145,6 @@ extern void setup_scanner_errposition_callback(ScannerCallbackState *scbstate, core_yyscan_t yyscanner, int location); extern void cancel_scanner_errposition_callback(ScannerCallbackState *scbstate); -extern void scanner_yyerror(const char *message, core_yyscan_t yyscanner) pg_attribute_noreturn(); +pg_noreturn extern void scanner_yyerror(const char *message, core_yyscan_t yyscanner); #endif /* SCANNER_H */ diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h index cae1e8b3294..1ff38db9e1f 100644 --- a/src/include/postmaster/autovacuum.h +++ b/src/include/postmaster/autovacuum.h @@ -56,8 +56,8 @@ extern void autovac_init(void); /* called from postmaster when a worker could not be forked */ extern void AutoVacWorkerFailed(void); -extern void AutoVacLauncherMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); -extern void AutoVacWorkerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void AutoVacLauncherMain(char *startup_data, size_t startup_data_len); +pg_noreturn extern void AutoVacWorkerMain(char *startup_data, size_t startup_data_len); extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId, BlockNumber blkno); diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h index f55adc85efc..1ba46b00b7e 100644 --- a/src/include/postmaster/bgworker_internals.h +++ b/src/include/postmaster/bgworker_internals.h @@ -52,6 +52,6 @@ extern void ForgetUnstartedBackgroundWorkers(void); extern void ResetBackgroundWorkerCrashTimes(void); /* Entry point for background worker processes */ -extern void BackgroundWorkerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void BackgroundWorkerMain(char *startup_data, size_t startup_data_len); #endif /* BGWORKER_INTERNALS_H */ diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h index 407f26e5302..d524964b8b0 100644 --- a/src/include/postmaster/bgwriter.h +++ b/src/include/postmaster/bgwriter.h @@ -27,8 +27,8 @@ extern PGDLLIMPORT int CheckPointTimeout; extern PGDLLIMPORT int CheckPointWarning; extern PGDLLIMPORT double CheckPointCompletionTarget; -extern void BackgroundWriterMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); -extern void CheckpointerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void BackgroundWriterMain(char *startup_data, size_t startup_data_len); +pg_noreturn extern void CheckpointerMain(char *startup_data, size_t startup_data_len); extern void RequestCheckpoint(int flags); extern void CheckpointWriteDelay(int flags, double progress); diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h index a7a417226b0..c59e5d93c67 100644 --- a/src/include/postmaster/pgarch.h +++ b/src/include/postmaster/pgarch.h @@ -29,7 +29,7 @@ extern Size PgArchShmemSize(void); extern void PgArchShmemInit(void); extern bool PgArchCanRestart(void); -extern void PgArchiverMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void PgArchiverMain(char *startup_data, size_t startup_data_len); extern void PgArchWakeup(void); extern void PgArchForceDirScan(void); diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index 24d49a5439e..089c024e2f7 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -91,7 +91,7 @@ extern PGDLLIMPORT const char *progname; extern PGDLLIMPORT bool redirection_done; extern PGDLLIMPORT bool LoadedSSL; -extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn(); +pg_noreturn extern void PostmasterMain(int argc, char *argv[]); extern void ClosePostmasterPorts(bool am_syslogger); extern void InitProcessGlobals(void); @@ -114,7 +114,7 @@ extern pid_t postmaster_child_launch(BackendType child_type, struct ClientSocket *client_sock); const char *PostmasterChildName(BackendType child_type); #ifdef EXEC_BACKEND -extern void SubPostmasterMain(int argc, char *argv[]) pg_attribute_noreturn(); +pg_noreturn extern void SubPostmasterMain(int argc, char *argv[]); #endif /* defined in pmchild.c */ diff --git a/src/include/postmaster/startup.h b/src/include/postmaster/startup.h index dde7ebde881..057b208548e 100644 --- a/src/include/postmaster/startup.h +++ b/src/include/postmaster/startup.h @@ -26,7 +26,7 @@ extern PGDLLIMPORT int log_startup_progress_interval; extern void HandleStartupProcInterrupts(void); -extern void StartupProcessMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void StartupProcessMain(char *startup_data, size_t startup_data_len); extern void PreRestoreCommand(void); extern void PostRestoreCommand(void); extern bool IsPromoteSignaled(void); diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h index 27bd16ae1da..a12488b3022 100644 --- a/src/include/postmaster/syslogger.h +++ b/src/include/postmaster/syslogger.h @@ -90,7 +90,7 @@ extern int SysLogger_Start(int child_slot); extern void write_syslogger_file(const char *buffer, int count, int destination); -extern void SysLoggerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void SysLoggerMain(char *startup_data, size_t startup_data_len); extern bool CheckLogrotateSignal(void); extern void RemoveLogrotateSignalFiles(void); diff --git a/src/include/postmaster/walsummarizer.h b/src/include/postmaster/walsummarizer.h index 2642aa701d7..18d85b7eb9a 100644 --- a/src/include/postmaster/walsummarizer.h +++ b/src/include/postmaster/walsummarizer.h @@ -21,7 +21,7 @@ extern PGDLLIMPORT int wal_summary_keep_time; extern Size WalSummarizerShmemSize(void); extern void WalSummarizerShmemInit(void); -extern void WalSummarizerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void WalSummarizerMain(char *startup_data, size_t startup_data_len); extern void GetWalSummarizerState(TimeLineID *summarized_tli, XLogRecPtr *summarized_lsn, diff --git a/src/include/postmaster/walwriter.h b/src/include/postmaster/walwriter.h index 5884d69fed1..4d880afd821 100644 --- a/src/include/postmaster/walwriter.h +++ b/src/include/postmaster/walwriter.h @@ -18,6 +18,6 @@ extern PGDLLIMPORT int WalWriterDelay; extern PGDLLIMPORT int WalWriterFlushAfter; -extern void WalWriterMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void WalWriterMain(char *startup_data, size_t startup_data_len); #endif /* _WALWRITER_H */ diff --git a/src/include/replication/slotsync.h b/src/include/replication/slotsync.h index e03c2a005a4..19670d5cea9 100644 --- a/src/include/replication/slotsync.h +++ b/src/include/replication/slotsync.h @@ -26,7 +26,7 @@ extern PGDLLIMPORT char *PrimarySlotName; extern char *CheckAndGetDbnameFromConninfo(void); extern bool ValidateSlotSyncParams(int elevel); -extern void ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len); extern void ShutDownSlotSync(void); extern bool SlotSyncWorkerCanRestart(void); diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h index 3342286d2a3..18cf8fc93ab 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -486,7 +486,7 @@ walrcv_clear_result(WalRcvExecResult *walres) } /* prototypes for functions in walreceiver.c */ -extern void WalReceiverMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void WalReceiverMain(char *startup_data, size_t startup_data_len); extern void ProcessWalRcvInterrupts(void); extern void WalRcvForceReply(void); diff --git a/src/include/replication/walsender_private.h b/src/include/replication/walsender_private.h index 9a9c40d6f34..335303b7360 100644 --- a/src/include/replication/walsender_private.h +++ b/src/include/replication/walsender_private.h @@ -132,7 +132,7 @@ typedef void *yyscan_t; #endif extern int replication_yyparse(yyscan_t yyscanner); extern int replication_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner); -extern void replication_yyerror(yyscan_t yyscanner, const char *message) pg_attribute_noreturn(); +pg_noreturn extern void replication_yyerror(yyscan_t yyscanner, const char *message); extern void replication_scanner_init(const char *str, yyscan_t *yyscannerp); extern void replication_scanner_finish(yyscan_t yyscanner); extern bool replication_scanner_is_replication_command(yyscan_t yyscanner); diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index b2d062781ec..5c5b692445c 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -65,7 +65,7 @@ typedef void (*shmem_startup_hook_type) (void); extern PGDLLIMPORT bool proc_exit_inprogress; extern PGDLLIMPORT bool shmem_exit_inprogress; -extern void proc_exit(int code) pg_attribute_noreturn(); +pg_noreturn extern void proc_exit(int code); extern void shmem_exit(int code); extern void on_proc_exit(pg_on_exit_callback function, Datum arg); extern void on_shmem_exit(pg_on_exit_callback function, Datum arg); diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index 787f3db06a9..4e29881ca3e 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -605,7 +605,7 @@ extern void lock_twophase_standby_recover(TransactionId xid, uint16 info, extern DeadLockState DeadLockCheck(PGPROC *proc); extern PGPROC *GetBlockingAutoVacuumPgproc(void); -extern void DeadLockReport(void) pg_attribute_noreturn(); +pg_noreturn extern void DeadLockReport(void); extern void RememberSimpleDeadLock(PGPROC *proc1, LOCKMODE lockmode, LOCK *lock, diff --git a/src/include/tcop/backend_startup.h b/src/include/tcop/backend_startup.h index 993b013afdd..8cc6cd2bf67 100644 --- a/src/include/tcop/backend_startup.h +++ b/src/include/tcop/backend_startup.h @@ -39,6 +39,6 @@ typedef struct BackendStartupData CAC_state canAcceptConnections; } BackendStartupData; -extern void BackendMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn(); +pg_noreturn extern void BackendMain(char *startup_data, size_t startup_data_len); #endif /* BACKEND_STARTUP_H */ diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h index 3c6ed917e17..b3060e0a430 100644 --- a/src/include/tcop/tcopprot.h +++ b/src/include/tcop/tcopprot.h @@ -69,19 +69,19 @@ extern List *pg_plan_queries(List *querytrees, const char *query_string, ParamListInfo boundParams); extern void die(SIGNAL_ARGS); -extern void quickdie(SIGNAL_ARGS) pg_attribute_noreturn(); +pg_noreturn extern void quickdie(SIGNAL_ARGS); extern void StatementCancelHandler(SIGNAL_ARGS); -extern void FloatExceptionHandler(SIGNAL_ARGS) pg_attribute_noreturn(); +pg_noreturn extern void FloatExceptionHandler(SIGNAL_ARGS); extern void HandleRecoveryConflictInterrupt(ProcSignalReason reason); extern void ProcessClientReadInterrupt(bool blocked); extern void ProcessClientWriteInterrupt(bool blocked); extern void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname); -extern void PostgresSingleUserMain(int argc, char *argv[], - const char *username) pg_attribute_noreturn(); -extern void PostgresMain(const char *dbname, - const char *username) pg_attribute_noreturn(); +pg_noreturn extern void PostgresSingleUserMain(int argc, char *argv[], + const char *username); +pg_noreturn extern void PostgresMain(const char *dbname, + const char *username); extern void ResetUsage(void); extern void ShowUsage(const char *title); extern int check_log_duration(char *msec_str, bool was_logged); diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index e54eca5b489..73e3716bae1 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -415,17 +415,8 @@ extern PGDLLIMPORT ErrorContextCallback *error_context_stack; error_context_stack = _save_context_stack##__VA_ARGS__; \ } while (0) -/* - * Some compilers understand pg_attribute_noreturn(); for other compilers, - * insert pg_unreachable() so that the compiler gets the point. - */ -#ifdef HAVE_PG_ATTRIBUTE_NORETURN #define PG_RE_THROW() \ pg_re_throw() -#else -#define PG_RE_THROW() \ - (pg_re_throw(), pg_unreachable()) -#endif extern PGDLLIMPORT sigjmp_buf *PG_exception_stack; @@ -476,9 +467,9 @@ extern void EmitErrorReport(void); extern ErrorData *CopyErrorData(void); extern void FreeErrorData(ErrorData *edata); extern void FlushErrorState(void); -extern void ReThrowError(ErrorData *edata) pg_attribute_noreturn(); +pg_noreturn extern void ReThrowError(ErrorData *edata); extern void ThrowErrorData(ErrorData *edata); -extern void pg_re_throw(void) pg_attribute_noreturn(); +pg_noreturn extern void pg_re_throw(void); extern char *GetErrorContextStack(void); diff --git a/src/include/utils/float.h b/src/include/utils/float.h index 7d1badd292a..96d4f7effbc 100644 --- a/src/include/utils/float.h +++ b/src/include/utils/float.h @@ -37,9 +37,9 @@ extern PGDLLIMPORT int extra_float_digits; /* * Utility functions in float.c */ -extern void float_overflow_error(void) pg_attribute_noreturn(); -extern void float_underflow_error(void) pg_attribute_noreturn(); -extern void float_zero_divide_error(void) pg_attribute_noreturn(); +pg_noreturn extern void float_overflow_error(void); +pg_noreturn extern void float_underflow_error(void); +pg_noreturn extern void float_zero_divide_error(void); extern int is_infinite(float8 val); extern float8 float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, diff --git a/src/include/utils/help_config.h b/src/include/utils/help_config.h index c27a54f1b91..38d92eac803 100644 --- a/src/include/utils/help_config.h +++ b/src/include/utils/help_config.h @@ -12,6 +12,6 @@ #ifndef HELP_CONFIG_H #define HELP_CONFIG_H 1 -extern void GucInfoMain(void) pg_attribute_noreturn(); +pg_noreturn extern void GucInfoMain(void); #endif diff --git a/src/include/utils/memutils_internal.h b/src/include/utils/memutils_internal.h index 5ce2d9b5877..eecb0aabd75 100644 --- a/src/include/utils/memutils_internal.h +++ b/src/include/utils/memutils_internal.h @@ -160,8 +160,8 @@ extern void MemoryContextCreate(MemoryContext node, extern void *MemoryContextAllocationFailure(MemoryContext context, Size size, int flags); -extern void MemoryContextSizeFailure(MemoryContext context, Size size, - int flags) pg_attribute_noreturn(); +pg_noreturn extern void MemoryContextSizeFailure(MemoryContext context, Size size, + int flags); static inline void MemoryContextCheckSize(MemoryContext context, Size size, int flags) diff --git a/src/interfaces/ecpg/preproc/preproc_extern.h b/src/interfaces/ecpg/preproc/preproc_extern.h index a60b0381fbb..2c89e30621e 100644 --- a/src/interfaces/ecpg/preproc/preproc_extern.h +++ b/src/interfaces/ecpg/preproc/preproc_extern.h @@ -89,7 +89,7 @@ extern char *cat_str(int count,...); extern char *make2_str(const char *str1, const char *str2); extern char *make3_str(const char *str1, const char *str2, const char *str3); extern void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3, 4); -extern void mmfatal(int error_code, const char *error,...) pg_attribute_printf(2, 3) pg_attribute_noreturn(); +pg_noreturn extern void mmfatal(int error_code, const char *error,...) pg_attribute_printf(2, 3); extern void output_get_descr_header(const char *desc_name); extern void output_get_descr(const char *desc_name, const char *index); extern void output_set_descr_header(const char *desc_name); diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h index 50c3b28472b..15904c08a4b 100644 --- a/src/pl/plpgsql/src/plpgsql.h +++ b/src/pl/plpgsql/src/plpgsql.h @@ -1326,7 +1326,7 @@ extern int plpgsql_peek(void); extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc, int *tok2_loc); extern int plpgsql_scanner_errposition(int location); -extern void plpgsql_yyerror(const char *message) pg_attribute_noreturn(); +pg_noreturn extern void plpgsql_yyerror(const char *message); extern int plpgsql_location_to_lineno(int location); extern int plpgsql_latest_lineno(void); extern void plpgsql_scanner_init(const char *str); diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index 1323e4c598d..8afbcbbe084 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -24,7 +24,7 @@ static void exit_nicely(PGconn *conn); -static void pg_attribute_noreturn() pg_fatal_impl(int line, const char *fmt,...) +pg_noreturn static void pg_fatal_impl(int line, const char *fmt,...) pg_attribute_printf(2, 3); static bool process_result(PGconn *conn, PGresult *res, int results, int numsent); @@ -71,8 +71,7 @@ exit_nicely(PGconn *conn) * Print an error to stderr and terminate the program. */ #define pg_fatal(...) pg_fatal_impl(__LINE__, __VA_ARGS__) -static void -pg_attribute_noreturn() +pg_noreturn static void pg_fatal_impl(int line, const char *fmt,...) { va_list args; diff --git a/src/test/modules/test_shm_mq/test_shm_mq.h b/src/test/modules/test_shm_mq/test_shm_mq.h index 0ae7bd64cd0..854bdd46bc2 100644 --- a/src/test/modules/test_shm_mq/test_shm_mq.h +++ b/src/test/modules/test_shm_mq/test_shm_mq.h @@ -40,6 +40,6 @@ extern void test_shm_mq_setup(int64 queue_size, int32 nworkers, shm_mq_handle **input); /* Main entrypoint for a worker. */ -extern PGDLLEXPORT void test_shm_mq_main(Datum) pg_attribute_noreturn(); +pg_noreturn extern PGDLLEXPORT void test_shm_mq_main(Datum); #endif diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c index d4403b24d98..04c2955e3fc 100644 --- a/src/test/modules/worker_spi/worker_spi.c +++ b/src/test/modules/worker_spi/worker_spi.c @@ -44,7 +44,7 @@ PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(worker_spi_launch); -PGDLLEXPORT void worker_spi_main(Datum main_arg) pg_attribute_noreturn(); +PGDLLEXPORT pg_noreturn void worker_spi_main(Datum main_arg); /* GUC variables */ static int worker_spi_naptime = 10; diff --git a/src/timezone/zic.c b/src/timezone/zic.c index d605c721ecf..3b70b888180 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -117,11 +117,11 @@ extern int link(const char *target, const char *linkname); (itssymlink(target) ? (errno = ENOTSUP, -1) : link(target, linkname)) #endif -static void memory_exhausted(const char *msg) pg_attribute_noreturn(); +pg_noreturn static void memory_exhausted(const char *msg); static void verror(const char *string, va_list args) pg_attribute_printf(1, 0); static void error(const char *string,...) pg_attribute_printf(1, 2); static void warning(const char *string,...) pg_attribute_printf(1, 2); -static void usage(FILE *stream, int status) pg_attribute_noreturn(); +pg_noreturn static void usage(FILE *stream, int status); static void addtt(zic_t starttime, int type); static int addtype(zic_t utoff, char const *abbr, bool isdst, bool ttisstd, bool ttisut); diff --git a/src/tools/pg_bsd_indent/err.h b/src/tools/pg_bsd_indent/err.h index a3e8f978255..1083462088e 100644 --- a/src/tools/pg_bsd_indent/err.h +++ b/src/tools/pg_bsd_indent/err.h @@ -37,9 +37,9 @@ * This is cut down to just the minimum that we need to build indent. */ -void err(int, const char *, ...) - pg_attribute_noreturn() pg_attribute_printf(2, 3); -void errx(int, const char *, ...) - pg_attribute_noreturn() pg_attribute_printf(2, 3); +pg_noreturn void err(int, const char *, ...) + pg_attribute_printf(2, 3); +pg_noreturn void errx(int, const char *, ...) + pg_attribute_printf(2, 3); #endif /* !_ERR_H_ */ base-commit: d85ce012f99f63249bb45a78fcecb7a2383920b1 -- 2.47.1