pg_noreturn to replace pg_attribute_noreturn()
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 13 Mar 2025 11:25:14 +0000 (12:25 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 13 Mar 2025 11:37:26 +0000 (12:37 +0100)
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".

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.  In one case,
we can make up for it by adding the pg_noreturn to a wrapper function
and adding a pg_unreachable(), in the other case, the latter was
already done before.

Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/pxr5b3z7jmkpenssra5zroxi7qzzp6eswuggokw64axmdixpnk@zbwxuq7gbbcw

54 files changed:
contrib/dblink/dblink.c
contrib/pgcrypto/px.h
src/backend/access/transam/xlogrecovery.c
src/backend/backup/basebackup_incremental.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/launch_backend.c
src/backend/postmaster/postmaster.c
src/backend/replication/logical/tablesync.c
src/backend/replication/walsender.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/fmgr/dfmgr.c
src/backend/utils/hash/dynahash.c
src/backend/utils/mmgr/slab.c
src/bin/pg_combinebackup/load_manifest.c
src/bin/pg_dump/pg_backup_utils.h
src/bin/pg_upgrade/pg_upgrade.h
src/bin/pg_verifybackup/pg_verifybackup.c
src/bin/pg_verifybackup/pg_verifybackup.h
src/bin/pgbench/pgbench.h
src/common/parse_manifest.c
src/include/bootstrap/bootstrap.h
src/include/c.h
src/include/commands/defrem.h
src/include/common/parse_manifest.h
src/include/mb/pg_wchar.h
src/include/parser/parse_relation.h
src/include/parser/scanner.h
src/include/postmaster/autovacuum.h
src/include/postmaster/bgworker_internals.h
src/include/postmaster/bgwriter.h
src/include/postmaster/pgarch.h
src/include/postmaster/postmaster.h
src/include/postmaster/startup.h
src/include/postmaster/syslogger.h
src/include/postmaster/walsummarizer.h
src/include/postmaster/walwriter.h
src/include/replication/slotsync.h
src/include/replication/walreceiver.h
src/include/replication/walsender_private.h
src/include/storage/ipc.h
src/include/storage/lock.h
src/include/tcop/backend_startup.h
src/include/tcop/tcopprot.h
src/include/utils/elog.h
src/include/utils/float.h
src/include/utils/help_config.h
src/include/utils/memutils_internal.h
src/interfaces/ecpg/preproc/preproc_extern.h
src/pl/plpgsql/src/plpgsql.h
src/test/modules/libpq_pipeline/libpq_pipeline.c
src/test/modules/test_shm_mq/test_shm_mq.h
src/test/modules/worker_spi/worker_spi.c
src/timezone/zic.c
src/tools/pg_bsd_indent/err.h

index bed2dee3d72bb1b5d9485a1a37f6746579780e96..58c1a6221c80b74be24f398c5aece85de2abb62d 100644 (file)
@@ -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)
index 37013cd9f82a97fb6442e8829ff4bf65bfdb5e7b..4b81fceab8ec2948f7d9ec9834a665dd5735f38f 100644 (file)
@@ -181,7 +181,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);
index a829a055a97fe67bfac3f4dddc40d33bff5416fe..2c19013c98b27b418f6257e9ca862bf9856a02d9 100644 (file)
@@ -4778,8 +4778,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,
index c2b7a55e347d12cf5bb6161e6283b8bb04608771..76a580686658ceac72774f7600992ab0bf537a08 100644 (file)
@@ -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);
 
 /*
index 800815dfbcc3a5b635306b26c54bd626af129b32..71c34027c88700875830b2191c5f81a0b5f8439b 100644 (file)
@@ -317,7 +317,7 @@ int         AutovacuumLauncherPid = 0;
 
 static Oid do_start_worker(void);
 static void ProcessAutoVacLauncherInterrupts(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);
index ecd04655c2a4b0b1bcb081dd512518fde36312b1..77fb877dbad67b0bde9ab9d631a47d10715cd54b 100644 (file)
@@ -171,7 +171,7 @@ static pid_t internal_forkexec(const char *child_kind, int child_slot,
 typedef struct
 {
    const char *name;
-   void        (*main_fn) (const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+   void        (*main_fn) (const void *startup_data, size_t startup_data_len);
    bool        shmem_attach;
 } child_process_kind;
 
index 57155c00e017b26d6b473b52adb7f02674be899b..d13846298bd56b0f27d2fdf724c41013c5cee7cb 100644 (file)
@@ -425,7 +425,7 @@ static void LogChildExit(int lev, const char *procname,
 static void PostmasterStateMachine(void);
 static void UpdatePMState(PMState newState);
 
-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);
index 6af5c9fe16c45386709a4edab6aa381a6f9f14d3..65b98aa905fe771961690046108481c9ebd3381f 100644 (file)
@@ -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)
 {
    /*
index 446d10c1a7d7a2e84fea286dc4a6cd1adec3aa35..d96121b3aad4225b442c6c2923a6e59d98c2d045 100644 (file)
@@ -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);
index 8473448849cfce6d54117ce6cbf1f19537fe0040..c4ff18ce65ebe35840563e57b98d96c403c84474 100644 (file)
@@ -235,10 +235,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);
 
 
 /*
index 87b233cb8871eb772dc5aa89ce0fea0376d7b45d..4409e3e6fa8ab059d05ef18b03e3374a751b6a62 100644 (file)
@@ -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);
index cd5a00132fc31f416cd346d3b3d88add03e48434..3f25929f2d81199b650c6ae1064f7c71b08b6871 100644 (file)
@@ -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);
index ec8eddad8632e703461b6416cd9300b253326dbe..d32c0d318fbf4a23713e1760e5b40c097723bb9b 100644 (file)
@@ -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;
index 485fe518e4127e1877a848becc606701097287ad..8e0d04a26a6a73d5b14e773f7260b3711dca8a16 100644 (file)
@@ -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
index 38551944513057f31bcb147ad5eae0098c2a3660..ba042016879d47c66e897d8960658df24db94375 100644 (file)
@@ -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
index f4e375d27c78225f87544a439cffd72c9d47b3d3..4c9d0172149116a5c3916039d36d28a23b508602 100644 (file)
@@ -481,7 +481,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);
index 7c720ab98bdc84ddedcfb1f092b00216fef0df1e..84edd2cdca5cd07450fdc5005e6b034a48baa1db 100644 (file)
@@ -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,
index 622c9d82a8126967e569cb29ee8036fd5cee7a84..8cb6f9c53ad854f394ba777632da3bb539784f1c 100644 (file)
@@ -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);
 
index 0ba216e5f72be4abae7216ecdf9e43752f0a377c..e053c9e2eb63db46301ac8fab4aea2f39cde0230 100644 (file)
@@ -140,9 +140,9 @@ struct PgBenchExprList
 
 extern int expr_yyparse(PgBenchExpr **expr_parse_result_p, yyscan_t yyscanner);
 extern int expr_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner);
-extern void expr_yyerror(PgBenchExpr **expr_parse_result_p, 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(PgBenchExpr **expr_parse_result_p, 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,
@@ -153,9 +153,9 @@ extern char *expr_scanner_get_substring(PsqlScanState state,
                                        int start_offset,
                                        bool chomp);
 
-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);
index 05858578207784016c6e0cb79ce537685c6e5548..71973af199b9082382b443bd6f5b79cc4a957e89 100644 (file)
@@ -114,8 +114,8 @@ static void json_manifest_finalize_wal_range(JsonManifestParseState *parse);
 static void verify_manifest_checksum(JsonManifestParseState *parse,
                                     const char *buffer, size_t size,
                                     pg_cryptohash_ctx *incr_ctx);
-static void json_manifest_parse_failure(JsonManifestParseContext *context,
-                                       char *msg);
+pg_noreturn static void json_manifest_parse_failure(JsonManifestParseContext *context,
+                                                   char *msg);
 
 static int hexdecode_char(char c);
 static bool hexdecode_string(uint8 *result, char *input, int nbytes);
@@ -889,6 +889,7 @@ static void
 json_manifest_parse_failure(JsonManifestParseContext *context, char *msg)
 {
    context->error_cb(context, "could not parse backup manifest: %s", msg);
+   pg_unreachable();
 }
 
 /*
index 69f3d31a4ef0a9afbe209e0b6418c45c1644c892..befc4fa1b3d87329940896d44ea81c9ebfb71ade 100644 (file)
@@ -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 */
index a14c6315162dec35ecade3fb1975da0bf27e73e9..94971474154aff523d4058825233b236373bfb56 100644 (file)
 #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 <stdnoreturn.h>.
