aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-03-03 14:17:48 +0000
committergingerBill <bill@gingerbill.org>2021-03-03 14:17:48 +0000
commit75f127af7c635c0963e9c2ce5857be9b282ac435 (patch)
treea2500d55290d6d66918cf5b7bf5fd451b7812eee /src/check_expr.cpp
parentc2794b62a92f6805723ee1b5bed1622858671478 (diff)
Add `-vet-extra` (checks for unneeded casts and transmutes)
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp16
1 files changed, 16 insertions, 0 deletions
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;