commit fe98fdcaa9c9aafe357345b67bcb9995986aac53
parent b79644529908fe05723f86b31bcb123105cd7ae5
Author: kyle <kyle@getaddrinfo.net>
Date: Mon, 26 Oct 2015 22:21:07 -0600
instrument: add while loop support
Diffstat:
4 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/instrument.cpp b/instrument.cpp
@@ -68,6 +68,13 @@ public:
TheRewriter.InsertTextBefore(RetValue->getLocStart(),
ss.str());
}
+ else if (isa<WhileStmt>(s)) {
+ WhileStmt *WhileStatement = cast<WhileStmt>(s);
+ Stmt *Cond = WhileStatement->getCond();
+ ss << ", ";
+ TheRewriter.InsertTextBefore(Cond->getLocStart(),
+ ss.str());
+ }
else if (isa<BreakStmt>(s) || isa<ContinueStmt>(s) ||
isa<DeclStmt>(s) || isa<SwitchStmt>(s) ||
isa<SwitchCase>(s)) {
diff --git a/tests/while_loops/instrumented.c b/tests/while_loops/instrumented.c
@@ -0,0 +1,13 @@
+static unsigned int lines[76];
+int
+main(void)
+{
+ lines[4] = 1; int i;
+
+ i = 0;
+ while (lines[7] = 1, i < 10) {
+ i++;
+ }
+
+ return lines[11] = 1, i;
+}
diff --git a/tests/while_loops/prog.c b/tests/while_loops/prog.c
@@ -0,0 +1,12 @@
+int
+main(void)
+{
+ int i;
+
+ i = 0;
+ while (i < 10) {
+ i++;
+ }
+
+ return i;
+}
diff --git a/tests/while_loops/test.sh b/tests/while_loops/test.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+${1}
+if [ $? -ne 10 ]; then
+ echo "${0}: basic while loops broken"
+ exit 1
+fi