+ *
+ * In a declaration, function specifiers go before the function name.  The
+ * common style is to put them before the return type.  (The MSVC fallback has
+ * the same requirement.  The GCC fallback is more flexible.)
+ */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define pg_noreturn _Noreturn
+#elif defined(__GNUC__) || defined(__SUNPRO_C)
+#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!
 #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
 
 /*
@@ -858,8 +872,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
 
 /*
index 6d9348bac8049dfa682a35fdea715504e16d6393..dd22b5efdfd91814f3c53ab2012c926523f1247b 100644 (file)
@@ -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 */
index 255cab5c2a9a33622adbda1422f643ef38d4dc48..6172d1d52244ebcdc15d56db3e54efd0c0b6549f 100644 (file)
@@ -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
 {
index ff7983ee90a3e82e6e386a0e70f2f2c7e062d573..bfef95baea2c841b6f435f3e5c2f7eafb142ddcb 100644 (file)
@@ -768,9 +768,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,
index 3ece5cd4eef9736be5ad34edf3df44d56e767fab..d59599cf2424eadfe38ebcbe2b0052b7dab6a731 100644 (file)
@@ -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,
                      VarReturningType returning_type,
                      int location, bool include_dropped,
index 74ad86698acbd2384ca08aa701d5be56045226bf..8d202d5b2848a0b3d530f20fd5d0cba4aa8a76b1 100644 (file)
@@ -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 */
index 6a95e5f55bdfa70daf0cf74595ae2a114f795ac6..e8135f41a1c24dd7bba73693983552635ed24f74 100644 (file)
@@ -58,8 +58,8 @@ extern void autovac_init(void);
 /* called from postmaster when a worker could not be forked */
 extern void AutoVacWorkerFailed(void);
 
-extern void AutoVacLauncherMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
-extern void AutoVacWorkerMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void AutoVacLauncherMain(const void *startup_data, size_t startup_data_len);
+pg_noreturn extern void AutoVacWorkerMain(const void *startup_data, size_t startup_data_len);
 
 extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type,
                                  Oid relationId, BlockNumber blkno);
