]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Apply constant promotion for FI_EQ / FI_NEQ
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Fri, 4 Mar 2022 16:51:50 +0000 (17:51 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Mon, 27 Jun 2022 19:13:31 +0000 (21:13 +0200)
Equality comparison is defined on all values, even of different
types, but we still want to do constant promotion if possible.

filter/data.c
filter/decl.m4
filter/f-inst.c
filter/test.conf

index 276738a900ebb5a8ce80b465516d35fc1f85d566..2bb5920cf0da220f0ba620852c935205c3e6945f 100644 (file)
@@ -192,7 +192,7 @@ val_compare(const struct f_val *v1, const struct f_val *v2)
     if (val_is_ip4(v1) && (v2->type == T_QUAD))
       return uint_cmp(ipa_to_u32(v1->val.ip), v2->val.i);
 
-    debug( "Types do not match in val_compare\n" );
+    DBG( "Types do not match in val_compare\n" );
     return F_CMP_ERROR;
   }
 
index fc26e19382cee70cd52b32faf429b20005742338..a2a8c88af2620335e141e0a9092847a8ad2c3962 100644 (file)
@@ -186,6 +186,12 @@ if (f$1->type && f$2->type && (f$1->type != f$2->type) &&
   cf_error("Arguments $1 and $2 of %s must be of the same type", f_instruction_name(what->fi_code));
 FID_INTERPRET_BODY()')
 
+m4_define(ARG_PREFER_SAME_TYPE, `
+FID_NEW_BODY()m4_dnl
+if (f$1->type && f$2->type && (f$1->type != f$2->type))
+   (void) (f_const_promotion(f$2, f$1->type) || f_const_promotion(f$1, f$2->type));
+FID_INTERPRET_BODY()')
+
 #      Executing another filter line. This replaces the recursion
 #      that was needed in the former implementation.
 m4_define(LINEX, `FID_INTERPRET_EXEC()LINEX_($1)FID_INTERPRET_NEW()return $1 FID_INTERPRET_BODY()')
index d321f06d26ae7335437c15384c9e298eab498e56..500732c6bcfedf31beaa6237f5d55f905bc710d0 100644 (file)
   INST(FI_NEQ, 2, 1) {
     ARG_ANY(1);
     ARG_ANY(2);
+    ARG_PREFER_SAME_TYPE(1, 2);
     RESULT(T_BOOL, i, !val_same(&v1, &v2));
   }
 
   INST(FI_EQ, 2, 1) {
     ARG_ANY(1);
     ARG_ANY(2);
+    ARG_PREFER_SAME_TYPE(1, 2);
     RESULT(T_BOOL, i, val_same(&v1, &v2));
   }
 
index 50c58b3a0d2f3f2f23b90dce971110300b30ece8..401a999bca04b3e97e4b9b98f86d146dea3d1221 100644 (file)
@@ -498,8 +498,8 @@ prefix set s1;
        s0 = [];
        s1 = [];
        bt_assert(pxs != s0);
-       bt_assert(pxs  = s1);
-       #bt_assert(pxs  = []);
+       bt_assert(pxs = s1);
+       bt_assert(pxs = []);
 }
 
 function t_prefix_set()
@@ -507,7 +507,7 @@ prefix set pxs;
 {
        pxs = [];
        bt_assert(format(pxs) = "[]");
-       #bt_assert(pxs = []);
+       bt_assert(pxs = []);
        bt_assert(1.2.0.0/16 !~ []);
        bt_assert(1.2.0.0/16 !~ pxs);
 
@@ -600,7 +600,7 @@ prefix set pxs;
 {
        pxs = [];
        bt_assert(format(pxs) = "[]");
-       #bt_assert(pxs = []);
+       bt_assert(pxs = []);
        bt_assert(12::34/128 !~ []);
        bt_assert(12::34/128 !~ pxs);