Add -vet-extra (checks for unneeded casts and transmutes)

This commit is contained in:
gingerBill
2021-03-03 14:17:48 +00:00
parent c2794b62a9
commit 75f127af7c
4 changed files with 28 additions and 3 deletions

View File

@@ -2388,6 +2388,14 @@ void check_cast(CheckerContext *c, Operand *x, Type *type) {
update_expr_type(c, x->expr, final_type, true);
}
if (build_context.vet_extra) {
if (are_types_identical(x->type, type)) {
gbString str = type_to_string(type);
warning(x->expr, "Unneeded cast to the same type '%s'", str);
gb_string_free(str);
}
}
x->type = type;
}
@@ -2429,6 +2437,14 @@ bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) {
return false;
}
if (build_context.vet_extra) {
if (are_types_identical(o->type, t)) {
gbString str = type_to_string(t);
warning(o->expr, "Unneeded transmute to the same type '%s'", str);
gb_string_free(str);
}
}
o->mode = Addressing_Value;
o->type = t;
return true;