index 29e6f44cf087e0fc7e9f9025ff9718ff5b1e2ecf..26cbc821edfbd4d1d516902548a2c793b557067c 100644 (file)
@@ -52,6 +52,6 @@ extern void ForgetUnstartedBackgroundWorkers(void);
 extern void ResetBackgroundWorkerCrashTimes(void);
 
 /* Entry point for background worker processes */
-extern void BackgroundWorkerMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void BackgroundWorkerMain(const void *startup_data, size_t startup_data_len);
 
 #endif                         /* BGWORKER_INTERNALS_H */
index 4fd717169f0660a75f3cebccc152f40a1ce9d0ba..800ecbfd13b318be381d73806ff1c94250a30b4e 100644 (file)
@@ -27,8 +27,8 @@ extern PGDLLIMPORT int CheckPointTimeout;
 extern PGDLLIMPORT int CheckPointWarning;
 extern PGDLLIMPORT double CheckPointCompletionTarget;
 
-extern void BackgroundWriterMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
-extern void CheckpointerMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void BackgroundWriterMain(const void *startup_data, size_t startup_data_len);
+pg_noreturn extern void CheckpointerMain(const void *startup_data, size_t startup_data_len);
 
 extern void RequestCheckpoint(int flags);
 extern void CheckpointWriteDelay(int flags, double progress);
index a32d78feb27a1980bfc7a74eaaee978ee6ca66fc..ef7b12520861f71dcaeed2a3f56d99a993a8007b 100644 (file)
@@ -29,7 +29,7 @@
 extern Size PgArchShmemSize(void);
 extern void PgArchShmemInit(void);
 extern bool PgArchCanRestart(void);
