From 75f127af7c635c0963e9c2ce5857be9b282ac435 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 3 Mar 2021 14:17:48 +0000 Subject: Add `-vet-extra` (checks for unneeded casts and transmutes) --- src/check_expr.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index a31f1c871..bcd16ca25 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -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; -- cgit v1.2.3