citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit c27a08761a2f73976cb99cbc951677d96324d0ff
parent 12bab1f71d08548b637c43ae8b06422f06096f40
Author: kyle <kyle@getaddrinfo.net>
Date:   Sun,  1 Nov 2015 20:52:09 -0700

instrument: add switch statement support

Diffstat:
Minstrument/instrumenter.cpp | 6+++++-
Atests/switch/Makefile | 11+++++++++++
Atests/switch/switch.c | 12++++++++++++
Atests/switch/switch.c.inst_good | 15+++++++++++++++
Atests/switch/test.sh | 0
5 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/instrument/instrumenter.cpp b/instrument/instrumenter.cpp @@ -38,13 +38,17 @@ instrumenter::VisitStmt(Stmt *s) WhileStmt *WhileStatement = cast<WhileStmt>(s); stmt_to_inst = WhileStatement->getCond(); } + else if (isa<SwitchStmt>(s)) { + SwitchStmt *SwitchStatement = cast<SwitchStmt>(s); + stmt_to_inst = SwitchStatement->getCond(); + } else if (isa<ReturnStmt>(s)) { ReturnStmt *ReturnStatement = cast<ReturnStmt>(s); stmt_to_inst = ReturnStatement->getRetValue(); } /* else if (isa<BreakStmt>(s) || isa<ContinueStmt>(s) || - || isa<SwitchStmt>(s) || isa<SwitchCase>(s)) { + || isa<SwitchCase>(s)) { } */ else if (isa<DeclStmt>(s)) { diff --git a/tests/switch/Makefile b/tests/switch/Makefile @@ -0,0 +1,11 @@ +BIN = prog +SRCS = switch.c +OBJS = $(SRCS:c=o) + +$(BIN): $(OBJS) + $(CC) -o $(BIN) $(OBJS) $(LDLIBS) + +diff: + diff -u switch.c.inst{_good,} + +.include "../Makefile.test" diff --git a/tests/switch/switch.c b/tests/switch/switch.c @@ -0,0 +1,12 @@ +int +main(void) +{ + int i; + + switch (i) { + case 0: + break; + case 1: + break; + } +} diff --git a/tests/switch/switch.c.inst_good b/tests/switch/switch.c.inst_good @@ -0,0 +1,15 @@ +unsigned int lines[81]; +int size = 81; +char file_name[] = "/home/kyle/src/scv/tests/switch/switch.c"; +int +main(void) +{ + int i; + + switch ((lines[6] = 1, i)) { + case 0: + break; + case 1: + break; + } +} diff --git a/tests/switch/test.sh b/tests/switch/test.sh