commit 3ca1b555fb64c22f3134592a6c56c948ac59e16b
parent fe1232cd1341860eb0b5a56aa98fb8cb95052e89
Author: Kyle Milz <kyle@0x30.net>
Date: Thu, 11 Aug 2016 23:49:10 -0600
src: add binary operator support
Diffstat:
17 files changed, 111 insertions(+), 24 deletions(-)
diff --git a/src/check.in b/src/check.in
@@ -45,7 +45,8 @@ FINE[8]="Switch statements"
FINE[9]="Return statement values"
FINE[10]="Call expressions"
FINE[11]="Total statements"
-FINE[12]="Errors rewriting source"
+FINE[12]="Binary operators"
+FINE[13]="Errors rewriting source"
fine_len=${#FINE[@]}
echo -n Checking .
diff --git a/src/inst_visitor.cc b/src/inst_visitor.cc
@@ -104,6 +104,12 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s)
else if (clang::isa<clang::CallExpr>(s)) {
modify_stmt(s, m_counters[CALL_EXPR]);
}
+ else if (clang::isa<clang::BinaryOperator>(s)) {
+ // If we can't rewrite the last token, don't even start.
+ if (s->getLocEnd().isMacroID())
+ return true;
+ modify_stmt(s, m_counters[BIN_OPER]);
+ }
return true;
}
diff --git a/src/inst_visitor.h b/src/inst_visitor.h
@@ -13,6 +13,7 @@ enum counters {
RET_STMT_VAL,
CALL_EXPR,
TOTAL_STMT,
+ BIN_OPER,
REWRITE_ERROR,
NCOUNTERS
};
@@ -32,6 +33,7 @@ public:
"Return statement values",
"Call expressions",
"Total statements",
+ "Binary operators",
"Errors rewriting source code"
}),
m_TheRewriter(R),
diff --git a/t/inst_binop.t b/t/inst_binop.t
@@ -0,0 +1,71 @@
+#!/bin/sh -e
+echo 1..3
+
+. test/utils.sh
+setup
+
+cat <<EOF > enum.c
+enum ASDF {
+ ONE = (1 << 0),
+ TWO = (1 << 1),
+ THR = (1 << 2)
+};
+
+static int foo = 5 + 5;
+
+static const struct {
+ int i;
+ unsigned char data[0 + 64 * 6];
+} blah;
+
+int main(void) {
+ if (4 + 3)
+ return 0;
+}
+EOF
+
+cat <<EOF > enum.c.inst_good
+enum ASDF {
+ ONE = (1 << 0),
+ TWO = (1 << 1),
+ THR = (1 << 2)
+};
+
+static int foo = 5 + 5;
+
+static const struct {
+ int i;
+ unsigned char data[0 + 64 * 6];
+} blah;
+
+int main(void) {citrun_start();++_citrun_lines[13];
+ if ((++_citrun_lines[14], (++_citrun_lines[14], 4 + 3)))
+ return (++_citrun_lines[15], 0);
+}
+EOF
+
+cat <<EOF > check.good
+Checking ..done
+
+Summary:
+ 1 Log files found
+ 1 Source files input
+ 1 Calls to the instrumentation tool
+ 1 Instrument successes
+
+Totals:
+ 18 Lines of source code
+ 32 Lines of instrumentation header
+ 1 Functions called 'main'
+ 1 Function definitions
+ 1 If statements
+ 1 Return statement values
+ 7 Total statements
+ 1 Binary operators
+EOF
+
+citrun-inst -c enum.c
+citrun-check > check.out
+
+diff -u enum.c.inst_good enum.c.citrun && echo "ok 2 - instrumented source diff"
+diff -u check.good check.out && echo "ok 3 - citrun.log diff"
diff --git a/t/inst_correct.t b/t/inst_correct.t
@@ -51,6 +51,7 @@ Totals:
5 Return statement values
4 Call expressions
58 Total statements
+ 7 Binary operators
EOF
cc -o fib fib.c
diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t
@@ -21,7 +21,7 @@ main(int argc, char *argv[])
{citrun_start();++_citrun_lines[0];++_citrun_lines[1];++_citrun_lines[2];
do {
argc++;
- } while ((++_citrun_lines[5], argc != 10));
+ } while ((++_citrun_lines[5], (++_citrun_lines[5], argc != 10)));
return (++_citrun_lines[6], 0);
}
EOF
@@ -43,10 +43,10 @@ Totals:
1 Do while loops
1 Return statement values
11 Total statements
+ 1 Binary operators
EOF
citrun-inst -c while.c
-cat citrun.log
citrun-check > check.out
diff -u while.c.inst_good while.c.citrun && echo "ok 2 - instrumented source diff"
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -25,7 +25,7 @@ main(int argc, char *argv[])
{citrun_start();++_citrun_lines[2];++_citrun_lines[3];++_citrun_lines[4];
for (;;);
- for (argc = 0; (++_citrun_lines[7], argc < 10); argc++)
+ for ((++_citrun_lines[7], argc = 0); (++_citrun_lines[7], (++_citrun_lines[7], argc < 10)); argc++)
argv++;
}
EOF
@@ -46,6 +46,7 @@ Totals:
1 Function definitions
1 For loops
15 Total statements
+ 2 Binary operators
EOF
citrun-inst -c for.c
diff --git a/t/inst_if.t b/t/inst_if.t
@@ -17,8 +17,6 @@ main(int argc, char *argv[])
if ((argc = 2))
return 5;
- if (argc && argc + 1)
- return 0;
else
exit(0);
}
@@ -30,17 +28,15 @@ cat <<EOF > if.c.inst_good
int
main(int argc, char *argv[])
{citrun_start();++_citrun_lines[2];++_citrun_lines[3];++_citrun_lines[4];
- if ((++_citrun_lines[5], argc == 1))
+ if ((++_citrun_lines[5], (++_citrun_lines[5], argc == 1)))
return (++_citrun_lines[6], 1);
else
(++_citrun_lines[8], exit(14));
- if ((++_citrun_lines[10], (argc = 2)))
+ if ((++_citrun_lines[10], ((++_citrun_lines[10], argc = 2))))
return (++_citrun_lines[11], 5);
- if ((++_citrun_lines[12], argc && argc + 1))
- return (++_citrun_lines[13], 0);
else
- (++_citrun_lines[15], exit(0));
+ (++_citrun_lines[13], exit(0));
}
EOF
@@ -54,14 +50,15 @@ Summary:
1 Instrument successes
Totals:
- 18 Lines of source code
+ 16 Lines of source code
32 Lines of instrumentation header
1 Functions called 'main'
1 Function definitions
- 3 If statements
- 3 Return statement values
+ 2 If statements
+ 2 Return statement values
2 Call expressions
- 33 Total statements
+ 23 Total statements
+ 2 Binary operators
EOF
citrun-inst -c if.c
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -60,6 +60,7 @@ Instrumentation of '' finished:
4 Return statement values
4 Call expressions
58 Total statements
+ 6 Binary operators
Modified source written successfully.
Instrumentation successful.
Running native compiler on modified source code.
diff --git a/t/inst_return.t b/t/inst_return.t
@@ -26,7 +26,7 @@ int foo() {++_citrun_lines[0];
int main(void) {citrun_start();++_citrun_lines[4];
return (++_citrun_lines[5], 10);
- return (++_citrun_lines[7], 10 + 10);
+ return (++_citrun_lines[7], (++_citrun_lines[7], 10 + 10));
return (++_citrun_lines[9], (++_citrun_lines[9], foo()));
}
@@ -49,6 +49,7 @@ Totals:
4 Return statement values
1 Call expressions
14 Total statements
+ 1 Binary operators
EOF
citrun-inst -c return.c
diff --git a/t/inst_while.t b/t/inst_while.t
@@ -20,10 +20,10 @@ cat <<EOF > while.c.inst_good
int
main(int argc, char *argv[])
{citrun_start();++_citrun_lines[0];++_citrun_lines[1];++_citrun_lines[2];
- while ((++_citrun_lines[3], argc < 17))
+ while ((++_citrun_lines[3], (++_citrun_lines[3], argc < 17)))
argc++;
- while ((++_citrun_lines[6], (argc && argv)));
+ while ((++_citrun_lines[6], ((++_citrun_lines[6], argc && argv))));
return (++_citrun_lines[7], 0);
}
EOF
@@ -45,6 +45,7 @@ Totals:
2 While loops
1 Return statement values
18 Total statements
+ 2 Binary operators
EOF
citrun-inst -c while.c
diff --git a/t/rt_dynamic.t b/t/rt_dynamic.t
@@ -25,9 +25,9 @@ my @lines = @{ $data->{$s0} };
is( $lines[$_], 0, "src 0 line $_ check" ) for (0..5);
is( $lines[$_], 1, "src 0 line $_ check" ) for (6..8);
is( $lines[$_], 0, "src 0 line $_ check" ) for (9..10);
-is( $lines[11], 1, "src 0 line 11 check" );
+is( $lines[11], 2, "src 0 line 11 check" );
is( $lines[$_], 0, "src 0 line $_ check" ) for (12..13);
-is( $lines[14], 1, "src 0 line 14 check" );
+is( $lines[14], 2, "src 0 line 14 check" );
is( $lines[15], 0, "src 0 line 15 check" );
is( $lines[16], 2, "src 0 line 16 check" );
is( $lines[$_], 0, "src 0 line $_ check" ) for (17..18);
diff --git a/tt/ccitrunrun.t b/tt/ccitrunrun.t
@@ -86,6 +86,7 @@ Totals:
89 Return statement values
1097 Call expressions
16820 Total statements
+ 1559 Binary operators
6 Errors rewriting source
EOF
diff --git a/tt/git.t b/tt/git.t
@@ -315,7 +315,8 @@ Totals:
272 Switch statements
6825 Return statement values
30619 Call expressions
- 528856 Total statements
+ 528570 Total statements
+ 34625 Binary operators
1530 Errors rewriting source
EOF
diff --git a/tt/mutt.t b/tt/mutt.t
@@ -146,7 +146,8 @@ Totals:
104 Switch statements
1956 Return statement values
6894 Call expressions
- 153801 Total statements
+ 153793 Total statements
+ 12082 Binary operators
558 Errors rewriting source
EOF
diff --git a/tt/nvi.t b/tt/nvi.t
@@ -158,7 +158,8 @@ Totals:
100 Switch statements
979 Return statement values
1646 Call expressions
- 49388 Total statements
+ 49384 Total statements
+ 4008 Binary operators
353 Errors rewriting source
EOF
diff --git a/tt/openssl.t b/tt/openssl.t
@@ -728,7 +728,8 @@ Totals:
275 Switch statements
7438 Return statement values
18751 Call expressions
- 419379 Total statements
+ 418826 Total statements
+ 27553 Binary operators
2912 Errors rewriting source
EOF