[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix -Wreturn-type warnings on -DNDEBUG
From: |
Arsen Arsenović |
Subject: |
[PATCH] Fix -Wreturn-type warnings on -DNDEBUG |
Date: |
Sun, 12 Feb 2023 18:40:33 +0100 |
* common/pk-utils.h (PK_UNREACHABLE): New macro. Diagnoses
reaching unreachable code and aborts.
* libpoke/ios.c: Use PK_UNREACHABLE.
* libpoke/libpoke.c: Ditto.
* libpoke/pkl-anal.c: Ditto.
* libpoke/pkl-asm.c: Ditto.
* libpoke/pkl-ast.c: Ditto.
* libpoke/pkl-diag.c: Ditto.
* libpoke/pkl-env.c: Ditto.
* libpoke/pkl-fold.c: Ditto.
* libpoke/pkl-gen.c: Ditto.
* libpoke/pkl-lex.l: Ditto.
* libpoke/pkl-parser.c: Ditto.
* libpoke/pkl-pass.c: Ditto.
* libpoke/pkl-promo.c: Ditto.
* libpoke/pkl-tab.y: Ditto.
* libpoke/pkl-trans.c: Ditto.
* libpoke/pkl-typify.c: Ditto.
* libpoke/pkl.c: Ditto.
* libpoke/pvm-val.c: Ditto.
* poke/pk-cmd-help.c: Ditto.
* poke/pk-cmd-set.c: Ditto.
* poke/pk-cmd-vm.c: Ditto.
* poke/pk-cmd.c: Ditto.
* poke/pk-ios.c: Ditto.
* poke/pk-map-tab.y: Ditto.
* poke/poke.c: Ditto.
---
As discussed on IRC.
Ready for dev/maint? Builds w/o (relevant) warnings with gcc (Gentoo
Hardened 13.0.1_pre20230205-r1 p7) 13.0.1 20230205 (experimental) with
-Wall -DNDEBUG {,-O3}.
ChangeLog | 30 ++++++++++++++++++++++++++++++
common/pk-utils.h | 10 ++++++++++
libpoke/ios.c | 6 +++---
libpoke/libpoke.c | 13 +++++++------
libpoke/pkl-anal.c | 2 +-
libpoke/pkl-asm.c | 40 ++++++++++++++++++++--------------------
libpoke/pkl-ast.c | 12 ++++++------
libpoke/pkl-diag.c | 3 ++-
libpoke/pkl-env.c | 4 ++--
libpoke/pkl-fold.c | 2 +-
libpoke/pkl-gen.c | 38 +++++++++++++++++++-------------------
libpoke/pkl-lex.l | 3 ++-
libpoke/pkl-parser.c | 3 ++-
libpoke/pkl-pass.c | 11 ++++++-----
libpoke/pkl-promo.c | 8 ++++----
libpoke/pkl-tab.y | 6 +++---
libpoke/pkl-trans.c | 2 +-
libpoke/pkl-typify.c | 2 +-
libpoke/pkl.c | 4 ++--
libpoke/pvm-val.c | 14 +++++++-------
poke/pk-cmd-help.c | 2 +-
poke/pk-cmd-set.c | 8 ++++----
poke/pk-cmd-vm.c | 3 ++-
poke/pk-cmd.c | 2 +-
poke/pk-ios.c | 3 ++-
poke/pk-map-tab.y | 2 +-
poke/poke.c | 2 +-
27 files changed, 141 insertions(+), 94 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 181a1a17..897e3dc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2023-02-12 Arsen Arsenović <arsen@aarsen.me>
+
+ * common/pk-utils.h (PK_UNREACHABLE): New macro. Diagnoses
+ reaching unreachable code and aborts.
+ * libpoke/ios.c: Use PK_UNREACHABLE.
+ * libpoke/libpoke.c: Ditto.
+ * libpoke/pkl-anal.c: Ditto.
+ * libpoke/pkl-asm.c: Ditto.
+ * libpoke/pkl-ast.c: Ditto.
+ * libpoke/pkl-diag.c: Ditto.
+ * libpoke/pkl-env.c: Ditto.
+ * libpoke/pkl-fold.c: Ditto.
+ * libpoke/pkl-gen.c: Ditto.
+ * libpoke/pkl-lex.l: Ditto.
+ * libpoke/pkl-parser.c: Ditto.
+ * libpoke/pkl-pass.c: Ditto.
+ * libpoke/pkl-promo.c: Ditto.
+ * libpoke/pkl-tab.y: Ditto.
+ * libpoke/pkl-trans.c: Ditto.
+ * libpoke/pkl-typify.c: Ditto.
+ * libpoke/pkl.c: Ditto.
+ * libpoke/pvm-val.c: Ditto.
+ * poke/pk-cmd-help.c: Ditto.
+ * poke/pk-cmd-set.c: Ditto.
+ * poke/pk-cmd-vm.c: Ditto.
+ * poke/pk-cmd.c: Ditto.
+ * poke/pk-ios.c: Ditto.
+ * poke/pk-map-tab.y: Ditto.
+ * poke/poke.c: Ditto.
+
2023-01-31 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/std.pk (Pk_Version): Add control fields.
diff --git a/common/pk-utils.h b/common/pk-utils.h
index b545a072..812300bc 100644
--- a/common/pk-utils.h
+++ b/common/pk-utils.h
@@ -23,6 +23,7 @@
#include <string.h>
#include <stdint.h>
+#include <stdlib.h>
/* Macros to avoid using strcmp directly. */
@@ -64,4 +65,13 @@ char *pk_str_replace (const char *in, const char *search,
const char *replace);
/* Left and rigth trim the given string from whitespaces. */
void pk_str_trim (char **str);
+/* Diagnoses reaching unreachable code, and aborts. */
+#define PK_UNREACHABLE() \
+ do \
+ { \
+ assert (0 && "Reached unreachable code."); \
+ abort (); \
+ } \
+ while (0)
+
#endif /* ! PK_UTILS_H */
diff --git a/libpoke/ios.c b/libpoke/ios.c
index b47a2b85..93da34c5 100644
--- a/libpoke/ios.c
+++ b/libpoke/ios.c
@@ -726,7 +726,7 @@ ios_read_int_common (ios io, ios_off offset, int flags,
return IOS_OK;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
@@ -1194,7 +1194,7 @@ ios_write_int_fast (ios io, ios_off offset, int flags,
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -1508,7 +1508,7 @@ ios_write_int_common (ios io, ios_off offset, int flags,
return IOS_OK;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index d03acc8e..43434942 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <assert.h>
+#include "pk-utils.h"
#include "pkt.h"
#include "pkl.h"
#include "pkl-ast.h" /* XXX */
@@ -966,7 +967,7 @@ pk_omode (pk_compiler pkc)
case PVM_PRINT_FLAT: omode = PK_PRINT_FLAT; break;
case PVM_PRINT_TREE: omode = PK_PRINT_TREE; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pkc->status = PK_OK;
return omode;
@@ -982,7 +983,7 @@ pk_set_omode (pk_compiler pkc, enum pk_omode omode)
case PK_PRINT_FLAT: mode = PVM_PRINT_FLAT; break;
case PK_PRINT_TREE: mode = PVM_PRINT_TREE; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pvm_set_omode (pkc->vm, mode);
pkc->status = PK_OK;
@@ -1012,7 +1013,7 @@ pk_endian (pk_compiler pkc)
case IOS_ENDIAN_LSB: endian = PK_ENDIAN_LSB; break;
case IOS_ENDIAN_MSB: endian = PK_ENDIAN_MSB; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pkc->status = PK_OK;
return endian;
@@ -1028,7 +1029,7 @@ pk_set_endian (pk_compiler pkc, enum pk_endian endian)
case PK_ENDIAN_LSB: ios_endian = IOS_ENDIAN_LSB; break;
case PK_ENDIAN_MSB: ios_endian = IOS_ENDIAN_MSB; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pvm_set_endian (pkc->vm, ios_endian);
pkc->status = PK_OK;
@@ -1044,7 +1045,7 @@ pk_nenc (pk_compiler pkc)
case IOS_NENC_1: nenc = PK_NENC_1; break;
case IOS_NENC_2: nenc = PK_NENC_2; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pkc->status = PK_OK;
return nenc;
@@ -1060,7 +1061,7 @@ pk_set_nenc (pk_compiler pkc, enum pk_nenc nenc)
case PK_NENC_1: ios_nenc = IOS_NENC_1; break;
case PK_NENC_2: ios_nenc = IOS_NENC_2; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pvm_set_nenc (pkc->vm, ios_nenc);
pkc->status = PK_OK;
diff --git a/libpoke/pkl-anal.c b/libpoke/pkl-anal.c
index 09d31b99..1e54e8a2 100644
--- a/libpoke/pkl-anal.c
+++ b/libpoke/pkl-anal.c
@@ -697,7 +697,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_cons)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
PKL_PHASE_END_HANDLER
diff --git a/libpoke/pkl-asm.c b/libpoke/pkl-asm.c
index f09050e7..b855cbf6 100644
--- a/libpoke/pkl-asm.c
+++ b/libpoke/pkl-asm.c
@@ -258,7 +258,7 @@ pkl_asm_insn_atoa (pkl_asm pasm,
RAS_MACRO_ARRAY_CONV_SIZ (bounder);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
}
@@ -414,7 +414,7 @@ pkl_asm_insn_peek (pkl_asm pasm, pkl_ast_node type,
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: PEEKD type
@@ -445,7 +445,7 @@ pkl_asm_insn_peekd (pkl_asm pasm, pkl_ast_node type)
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: REV depth
@@ -491,7 +491,7 @@ pkl_asm_insn_format (pkl_asm pasm, pkl_ast_node type)
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: PRINT type
@@ -510,7 +510,7 @@ pkl_asm_insn_print (pkl_asm pasm, pkl_ast_node type)
}
else if (type_code == PKL_TYPE_ANY)
{
- assert (0);
+ PK_UNREACHABLE ();
}
else if (type_code == PKL_TYPE_INTEGRAL)
{
@@ -529,7 +529,7 @@ pkl_asm_insn_print (pkl_asm pasm, pkl_ast_node type)
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: POKE type, endian, nenc
@@ -567,7 +567,7 @@ pkl_asm_insn_poke (pkl_asm pasm, pkl_ast_node type,
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
@@ -599,7 +599,7 @@ pkl_asm_insn_poked (pkl_asm pasm, pkl_ast_node type)
(unsigned int) size);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: NEG type
@@ -739,7 +739,7 @@ pkl_asm_insn_binop (pkl_asm pasm,
pkl_asm_insn (pasm, pow_table[tl][signed_p]);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
else if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_OFFSET)
@@ -792,7 +792,7 @@ pkl_asm_insn_binop (pkl_asm pasm,
}
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/*
@@ -866,7 +866,7 @@ pkl_asm_insn_cmp (pkl_asm pasm,
case PKL_INSN_GE: oinsn = PKL_INSN_GES; break;
case PKL_INSN_LE: oinsn = PKL_INSN_LES; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
/* Assembly the instruction. */
@@ -904,7 +904,7 @@ pkl_asm_insn_cmp (pkl_asm pasm,
case PKL_INSN_GE: oinsn = ge_table[tl][signed_p]; break;
case PKL_INSN_LE: oinsn = le_table[tl][signed_p]; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -962,10 +962,10 @@ pkl_asm_insn_cmp (pkl_asm pasm,
else if (insn == PKL_INSN_NE)
pkl_asm_insn (pasm, PKL_INSN_NEC);
else
- assert (0);
+ PK_UNREACHABLE ();
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Macro-instruction: ASETC array_type
@@ -1358,7 +1358,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...)
have hacks to prevent the assert below in both
pkl_asm_note and the push instructions. */
#if defined POKE_HOST_32BIT
- assert (0);
+ PK_UNREACHABLE ();
#endif
pvm_program_append_val_parameter (pasm->program, val);
break;
@@ -1385,7 +1385,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...)
case 'a':
/* Fallthrough. */
case 'i':
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -1649,7 +1649,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...)
else if (insn == PKL_INSN_MODO)
pkl_asm_insn_modo (pasm, base_type, unit);
else
- assert (0);
+ PK_UNREACHABLE ();
break;
}
case PKL_INSN_REMAP:
@@ -1691,7 +1691,7 @@ pkl_asm_insn (pkl_asm pasm, enum pkl_asm_insn insn, ...)
}
case PKL_INSN_MACRO:
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
}
@@ -2184,7 +2184,7 @@ pkl_asm_break_label_1 (struct pkl_asm_level *level)
}
/* The compiler must guarantee this does NOT happen. */
- assert (0);
+ PK_UNREACHABLE ();
}
pvm_program_label
@@ -2210,7 +2210,7 @@ pkl_asm_continue_label_1 (struct pkl_asm_level *level)
}
/* The compiler must guarantee this does NOT happen. */
- assert (0);
+ PK_UNREACHABLE ();
}
pvm_program_label
diff --git a/libpoke/pkl-ast.c b/libpoke/pkl-ast.c
index e93eb6cd..99d7473d 100644
--- a/libpoke/pkl-ast.c
+++ b/libpoke/pkl-ast.c
@@ -1092,7 +1092,7 @@ pkl_ast_sizeof_type (pkl_ast ast, pkl_ast_node type)
* PKL_AST_INTEGER_VALUE (unit));
}
else
- assert (0);
+ PK_UNREACHABLE ();
PKL_AST_TYPE (res) = ASTREF (res_type);
break;
}
@@ -1199,7 +1199,7 @@ pkl_ast_sizeof_type (pkl_ast ast, pkl_ast_node type)
break;
case PKL_TYPE_STRING:
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -1226,7 +1226,7 @@ pkl_ast_sizeof_integral_type (pkl_ast_node type)
return PKL_AST_TYPE_I_SIZE (itype);
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
/* Return 1 if the given TYPE can be mapped in IO. 0 otherwise. */
@@ -1524,14 +1524,14 @@ pkl_type_append_to (pkl_ast_node type, int
use_given_name,
else if (PKL_AST_CODE (unit) == PKL_AST_INTEGER)
sb_appendf (buffer, "%" PRIu64, PKL_AST_INTEGER_VALUE (unit));
else
- assert (0);
+ PK_UNREACHABLE ();
sb_append (buffer, ">");
break;
}
case PKL_TYPE_NOTYPE:
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -2712,7 +2712,7 @@ pkl_ast_node_free_1 (gl_set_t visitations, pkl_ast_node
ast)
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_AST_NODE_FREE (PKL_AST_TYPE (ast));
diff --git a/libpoke/pkl-diag.c b/libpoke/pkl-diag.c
index 6f7e7c4b..f5dbf30f 100644
--- a/libpoke/pkl-diag.c
+++ b/libpoke/pkl-diag.c
@@ -24,6 +24,7 @@
#include "tmpdir.h"
#include "tempname.h"
+#include "pk-utils.h"
#include "pkt.h"
#include "pkl.h"
#include "pkl-diag.h"
@@ -135,7 +136,7 @@ pkl_detailed_location (pkl_ast ast, pkl_ast_loc loc,
}
}
else
- assert (0);
+ PK_UNREACHABLE ();
pk_puts ("\n");
diff --git a/libpoke/pkl-env.c b/libpoke/pkl-env.c
index e97f9a4e..a9d664d8 100644
--- a/libpoke/pkl-env.c
+++ b/libpoke/pkl-env.c
@@ -174,7 +174,7 @@ get_ns_table (pkl_env env, int namespace)
table = &env->units_hash_table;
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
return table;
@@ -245,7 +245,7 @@ pkl_env_register (pkl_env env,
PKL_AST_DECL_ORDER (decl) = env->num_units++;
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
return 1;
}
diff --git a/libpoke/pkl-fold.c b/libpoke/pkl-fold.c
index f2ea7bc2..74f9dbd1 100644
--- a/libpoke/pkl-fold.c
+++ b/libpoke/pkl-fold.c
@@ -134,7 +134,7 @@ EMUL_UUU (ge) { return op1 >= op2; }
EMUL_III (ge) { return op1 >= op2; }
EMUL_UUU (gcd) { return fold_gcd (op1, op2); }
-EMUL_III (gcd) { assert (0); return 0; }
+EMUL_III (gcd) { PK_UNREACHABLE (); return 0; }
EMUL_UUU (sl) { return op1 << op2; }
EMUL_III (sl) { return op1 << op2; }
diff --git a/libpoke/pkl-gen.c b/libpoke/pkl-gen.c
index bbdfd7d2..2b009d64 100644
--- a/libpoke/pkl-gen.c
+++ b/libpoke/pkl-gen.c
@@ -523,10 +523,10 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_decl)
case PKL_AST_DECL_KIND_TYPE:
if (PKL_AST_TYPE_CODE (initial) == PKL_TYPE_STRUCT
|| PKL_AST_TYPE_CODE (initial) == PKL_TYPE_ARRAY)
- assert (0);
+ PK_UNREACHABLE ();
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -734,7 +734,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_comp_stmt)
RAS_MACRO_BUILTIN_SET_COLOR_BGCOLOR;
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
else
@@ -1296,7 +1296,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_loop_stmt)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_PASS_BREAK;
@@ -2444,7 +2444,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_cast)
pkl_asm_insn (pasm, PKL_INSN_NIP); /* IVAL */
}
else
- assert (0);
+ PK_UNREACHABLE ();
PKL_PASS_BREAK;
}
@@ -2478,7 +2478,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_cons)
PKL_GEN_POP_CONTEXT;
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
PKL_PHASE_END_HANDLER
@@ -2685,7 +2685,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_trimmer)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_PASS_BREAK;
@@ -2768,7 +2768,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_indexer)
RAS_MACRO_STROREF (index_type);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
@@ -3020,7 +3020,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_type_integral)
IOS_NENC_2, IOS_ENDIAN_MSB);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
else if (PKL_GEN_IN_CTX_P (PKL_GEN_CTX_IN_MAPPER))
@@ -3040,7 +3040,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_type_integral)
IOS_NENC_2, IOS_ENDIAN_MSB);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pkl_asm_insn (pasm, PKL_INSN_NIP); /* STRICT is not used. */
@@ -3993,7 +3993,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_add)
}
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4021,7 +4021,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_sub)
}
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4072,7 +4072,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_mul)
}
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4143,7 +4143,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_div)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4172,7 +4172,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_mod)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4202,7 +4202,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_binexp)
case PKL_AST_OP_SR: insn = PKL_INSN_SR; break;
case PKL_AST_OP_POW: insn = PKL_INSN_POW; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -4218,7 +4218,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_binexp)
pkl_asm_insn (pasm, PKL_INSN_NIP);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
@@ -4422,7 +4422,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_rela)
case PKL_AST_OP_LE: rela_insn = PKL_INSN_LE; break;
case PKL_AST_OP_GE: rela_insn = PKL_INSN_GE; break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -4443,7 +4443,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_op_rela)
pkl_asm_insn (pasm, PKL_INSN_NIP2);
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
diff --git a/libpoke/pkl-lex.l b/libpoke/pkl-lex.l
index d77fb808..1aac75af 100644
--- a/libpoke/pkl-lex.l
+++ b/libpoke/pkl-lex.l
@@ -42,6 +42,7 @@
#include <ctype.h>
#include <assert.h>
#include <stdlib.h>
+#include "pk-utils.h"
#include "pkl.h"
#include "pkl-ast.h"
#include "pkl-env.h"
@@ -472,7 +473,7 @@ S ::
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
}
diff --git a/libpoke/pkl-parser.c b/libpoke/pkl-parser.c
index 15e85ab6..66d8d0a8 100644
--- a/libpoke/pkl-parser.c
+++ b/libpoke/pkl-parser.c
@@ -24,6 +24,7 @@
#include "pkl-ast.h"
#include "pkl-parser.h"
#include "pkl-tab.h"
+#include "pk-utils.h"
#define YYSTYPE PKL_TAB_STYPE
#define YYLTYPE PKL_TAB_LTYPE
#include "pkl-lex.h"
@@ -160,7 +161,7 @@ pkl_parse_buffer (pkl_compiler compiler, pkl_env *env,
else if (what == PKL_PARSE_STATEMENT)
parser->start_token = START_STMT;
else
- assert (0);
+ PK_UNREACHABLE ();
yybuffer = pkl_tab__scan_string (buffer, parser->scanner);
diff --git a/libpoke/pkl-pass.c b/libpoke/pkl-pass.c
index 4fb9ec26..29274a7e 100644
--- a/libpoke/pkl-pass.c
+++ b/libpoke/pkl-pass.c
@@ -18,6 +18,7 @@
#include <config.h>
+#include "pk-utils.h"
#include "pkl-pass.h"
#define PKL_CALL_PHASES(CLASS,ORDER,DISCR) \
@@ -171,7 +172,7 @@ pkl_call_node_handlers (pkl_compiler compiler,
#undef PKL_DEF_OP
default:
/* Unknown operation code. */
- assert (0);
+ PK_UNREACHABLE ();
}
}
@@ -219,7 +220,7 @@ pkl_call_node_handlers (pkl_compiler compiler,
#undef PKL_DEF_OP
default:
/* Unknown operation code. */
- assert (0);
+ PK_UNREACHABLE ();
}
}
@@ -233,7 +234,7 @@ pkl_call_node_handlers (pkl_compiler compiler,
}
}
else
- assert (0);
+ PK_UNREACHABLE ();
newnode:
restart:
@@ -456,7 +457,7 @@ pkl_do_pass_1 (pkl_compiler compiler,
break;
default:
/* Unknown type code. */
- assert (0);
+ PK_UNREACHABLE ();
}
break;
}
@@ -616,7 +617,7 @@ pkl_do_pass_1 (pkl_compiler compiler,
break;
default:
/* Unknown node code. This kills the poke :'( */
- assert (0);
+ PK_UNREACHABLE ();
}
/* Call the post-order handlers from registered phases. */
diff --git a/libpoke/pkl-promo.c b/libpoke/pkl-promo.c
index 30030c44..7e232f2c 100644
--- a/libpoke/pkl-promo.c
+++ b/libpoke/pkl-promo.c
@@ -571,7 +571,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_mul)
else if (PKL_AST_TYPE_CODE (op_type) == PKL_TYPE_STRING)
;
else
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_PASS_DONE;
@@ -753,7 +753,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_bshiftpow)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_PASS_DONE;
@@ -977,7 +977,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_type_array)
break;
}
default:
- assert (0); /* This can't happen. */
+ PK_UNREACHABLE (); /* This can't happen. */
}
PKL_PASS_RESTART = restart;
@@ -1662,7 +1662,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_cons)
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_PASS_DONE;
diff --git a/libpoke/pkl-tab.y b/libpoke/pkl-tab.y
index 1fc8f063..c2117432 100644
--- a/libpoke/pkl-tab.y
+++ b/libpoke/pkl-tab.y
@@ -1769,7 +1769,7 @@ struct_type_specifier:
PKL_ENV_NS_MAIN,
PKL_AST_IDENTIFIER_POINTER
(offset_identifier),
decl))
- assert (0);
+ PK_UNREACHABLE ();
}
}
struct_type_elem_list '}'
@@ -2462,7 +2462,7 @@ stmt:
PKL_AST_IDENTIFIER_POINTER ($3),
$<ast>$))
/* This should never happen. */
- assert (0);
+ PK_UNREACHABLE ();
}
')' stmt
{
@@ -2512,7 +2512,7 @@ stmt:
PKL_AST_IDENTIFIER_POINTER ($3),
$<ast>$))
/* This should never happen. */
- assert (0);
+ PK_UNREACHABLE ();
}
WHERE expression ')' stmt
{
diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
index 7d5ff8d9..27c4554f 100644
--- a/libpoke/pkl-trans.c
+++ b/libpoke/pkl-trans.c
@@ -471,7 +471,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string)
}
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
new_string_pointer[i] = '\0';
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index cd1e4cbc..e13a57af 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -2205,7 +2205,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_cons)
PKL_AST_CONS_KIND (cons) = PKL_AST_CONS_KIND_ARRAY;
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
}
PKL_AST_TYPE (cons) = ASTREF (cons_type);
diff --git a/libpoke/pkl.c b/libpoke/pkl.c
index f4fc181c..130d2825 100644
--- a/libpoke/pkl.c
+++ b/libpoke/pkl.c
@@ -830,11 +830,11 @@ pvm_type_to_ast_type (pkl_ast ast, pvm_val type)
break;
case PVM_TYPE_STRUCT:
/* XXX writeme */
- assert (0);
+ PK_UNREACHABLE ();
break;
case PVM_TYPE_CLOSURE:
/* XXX writeme */
- assert (0);
+ PK_UNREACHABLE ();
break;
default:
break;
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index 2903b1e5..3c83d92a 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -990,7 +990,7 @@ pvm_sizeof (pvm_val val)
/* By convention, PVM_NULL values have size zero. */
return 0;
- assert (0);
+ PK_UNREACHABLE ();
return 0;
}
@@ -1140,7 +1140,7 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base,
int indent,
uint_fmt = "";
break;
default:
- assert (0);
+ PK_UNREACHABLE ();
break;
}
@@ -1489,7 +1489,7 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base,
int indent,
case 16: pk_puts ("int16"); break;
case 32: pk_puts ("int32"); break;
case 64: pk_puts ("int64"); break;
- default: assert (0); break;
+ default: PK_UNREACHABLE (); break;
}
}
break;
@@ -1562,7 +1562,7 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base,
int indent,
break;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
pk_term_end_class ("type");
@@ -1582,7 +1582,7 @@ pvm_print_val_1 (pvm vm, int depth, int mode, int base,
int indent,
pk_term_end_class ("special");
}
else
- assert (0);
+ PK_UNREACHABLE ();
}
#undef PVM_PRINT_VAL_1
@@ -1651,7 +1651,7 @@ pvm_typeof (pvm_val val)
else if (PVM_IS_CLS (val))
type = PVM_NULL;
else
- assert (0);
+ PK_UNREACHABLE ();
return type;
}
@@ -1713,7 +1713,7 @@ pvm_type_equal_p (pvm_val type1, pvm_val type2)
return 1;
}
default:
- assert (0);
+ PK_UNREACHABLE ();
}
}
diff --git a/poke/pk-cmd-help.c b/poke/pk-cmd-help.c
index 10874f40..ebf4afd1 100644
--- a/poke/pk-cmd-help.c
+++ b/poke/pk-cmd-help.c
@@ -40,7 +40,7 @@ pk_cmd_help (int argc, struct pk_cmd_arg argv[], uint64_t
uflags)
if (pk_call (poke_compiler, pk_help, &ret, &exit_exception,
1 /* narg */, topic) == PK_ERROR
|| exit_exception != PK_NULL)
- assert (0);
+ PK_UNREACHABLE ();
return 1;
}
diff --git a/poke/pk-cmd-set.c b/poke/pk-cmd-set.c
index b2dc2b05..0e3e2e1a 100644
--- a/poke/pk-cmd-set.c
+++ b/poke/pk-cmd-set.c
@@ -39,7 +39,7 @@ pk_cmd_set_dump (int argc, struct pk_cmd_arg argv[], uint64_t
uflags)
if (pk_call (poke_compiler, registry_printer, &retval, &exit_exception,
0) == PK_ERROR
|| exit_exception != PK_NULL)
- assert (0); /* This shouldn't happen. */
+ PK_UNREACHABLE (); /* This shouldn't happen. */
#if HAVE_HSERVER
{
@@ -84,7 +84,7 @@ pk_cmd_set (int int_p,
== PK_ERROR
|| exit_exception != PK_NULL)
/* This shouldn't happen. */
- assert (0);
+ PK_UNREACHABLE ();
if (int_p)
pk_printf ("%" PRId64 "\n", pk_int_value (retval));
@@ -111,7 +111,7 @@ pk_cmd_set (int int_p,
|| exit_exception != PK_NULL)
/* This shouldn't happen, since we know `newval' is of the
right type. */
- assert (0);
+ PK_UNREACHABLE ();
/* `retval' is a string. If it is empty, everything went ok, if
it is not it is an explicative message on what went
@@ -153,7 +153,7 @@ pk_cmd_set_error_on_warning (int argc, struct pk_cmd_arg
argv[],
checking whether the passed string is empty or not. */
if (argc != 2)
- assert (0);
+ PK_UNREACHABLE ();
arg = PK_CMD_ARG_STR (argv[1]);
diff --git a/poke/pk-cmd-vm.c b/poke/pk-cmd-vm.c
index 90b25c33..51ff59a7 100644
--- a/poke/pk-cmd-vm.c
+++ b/poke/pk-cmd-vm.c
@@ -21,6 +21,7 @@
#include "poke.h"
#include "pk-cmd.h"
+#include "pk-utils.h"
#include "pk-repl.h" /* For poke_completion_function */
#define PK_VM_DIS_UFLAGS "n"
@@ -115,7 +116,7 @@ pk_cmd_vm_dispatch (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
if (pk_call (poke_compiler, vm_dispatch, &retval, &exception, 0)
== PK_ERROR
|| exception != PK_NULL)
- assert (0); /* This shouldn't happen. */
+ PK_UNREACHABLE (); /* This shouldn't happen. */
return 1;
}
diff --git a/poke/pk-cmd.c b/poke/pk-cmd.c
index 92569978..e09751b1 100644
--- a/poke/pk-cmd.c
+++ b/poke/pk-cmd.c
@@ -496,7 +496,7 @@ pk_cmd_exec_1 (const char *str, struct pk_trie *cmds_trie,
char *prefix)
}
default:
/* This should NOT happen. */
- assert (0);
+ PK_UNREACHABLE ();
}
if (match)
diff --git a/poke/pk-ios.c b/poke/pk-ios.c
index 7c83875f..bd78ff3c 100644
--- a/poke/pk-ios.c
+++ b/poke/pk-ios.c
@@ -26,6 +26,7 @@
#include "poke.h"
#include "pk-ios.h"
+#include "pk-utils.h"
#include "pk-map.h"
int
@@ -210,7 +211,7 @@ pk_open_proc_maps (int ios_id, uint64_t pid, int all_p)
ios_id,
range_begin, range_end - range_begin,
map_name) == -1)
- assert (0);
+ PK_UNREACHABLE ();
if (pk_ios_open (poke_compiler, handler, flags, 0) == PK_IOS_NOID)
continue;
diff --git a/poke/pk-map-tab.y b/poke/pk-map-tab.y
index 72067332..05d3ee3e 100644
--- a/poke/pk-map-tab.y
+++ b/poke/pk-map-tab.y
@@ -326,7 +326,7 @@ map_entry:
else if (!offset)
pk_map_printf_error (map_parser, @$, "entry lacks an
%%offset\n");
else
- assert (0);
+ PK_UNREACHABLE ();
YYERROR;
}
diff --git a/poke/poke.c b/poke/poke.c
index 3dedc95f..af223309 100644
--- a/poke/poke.c
+++ b/poke/poke.c
@@ -816,7 +816,7 @@ poke_handle_exception (pk_val exception)
assert (handler != PK_NULL);
if (pk_call (poke_compiler, handler, NULL, NULL, 1, exception)
== PK_ERROR)
- assert (0);
+ PK_UNREACHABLE ();
}
void
--
2.39.1
- [PATCH] Fix -Wreturn-type warnings on -DNDEBUG,
Arsen Arsenović <=