mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-17 16:48:43 +00:00
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.
This commit is contained in:
parent
b2d6d2948a
commit
fb1d8f6513
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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()')
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user