diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2022-03-04 17:51:50 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2022-06-27 21:13:31 +0200 |
commit | fb1d8f65136aa6190b527b691f24abe16a461471 (patch) | |
tree | 02fcdf35aa6c32167b78f82d2e9666ed1a58686f /filter | |
parent | b2d6d2948af268812a8f55f260d340194eb3f7ac (diff) |
Filter: Apply constant promotion for FI_EQ / FI_NEQ
Equality comparison is defined on all values, even of different
types, but we still want to do constant promotion if possible.
Diffstat (limited to 'filter')
-rw-r--r-- | filter/data.c | 2 | ||||
-rw-r--r-- | filter/decl.m4 | 6 | ||||
-rw-r--r-- | filter/f-inst.c | 2 | ||||
-rw-r--r-- | filter/test.conf | 8 |
4 files changed, 13 insertions, 5 deletions
diff --git a/filter/data.c b/filter/data.c index 276738a9..2bb5920c 100644 --- a/filter/data.c +++ b/filter/data.c @@ -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; } diff --git a/filter/decl.m4 b/filter/decl.m4 index fc26e193..a2a8c88a 100644 --- a/filter/decl.m4 +++ b/filter/decl.m4 @@ -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()') diff --git a/filter/f-inst.c b/filter/f-inst.c index d321f06d..500732c6 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -423,12 +423,14 @@ 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)); } diff --git a/filter/test.conf b/filter/test.conf index 50c58b3a..401a999b 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -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); |