-extern void PgArchiverMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void PgArchiverMain(const void *startup_data, size_t startup_data_len);
 extern void PgArchWakeup(void);
 extern void PgArchForceDirScan(void);
 
index aa786bfacf360bd0fc477db7c1f4ac692ebcebf1..39566ee2bd51c3981858d540b59d52adef03dcb7 100644 (file)
@@ -90,7 +90,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);
 
@@ -113,7 +113,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 */
index 158f52255a6621db7f52db880dc86ba9d7fe523d..ec2c8d3bff56bd02e564196372a5f5bbc20133e1 100644 (file)
@@ -26,7 +26,7 @@
 extern PGDLLIMPORT int log_startup_progress_interval;
 
 extern void ProcessStartupProcInterrupts(void);
-extern void StartupProcessMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void StartupProcessMain(const void *startup_data, size_t startup_data_len);
 extern void PreRestoreCommand(void);
 extern void PostRestoreCommand(void);
 extern bool IsPromoteSignaled(void);
index 197d8e43fdd1f09b48f57297773a91364cfe213c..15fca58ff5dd28ce376acd80819febb092a1c213 100644 (file)
@@ -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(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void SysLoggerMain(const void *startup_data, size_t startup_data_len);
 
 extern bool CheckLogrotateSignal(void);
 extern void RemoveLogrotateSignalFiles(void);
index e1086d02c8bfa0942cd3a40cc6d68189cd1ec541..34dda607c6931c624fc31994ea85a0ea6b7df7fd 100644 (file)
@@ -21,7 +21,7 @@ extern PGDLLIMPORT int wal_summary_keep_time;
 
 extern Size WalSummarizerShmemSize(void);
 extern void WalSummarizerShmemInit(void);
-extern void WalSummarizerMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void WalSummarizerMain(const void *startup_data, size_t startup_data_len);
 
 extern void GetWalSummarizerState(TimeLineID *summarized_tli,
                                  XLogRecPtr *summarized_lsn,
index ea8c22b174fe82b70880aabf66632de4e7f78ec3..58e5c913d5ab69670711a266a3bf958e9dabb6d4 100644 (file)
@@ -18,6 +18,6 @@
 extern PGDLLIMPORT int WalWriterDelay;
 extern PGDLLIMPORT int WalWriterFlushAfter;
 
-extern void WalWriterMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void WalWriterMain(const void *startup_data, size_t startup_data_len);
 
 #endif                         /* _WALWRITER_H */
index 6cde7f81cec6c41dea2d4bdfaccaa717279e625c..16b721463dde6b9cf5eaaeda03dcfbae85f1b35a 100644 (file)
@@ -26,7 +26,7 @@ extern PGDLLIMPORT char *PrimarySlotName;
 extern char *CheckAndGetDbnameFromConninfo(void);
 extern bool ValidateSlotSyncParams(int elevel);
 
-extern void ReplSlotSyncWorkerMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void ReplSlotSyncWorkerMain(const void *startup_data, size_t startup_data_len);
 
 extern void ShutDownSlotSync(void);
 extern bool SlotSyncWorkerCanRestart(void);
index 992be93cce84afffcb8d3e3bc7bfcae8df422740..ecca21fecb4c7d07206de2554f25242c2a62a06d 100644 (file)
@@ -486,7 +486,7 @@ walrcv_clear_result(WalRcvExecResult *walres)
 }
 
 /* prototypes for functions in walreceiver.c */
-extern void WalReceiverMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void WalReceiverMain(const void *startup_data, size_t startup_data_len);
 extern void ProcessWalRcvInterrupts(void);
 extern void WalRcvForceReply(void);
 
index 814b812432a31d12e521d2d08229c948b0c6f29e..0fc77f1b4af7ef41b83fcf3af847d1f9009d7f0f 100644 (file)
@@ -132,7 +132,7 @@ typedef void *yyscan_t;
 #endif
 extern int replication_yyparse(Node **replication_parse_result_p, yyscan_t yyscanner);
 extern int replication_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner);
