Skip to content

Commit

Permalink
Ensure that every function which returns a value uses either UNREACHA…
Browse files Browse the repository at this point in the history
…BLE_CODE

or actually returns a value.
  • Loading branch information
davidgiven committed Nov 1, 2024
1 parent 361ec36 commit 183aa1e
Show file tree
Hide file tree
Showing 130 changed files with 234 additions and 235 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ BUILDDIR ?= $(ACK_TEMP_DIR)/ack-build

# What build flags do you want to use for native code?

CFLAGS ?= -g -Werror=return-type
LDFLAGS ?=
CFLAGS ?= -g \
-Werror=return-type \
-fsanitize=unreachable \
-DUNREACHABLE_CODE='__builtin_unreachable()' \
-DNORETURN=_Noreturn

LDFLAGS ?= -g \
-fsanitize=unreachable

# Various commands.

Expand Down
4 changes: 2 additions & 2 deletions lang/cem/cemcom.ansi/LLlex.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int GetToken(register struct token* ptok)
break;
default:
crash("bad class for char 0%o", ch);
/* NOTREACHED */
UNREACHABLE_CODE;
}
UnGetChar();
return ptok->tk_symb = ch;
Expand Down Expand Up @@ -385,7 +385,7 @@ int GetToken(register struct token* ptok)
default: /* this cannot happen */
crash("bad class for char 0%o", ch);
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

static arith char_constant(char* nm)
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom.ansi/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ code_declaration(
break;
default:
crash("bad local storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom.ansi/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void conversion(register struct type *from_type, register struct type *to_type)
break;
default:
crash("(conversion) illegal type conversion");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}
if ((int)(to_type->tp_size) < (int)word_size
Expand Down
10 changes: 5 additions & 5 deletions lang/cem/cemcom.ansi/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void crash(char *fmt, ...)
#else /* DEBUG */
sys_stop(S_EXIT);
#endif /* DEBUG */
/* NOTREACHED */
UNREACHABLE_CODE;
}

/*VARARGS*/
Expand All @@ -270,7 +270,7 @@ void fatal(char *fmt, ...)

if (C_busy()) C_close();
sys_stop(S_EXIT);
/*NOTREACHED*/
UNREACHABLE_CODE;
}
#else
/*VARARGS*/
Expand Down Expand Up @@ -501,7 +501,7 @@ void crash(va_alist) /* fmt, args */
#else /* DEBUG */
sys_stop(S_EXIT);
#endif /* DEBUG */
/* NOTREACHED */
UNREACHABLE_CODE;
}

/*VARARGS*/
Expand All @@ -519,7 +519,7 @@ void fatal(va_alist) /* fmt, args */

if (C_busy()) C_close();
sys_stop(S_EXIT);
/*NOTREACHED*/
UNREACHABLE_CODE;
}
#endif

Expand Down Expand Up @@ -593,7 +593,7 @@ static void _error(int class, char *fn, unsigned int ln, char* fmt, va_list ap)
break;
#endif /* DEBUG */
default:
/*NOTREACHED*/;
UNREACHABLE_CODE;
}

#ifdef LINT
Expand Down
8 changes: 4 additions & 4 deletions lang/cem/cemcom.ansi/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int rank_of(int oper)
case ',':
return 15;
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

void dot2expr(struct expr **expp)
Expand All @@ -123,7 +123,7 @@ void dot2expr(struct expr **expp)
break;
default:
crash("bad conversion to expression");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down Expand Up @@ -306,7 +306,7 @@ writh ivalue, int fund)
break;
default:
crash("(fill_int_expr) bad fund %s\n", symbol2str(fund));
/*NOTREACHED*/
UNREACHABLE_CODE;
}
ex->ex_class = Value;
ex->VL_CLASS = Const;
Expand Down Expand Up @@ -488,7 +488,7 @@ int is_zero_cst(register struct expr *expr)
flt_arith2flt((arith) 0, &var, 0);
return flt_cmp(&var, &(expr->FL_ARITH)) == 0;
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

