From ea437a691b3ee2ab1ed1b1deb5aa4ef6ee230d06 Mon Sep 17 00:00:00 2001 From: Oldes Huhuman Date: Fri, 26 Apr 2024 23:31:52 +0200 Subject: [PATCH] CHANGE: use `noreturn` attribute in `Trap*` functions and mark these as DEAD_END to silence compiler warnings --- src/core/c-error.c | 49 +++++++++++++++++++++++++------------ src/core/d-crash.c | 6 ++--- src/core/f-stubs.c | 6 +---- src/core/n-data.c | 4 +-- src/core/p-checksum.c | 3 +-- src/core/p-crypt.c | 4 +-- src/core/p-net.c | 2 +- src/core/t-char.c | 2 +- src/core/t-gob.c | 2 +- src/core/t-struct.c | 4 +-- src/core/t-vector.c | 2 +- src/core/u-bincode.c | 3 +-- src/core/u-compress.c | 5 +--- src/core/u-png-filter.c | 3 +-- src/include/reb-c.h | 38 +++++++++++++++++++++++----- src/include/sys-core.h | 3 +-- src/include/sys-int-funcs.h | 8 ------ 17 files changed, 81 insertions(+), 63 deletions(-) diff --git a/src/core/c-error.c b/src/core/c-error.c index eb9b6ae334..0f873c6325 100644 --- a/src/core/c-error.c +++ b/src/core/c-error.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -504,124 +505,135 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot /*********************************************************************** ** -*/ void Trap0(REBCNT num) +*/ REB_NORETURN void Trap0(REBCNT num) /* ***********************************************************************/ { Throw_Error(Make_Error(num, 0, 0, 0)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap1(REBCNT num, REBVAL *arg1) +*/ REB_NORETURN void Trap1(REBCNT num, REBVAL *arg1) /* ***********************************************************************/ { Throw_Error(Make_Error(num, arg1, 0, 0)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap2(REBCNT num, REBVAL *arg1, REBVAL *arg2) +*/ REB_NORETURN void Trap2(REBCNT num, REBVAL *arg1, REBVAL *arg2) /* ***********************************************************************/ { Throw_Error(Make_Error(num, arg1, arg2, 0)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap3(REBCNT num, REBVAL *arg1, REBVAL *arg2, REBVAL *arg3) +*/ REB_NORETURN void Trap3(REBCNT num, REBVAL *arg1, REBVAL *arg2, REBVAL *arg3) /* ***********************************************************************/ { Throw_Error(Make_Error(num, arg1, arg2, arg3)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Arg(REBVAL *arg) +*/ REB_NORETURN void Trap_Arg(REBVAL *arg) /* ***********************************************************************/ { Trap1(RE_INVALID_ARG, arg); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Type(REBVAL *arg) +*/ REB_NORETURN void Trap_Type(REBVAL *arg) /* ** type is not allowed here ** ***********************************************************************/ { Trap1(RE_INVALID_TYPE, Of_Type(arg)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Range(REBVAL *arg) +*/ REB_NORETURN void Trap_Range(REBVAL *arg) /* ** value out of range: ** ***********************************************************************/ { Trap1(RE_OUT_OF_RANGE, arg); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Word(REBCNT num, REBCNT sym, REBVAL *arg) +*/ REB_NORETURN void Trap_Word(REBCNT num, REBCNT sym, REBVAL *arg) /* ***********************************************************************/ { Init_Word(DS_TOP, sym); if (arg) Trap2(num, DS_TOP, arg); else Trap1(num, DS_TOP); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Action(REBCNT type, REBCNT action) +*/ REB_NORETURN void Trap_Action(REBCNT type, REBCNT action) /* ***********************************************************************/ { Trap2(RE_CANNOT_USE, Get_Action_Word(action), Get_Type(type)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Math_Args(REBCNT type, REBCNT action) +*/ REB_NORETURN void Trap_Math_Args(REBCNT type, REBCNT action) /* ***********************************************************************/ { Trap2(RE_NOT_RELATED, Get_Action_Word(action), Get_Type(type)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Types(REBCNT errnum, REBCNT type1, REBCNT type2) +*/ REB_NORETURN void Trap_Types(REBCNT errnum, REBCNT type1, REBCNT type2) /* ***********************************************************************/ { if (type2 != 0) Trap2(errnum, Get_Type(type1), Get_Type(type2)); Trap1(errnum, Get_Type(type1)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Expect(REBVAL *object, REBCNT index, REBCNT type) +*/ REB_NORETURN void Trap_Expect(REBVAL *object, REBCNT index, REBCNT type) /* ** Object field is not of expected type. ** PORT expected SCHEME of OBJECT type @@ -629,43 +641,47 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot ***********************************************************************/ { Trap3(RE_EXPECT_TYPE, Of_Type(object), Obj_Word(object, index), Get_Type(type)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Make(REBCNT type, REBVAL *spec) +*/ REB_NORETURN void Trap_Make(REBCNT type, REBVAL *spec) /* ***********************************************************************/ { Trap2(RE_BAD_MAKE_ARG, Get_Type(type), spec); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Num(REBCNT err, REBCNT num) +*/ REB_NORETURN void Trap_Num(REBCNT err, REBCNT num) /* ***********************************************************************/ { DS_PUSH_INTEGER(num); Trap1(err, DS_TOP); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Reflect(REBCNT type, REBVAL *arg) +*/ REB_NORETURN void Trap_Reflect(REBCNT type, REBVAL *arg) /* ***********************************************************************/ { Trap2(RE_CANNOT_USE, arg, Get_Type(type)); + DEAD_END; } /*********************************************************************** ** -*/ void Trap_Port(REBCNT errnum, REBSER *port, REBINT err_code) +*/ REB_NORETURN void Trap_Port(REBCNT errnum, REBSER *port, REBINT err_code) /* ***********************************************************************/ { @@ -679,6 +695,7 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot DS_PUSH_INTEGER(-err_code); Trap2(errnum, val, DS_TOP); + DEAD_END; } diff --git a/src/core/d-crash.c b/src/core/d-crash.c index d78eb0e2cc..09bf604707 100644 --- a/src/core/d-crash.c +++ b/src/core/d-crash.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Developers +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -121,8 +121,8 @@ enum Crash_Msg_Nums { #else OS_CRASH(Crash_Msgs[CM_ERROR], buf); #endif - // will not reach here, but... - abort(); // just to silent the function declared 'noreturn' should not return warning + // will not reach here... + DEAD_END; } /*********************************************************************** diff --git a/src/core/f-stubs.c b/src/core/f-stubs.c index ced23a8312..985fd3fe07 100644 --- a/src/core/f-stubs.c +++ b/src/core/f-stubs.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -172,7 +173,6 @@ return n; Trap_Range(val); - return 0; } @@ -186,7 +186,6 @@ if (IS_DECIMAL(val) || IS_PERCENT(val)) return (REBI64)VAL_DECIMAL(val); if (IS_MONEY(val)) return deci_to_int(VAL_DECI(val)); Trap_Arg(val); - return 0; } @@ -200,7 +199,6 @@ if (IS_INTEGER(val)) return (REBDEC)VAL_INT64(val); if (IS_MONEY(val)) return deci_to_decimal(VAL_DECI(val)); Trap_Arg(val); - return 0; } @@ -235,7 +233,6 @@ return n; Trap_Range(val); - DEAD_END; } @@ -612,7 +609,6 @@ if (IS_LOGIC(arg)) return (VAL_LOGIC(arg) != 0); if (IS_DECIMAL(arg) || IS_PERCENT(arg)) return (VAL_DECIMAL(arg) != 0.0); Trap_Arg(arg); - DEAD_END; } diff --git a/src/core/n-data.c b/src/core/n-data.c index 9c2661ca25..7de1fe1944 100644 --- a/src/core/n-data.c +++ b/src/core/n-data.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Developers +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -154,8 +154,6 @@ static int Check_Char_Range(REBVAL *val, REBINT limit) } Trap_Arg(types); - - return 0; // for compiler } diff --git a/src/core/p-checksum.c b/src/core/p-checksum.c index 603b435978..ef4b7eb2cf 100644 --- a/src/core/p-checksum.c +++ b/src/core/p-checksum.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Contributors +** Copyright 2012-2024 Rebol Open Source Contributors ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -284,7 +284,6 @@ method = Obj_Value(spec, STD_PORT_SPEC_CHECKSUM_METHOD); if (!method || !IS_WORD(method)) { Trap1(RE_INVALID_SPEC, spec); - return 0; //just to make xcode analyze happy } req = Use_Port_State(port, RDI_CHECKSUM, sizeof(REBREQ)); diff --git a/src/core/p-crypt.c b/src/core/p-crypt.c index f289c8aec9..214c9a84e3 100644 --- a/src/core/p-crypt.c +++ b/src/core/p-crypt.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Contributors +** Copyright 2012-2024 Rebol Open Source Contributors ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -478,7 +478,6 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx); Trap1(RE_INVALID_SPEC, spec); } Trap_Port(RE_CANNOT_OPEN, port, err); - return FALSE; } @@ -1037,7 +1036,6 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx); } if (!Crypt_Open(port)) { Trap_Port(RE_CANNOT_OPEN, port, 0); - return R_FALSE; } return R_ARG1; } diff --git a/src/core/p-net.c b/src/core/p-net.c index 5c1533d0b8..4ab249e58b 100644 --- a/src/core/p-net.c +++ b/src/core/p-net.c @@ -113,7 +113,7 @@ enum Transport_Types { if (!info || !IS_OBJECT(info)) { Trap_Port(RE_INVALID_SPEC, port, -10); - return; // prevents compiler's warning + DEAD_END; } obj = CLONE_OBJECT(VAL_OBJ_FRAME(info)); diff --git a/src/core/t-char.c b/src/core/t-char.c index ea225d17a3..781a80a7ea 100644 --- a/src/core/t-char.c +++ b/src/core/t-char.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -72,7 +73,6 @@ arg = (REBINT)VAL_DECIMAL(val); else { Trap_Math_Args(REB_CHAR, action); - return R_NONE; // just to make xcode happy } } diff --git a/src/core/t-gob.c b/src/core/t-gob.c index 4f3fa042c0..a169659c9e 100644 --- a/src/core/t-gob.c +++ b/src/core/t-gob.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -792,7 +793,6 @@ const REBCNT Gob_Flag_Words[] = { tail = GOB_PANE(gob) ? GOB_TAIL(gob) : 0; } else if (!(IS_DATATYPE(val) && action == A_MAKE)){ Trap_Arg(val); - return R_FALSE; // shut-up compiler's warnings } // unary actions diff --git a/src/core/t-struct.c b/src/core/t-struct.c index c1b4a2ec69..1431732638 100644 --- a/src/core/t-struct.c +++ b/src/core/t-struct.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2014 Atronix Engineering, Inc. -** Copyright 2021-2023 Rebol Open Source Developers +** Copyright 2021-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -1163,6 +1163,4 @@ static void init_fields(REBVAL *ret, REBVAL *spec) is_arg_error: Trap_Types(RE_EXPECT_VAL, REB_STRUCT, VAL_TYPE(arg)); - - return R_NONE; // Not needed, but Xcode complains 'Control may reach end of non-void function' } diff --git a/src/core/t-vector.c b/src/core/t-vector.c index f59eef22e4..f491f94fff 100644 --- a/src/core/t-vector.c +++ b/src/core/t-vector.c @@ -3,6 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -879,7 +880,6 @@ static void reverse_vector(REBVAL *value, REBCNT len) bad_make: Trap_Make(REB_VECTOR, arg); - DEAD_END; } diff --git a/src/core/u-bincode.c b/src/core/u-bincode.c index f3703361aa..55de9e7482 100644 --- a/src/core/u-bincode.c +++ b/src/core/u-bincode.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Developers +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -1713,6 +1713,5 @@ static REBCNT EncodedU32_Size(u32 value) { error: Trap_Word(RE_DIALECT, SYM_BINCODE, value); - return R_ARG1; //just to make Clang happy } #endif //IGNORE_BINCODE diff --git a/src/core/u-compress.c b/src/core/u-compress.c index 02ce4694ed..ddd3944255 100644 --- a/src/core/u-compress.c +++ b/src/core/u-compress.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Contributors +** Copyright 2012-2024 Rebol Open Source Contributors ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -401,7 +401,6 @@ void BrotliDefaultFreeFunc(void* opaque, void* address) { BrotliEncoderDestroyInstance(BrotliEncoder); SET_INTEGER(DS_RETURN, 0); Trap1(RE_BAD_PRESS, DS_RETURN); //!!!provide error string descriptions - return NULL; // not reached! } BrotliEncoderDestroyInstance(BrotliEncoder); @@ -435,7 +434,6 @@ static BrotliDecoderState *BrotliDecoder = NULL; if (!BrotliDecoder) { // Failed to create the Brotli decoder Trap0(RE_NO_MEMORY); - return 0; } if (in_len < 0 || (index + in_len > BIN_LEN(input))) in_len = BIN_LEN(input) - index; @@ -483,7 +481,6 @@ static BrotliDecoderState *BrotliDecoder = NULL; BrotliDecoderDestroyInstance(BrotliDecoder); BrotliDecoder = NULL; Trap1(RE_BAD_PRESS, DS_RETURN); - return 0; // Failed to decompress the input buffer } #endif //INCLUDE_BROTLI diff --git a/src/core/u-png-filter.c b/src/core/u-png-filter.c index 3dbcea2762..f18c73411b 100644 --- a/src/core/u-png-filter.c +++ b/src/core/u-png-filter.c @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2021 Rebol Open Source Contributors +** Copyright 2012-2024 Rebol Open Source Contributors ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -71,7 +71,6 @@ static REBYTE get_png_filter_type(REBVAL* val) { return MIN(PNG_FILTER_PAETH, MAX(0, VAL_INT32(val))); } Trap1(RE_INVALID_ARG, val); - return 0; // to make xcode happy } /*********************************************************************** diff --git a/src/include/reb-c.h b/src/include/reb-c.h index d4fa5c8c2d..47f1b385be 100644 --- a/src/include/reb-c.h +++ b/src/include/reb-c.h @@ -442,14 +442,40 @@ inline uint64_t rotl64(uint64_t x, int8_t r) (p)[7] = (u8)((v) >> 56) & 0xff; \ } while (0) +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif +#if !defined(GCC_VERSION_AT_LEAST) +# ifdef __GNUC__ +# define GCC_VERSION_AT_LEAST(m, n) \ + (__GNUC__ > (m) || (__GNUC__ == (m) && __GNUC_MINOR__ >= (n))) +# else +# define GCC_VERSION_AT_LEAST(m, n) 0 +# endif +#endif //! Function attribute used by functions that never return (that terminate the process). -#if defined(__GNUC__) -#define REB_NORETURN __attribute__((__noreturn__)) -#elif defined(_MSC_VER) -#define REB_NORETURN __declspec(noreturn) -#else -#define REB_NORETURN +#if !defined(REB_NORETURN) +# if defined(__clang__) || GCC_VERSION_AT_LEAST(2, 5) +# define REB_NORETURN __attribute__ ((noreturn)) +# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define REB_NORETURN _Noreturn +# elif defined(__TINYC__) +# define REB_NORETURN /* _Noreturn unreliable [1] */ +# elif defined(_MSC_VER) +# define REB_NORETURN __declspec(noreturn) +# else +# define REB_NORETURN +# endif +#endif +#if !defined(DEAD_END) +# if __has_builtin(__builtin_unreachable) || GCC_VERSION_AT_LEAST(4, 5) +# define DEAD_END __builtin_unreachable() +# elif defined(_MSC_VER) +# define DEAD_END __assume(0) +# else +# define DEAD_END abort() +# endif #endif /* These macros are easier-to-spot variants of the parentheses cast. diff --git a/src/include/sys-core.h b/src/include/sys-core.h index 15d8f4919b..fd4dc0ad18 100644 --- a/src/include/sys-core.h +++ b/src/include/sys-core.h @@ -3,7 +3,7 @@ ** REBOL [R3] Language Interpreter and Run-time Environment ** ** Copyright 2012 REBOL Technologies -** Copyright 2012-2023 Rebol Open Source Developers +** Copyright 2012-2024 Rebol Open Source Developers ** REBOL is a trademark of REBOL Technologies ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -336,7 +336,6 @@ enum { //#define DO_BLOCK(v) Do_Block(VAL_SERIES(v), VAL_INDEX(v)) #define DO_BLK(v) Do_Blk(VAL_SERIES(v), VAL_INDEX(v)) -#define DEAD_END return 0 // makes compiler happy (for never used return case) #define NO_RESULT ((REBCNT)(-1)) #define ALL_BITS ((REBCNT)(-1)) diff --git a/src/include/sys-int-funcs.h b/src/include/sys-int-funcs.h index 7f5effdea6..0f4bb9894a 100644 --- a/src/include/sys-int-funcs.h +++ b/src/include/sys-int-funcs.h @@ -27,15 +27,7 @@ #ifndef __SYS_INT_FUNCS_H_ #define __SYS_INT_FUNCS_H_ -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif -#ifdef __GNUC__ -#define GCC_VERSION_AT_LEAST(m, n) (__GNUC__ >= (m) && __GNUC_MINOR__ >= (n)) -#else -#define GCC_VERSION_AT_LEAST(m, n) 0 -#endif #if __has_builtin(__builtin_sadd_overflow) || GCC_VERSION_AT_LEAST(5, 1) #define REB_I32_ADD_OF(x, y, sum) __builtin_sadd_overflow((x), (y), (sum))