-extern void replication_yyerror(Node **replication_parse_result_p, yyscan_t yyscanner, const char *message) pg_attribute_noreturn();
+pg_noreturn extern void replication_yyerror(Node **replication_parse_result_p, 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);
index e0f5f92e947ecd6807b6c1892b7f915a151c3f03..3baf418b3d1ed999b3a87666c20e04576a124fef 100644 (file)
@@ -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);
index 1076995518faf1ba66cb4323a9c4ba63b9ce39e1..c0c0b0f7a2d1c46057b807b7189556312ce43007 100644 (file)
@@ -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,
index 2912ef802889f73dbb75bef941a10ef8b097a780..578828c1cafc9e187f82aabd087495f8a3e46c09 100644 (file)
@@ -117,6 +117,6 @@ typedef struct ConnectionTiming
    TimestampTz auth_end;
 } ConnectionTiming;
 
-extern void BackendMain(const void *startup_data, size_t startup_data_len) pg_attribute_noreturn();
+pg_noreturn extern void BackendMain(const void *startup_data, size_t startup_data_len);
 
 #endif                         /* BACKEND_STARTUP_H */
index a62367f7793dc0997d2ee67c36c67227f1c53b5c..a83cc4f48501601d7b51b4178effc4aa11cf111f 100644 (file)
@@ -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);
index a0244bff1fc634092e9e0c74a89b1a3c39ea50e6..855c147325b237866d667c7e0fb2088205b2810d 100644 (file)
@@ -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);
 
index 9233fa479c6672cd7d438c59d367f07c8791363f..0e2e9ec53478319806092adb9cab7d8d7fa7bef2 100644 (file)
@@ -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,
index d4f26eb49d0533a65d78b6e81bb80a238e41f2be..4e58f130054e09fff1072928205662355ce9ca45 100644 (file)
@@ -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
index 693650353c67b567de7521df223b39814e888a6a..a6caa6335e34abb519649f6c05ae9c480deddf44 100644 (file)
@@ -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)
index a60b0381fbb39541cf8a07f788b93e59c1864e60..2c89e30621ed062033d0169fc22a5205edddefb2 100644 (file)
@@ -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);
index d73996e09c07efd1ca511979002fbc076181c441..aea0d0f98b2977ddcfcc37f0aa1469938a6f0289 100644 (file)
@@ -1354,7 +1354,7 @@ extern int    plpgsql_peek(yyscan_t yyscanner);
 extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc,
                          int *tok2_loc, yyscan_t yyscanner);
 extern int plpgsql_scanner_errposition(int location, yyscan_t yyscanner);
-extern void plpgsql_yyerror(YYLTYPE *yyllocp, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner, const char *message) pg_attribute_noreturn();
+pg_noreturn extern void plpgsql_yyerror(YYLTYPE *yyllocp, PLpgSQL_stmt_block **plpgsql_parse_result_p, yyscan_t yyscanner, const char *message);
 extern int plpgsql_location_to_lineno(int location, yyscan_t yyscanner);
 extern int plpgsql_latest_lineno(yyscan_t yyscanner);
 extern yyscan_t plpgsql_scanner_init(const char *str);
index 7ff18e91e6615e1175ba40617e474a37c26712d7..ac9ac95135f381609b7eec9cecd522e3f50c3314 100644 (file)
@@ -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;
index 9ad9f63b44e388c6325a6d887d2cb711a06c12fc..5346557d473c4f83748c1130cad8f3a0e0d81d2a 100644 (file)
@@ -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
index 5b87d4f7038de0e9d1ac8bd0343748d950175ea4..9c53d896b6ae5b8505c4a86e5188a20259f7b0e1 100644 (file)
@@ -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;
index d605c721ecf703379d0b990a1b04187dd5989cce..3b70b8881805fd163cd9252cc861f76201b6704f 100644 (file)
@@ -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);
index a3e8f9782557237a73fd58cf7b2fe072d72d6e33..1083462088e2b25389e477a8c8187e56607fee17 100644 (file)
@@ -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_ */