void free_expression(register struct expr *expr)
Expand Down
8 changes: 4 additions & 4 deletions lang/cem/cemcom.ansi/idf.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void global_redecl(register struct idf *idf, int new_sc, struct type *tp)
break;
default:
crash("bad storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
break;
case GLOBAL:
Expand All @@ -359,7 +359,7 @@ void global_redecl(register struct idf *idf, int new_sc, struct type *tp)
break;
default:
crash("bad storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
break;
case STATIC:
Expand All @@ -373,7 +373,7 @@ void global_redecl(register struct idf *idf, int new_sc, struct type *tp)
break;
default:
crash("bad storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
break;
case ENUM:
Expand All @@ -382,7 +382,7 @@ void global_redecl(register struct idf *idf, int new_sc, struct type *tp)
break;
default:
crash("bad storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lang/cem/cemcom.ansi/l_lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ value2state(expr, val)

default:
NOTREACHED();
/* NOTREACHED */
UNREACHABLE_CODE;
}
}

Expand Down Expand Up @@ -398,7 +398,7 @@ add_expr_state(value, to_state, espp)
break;
default:
NOTREACHED();
/* NOTREACHED */
UNREACHABLE_CODE;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lang/cem/cemcom.ansi/l_outdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ output_def(od)
break;
default:
NOTREACHED();
/*NOTREACHED*/
UNREACHABLE_CODE;
}
printf(":");
outargtype(od->od_type);
Expand Down Expand Up @@ -437,7 +437,7 @@ outarg(arg)

default:
NOTREACHED();
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down Expand Up @@ -514,7 +514,7 @@ outargtype(tp)
break;
default:
NOTREACHED();
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lang/cem/cemcom.ansi/l_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ lint_case_stmt(dflt)

default:
NOTREACHED();
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down Expand Up @@ -1022,7 +1022,7 @@ lint_break_stmt()

default:
NOTREACHED();
/*NOTREACHED*/
UNREACHABLE_CODE;
}
top_ls->ls_current->st_notreached = 1;
top_ls->ls_current->st_warned = 0;
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom.ansi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int main(int argc, char *argv[])
#endif /* DEBUG */

sys_stop(err_occurred ? S_EXIT : S_END);
/*NOTREACHED*/
UNREACHABLE_CODE;
}

char *source = 0;
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom.ansi/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ register struct proto *pl)
break;
default:
crash("bad constructor in construct_type");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
return dtp;
}
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/LLlex.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ GetToken(ptok)
default: /* this cannot happen */
crash("bad class for char 0%o", ch);
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

skipcomment()
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ is_test_op(oper)
default:
return 0;
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

any2opnd(expp, oper)
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/ch7.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ ch7cast(expp, oper, tp)
#else /* NOFLOAT */
else {
crash("(ch7cast) floats not implemented\n");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
#endif /* NOFLOAT */
}
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ code_declaration(idf, expr, lvl, sc)
break;
default:
crash("bad local storage class");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ conversion(from_type, to_type)
#endif /* NOFLOAT */
default:
crash("(conversion) illegal type conversion");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
if ((int)(to_type->tp_size) < (int)word_size
#ifndef NOFLOAT
Expand Down
2 changes: 1 addition & 1 deletion lang/cem/cemcom/domacro.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ getparams(buf, parbuf)
LoadChar(c);
c = skipspaces(c,0);
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

EXPORT
Expand Down
10 changes: 5 additions & 5 deletions lang/cem/cemcom/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ crash(char *fmt, ...)
#else /* DEBUG */
sys_stop(S_EXIT);
#endif /* DEBUG */
/* NOTREACHED */
UNREACHABLE_CODE;
}

/*VARARGS*/
Expand All @@ -218,7 +218,7 @@ fatal(char *fmt, ...)

if (C_busy()) C_close();
sys_stop(S_EXIT);
/*NOTREACHED*/
UNREACHABLE_CODE;
}
#else
/*VARARGS*/
Expand Down Expand Up @@ -388,7 +388,7 @@ crash(va_alist) /* fmt, args */
#else /* DEBUG */
sys_stop(S_EXIT);
#endif /* DEBUG */
/* NOTREACHED */
UNREACHABLE_CODE;
}

/*VARARGS*/
Expand All @@ -406,7 +406,7 @@ fatal(va_alist) /* fmt, args */

if (C_busy()) C_close();
sys_stop(S_EXIT);
/*NOTREACHED*/
UNREACHABLE_CODE;
}
#endif

Expand Down Expand Up @@ -472,7 +472,7 @@ _error(class, fn, ln, fmt, ap)
remark = "fatal error --";
break;
default:
/*NOTREACHED*/;
UNREACHABLE_CODE;
}

#ifdef LINT
Expand Down
6 changes: 3 additions & 3 deletions lang/cem/cemcom/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ rank_of(oper)
case ',':
return 15;
}
/*NOTREACHED*/
UNREACHABLE_CODE;
}

#ifndef NOROPTION
Expand Down Expand Up @@ -151,7 +151,7 @@ dot2expr(expp)
#endif /* NOFLOAT */
default:
crash("bad conversion to expression");
/*NOTREACHED*/
UNREACHABLE_CODE;
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ fill_int_expr(ex, ivalue, fund)
break;
default:
crash("(intexpr) bad fund %s\n", symbol2str(fund));
/*NOTREACHED*/
UNREACHABLE_CODE;
}
ex->ex_class = Value;
ex->VL_CLASS = Const;
Expand Down
Loading

0 comments on commit 183aa1e

Please sign in to comment.