Filter: make bitwise and, or, xor higher prio than relational expressions
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 22 Sep 2017 21:38:13 +0000 (17:38 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 6 Jun 2018 20:28:14 +0000 (16:28 -0400)
It seems that the usual use-case for bitwise ops are to apply them on
values rather than on the result of equality/inequality. Therefore, move
away from the C operator precedence order, and ensure bitwise and, or,
xor are higher priority than relational expressions (equality and
inequality).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/lib/lttng-ctl/filter/filter-parser.y
tests/regression/tools/filtering/test_valid_filter

index 2fa41ab405259d9eec1533ff47793a5d54cc3a26..e9c2e6aabe9c1ad25891052f2af76381b2d1202f 100644 (file)
@@ -596,22 +596,49 @@ shift_expression
                }
        ;
 
-relational_expression
+and_expression
        : shift_expression
                {       $$ = $1;                                        }
-       | relational_expression LT_OP shift_expression
+       | and_expression AND_BIN shift_expression
+               {
+                       $$ = make_op_node(parser_ctx, AST_OP_BIT_AND, $1, $3);
+               }
+       ;
+
+exclusive_or_expression
+       : and_expression
+               {       $$ = $1;                                        }
+       | exclusive_or_expression XOR_BIN and_expression
+               {
+                       $$ = make_op_node(parser_ctx, AST_OP_BIT_XOR, $1, $3);
+               }
+       ;
+
+inclusive_or_expression
+       : exclusive_or_expression
+               {       $$ = $1;                                        }
+       | inclusive_or_expression OR_BIN exclusive_or_expression
+               {
+                       $$ = make_op_node(parser_ctx, AST_OP_BIT_OR, $1, $3);
+               }
+       ;
+
+relational_expression
+       : inclusive_or_expression
+               {       $$ = $1;                                        }
+       | relational_expression LT_OP inclusive_or_expression
                {
                        $$ = make_op_node(parser_ctx, AST_OP_LT, $1, $3);
                }
-       | relational_expression GT_OP shift_expression
+       | relational_expression GT_OP inclusive_or_expression
                {
                        $$ = make_op_node(parser_ctx, AST_OP_GT, $1, $3);
                }
-       | relational_expression LE_OP shift_expression
+       | relational_expression LE_OP inclusive_or_expression
                {
                        $$ = make_op_node(parser_ctx, AST_OP_LE, $1, $3);
                }
-       | relational_expression GE_OP shift_expression
+       | relational_expression GE_OP inclusive_or_expression
                {
                        $$ = make_op_node(parser_ctx, AST_OP_GE, $1, $3);
                }
@@ -630,37 +657,10 @@ equality_expression
                }
        ;
 
-and_expression
-       : equality_expression
-               {       $$ = $1;                                        }
-       | and_expression AND_BIN equality_expression
-               {
-                       $$ = make_op_node(parser_ctx, AST_OP_BIT_AND, $1, $3);
-               }
-       ;
-
-exclusive_or_expression
-       : and_expression
-               {       $$ = $1;                                        }
-       | exclusive_or_expression XOR_BIN and_expression
-               {
-                       $$ = make_op_node(parser_ctx, AST_OP_BIT_XOR, $1, $3);
-               }
-       ;
-
-inclusive_or_expression
-       : exclusive_or_expression
-               {       $$ = $1;                                        }
-       | inclusive_or_expression OR_BIN exclusive_or_expression
-               {
-                       $$ = make_op_node(parser_ctx, AST_OP_BIT_OR, $1, $3);
-               }
-       ;
-
 logical_and_expression
-       : inclusive_or_expression
+       : equality_expression
                {       $$ = $1;                                        }
-       | logical_and_expression AND_OP inclusive_or_expression
+       | logical_and_expression AND_OP equality_expression
                {
                        $$ = make_op_node(parser_ctx, AST_OP_AND, $1, $3);
                }
index 725d82d4af74c87fad668619575c066edd1fa00b..6503cba2435a789e79ea313b9001a71d0c5bcaf6 100755 (executable)
@@ -24,8 +24,8 @@ STATS_BIN="$TESTDIR/utils/babelstats.pl"
 SESSION_NAME="valid_filter"
 NR_ITER=100
 NUM_GLOBAL_TESTS=2
-NUM_UST_TESTS=1098
-NUM_KERNEL_TESTS=1032
+NUM_UST_TESTS=1110
+NUM_KERNEL_TESTS=1044
 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
 
 source $TESTDIR/utils/utils.sh
@@ -719,10 +719,16 @@ UST_FILTERS=(
        "(1<<63) < 0"
 
        true_statement
-       "1<<1==2"       # C99 operator priority: comparator before bitwise
+       "(1<<2!=4)==0"  # operator priority: shift before equality
 
-       has_no_event
-       "!(1<<1==2)"    # C99 operator priority: comparator before bitwise
+       true_statement
+       "1&3==1"        # operator priority: masks before equality
+
+       true_statement
+       "(3|1==3)==1"   # operator priority: masks before equality
+
+       true_statement
+       "(2^1==3)==1"   # operator priority: masks before equality
 
        true_statement
        "(1 << 32) == 4294967296"
@@ -1192,10 +1198,16 @@ KERNEL_FILTERS=(
        "(1<<63) < 0"
 
        true_statement
-       "1<<1==2"       # C99 operator priority: comparator before bitwise
+       "(1<<2!=4)==0"  # operator priority: shift before equality
 
-       has_no_event
-       "!(1<<1==2)"    # C99 operator priority: comparator before bitwise
+       true_statement
+       "1&3==1"        # operator priority: masks before equality
+
+       true_statement
+       "(3|1==3)==1"   # operator priority: masks before equality
+
+       true_statement
+       "(2^1==3)==1"   # operator priority: masks before equality
 
        true_statement
        "(1 << 32) == 4294967296"
This page took 0.028925 seconds and 4 git commands to generate.