commit a603e6195e2a2a20ef4ce16e0db96c00ece8959a
parent 5d0d78286053b590d6739d92f179634e560c9118
Author: Kyle Milz <kyle@0x30.net>
Date: Wed, 10 Aug 2016 22:12:45 -0600
src: don't instrument in system headers
Diffstat:
7 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/src/inst_visitor.cc b/src/inst_visitor.cc
@@ -21,6 +21,22 @@
#include "inst_visitor.h"
bool
+RewriteASTVisitor::TraverseStmt(clang::Stmt *s)
+{
+ if (s == NULL)
+ return true;
+
+ clang::SourceLocation start_loc = s->getLocStart();
+ clang::FullSourceLoc full_loc(start_loc, m_SM);
+
+ if (full_loc.isInSystemHeader())
+ return false;
+
+ RecursiveASTVisitor<RewriteASTVisitor>::TraverseStmt(s);
+ return true;
+}
+
+bool
RewriteASTVisitor::VisitVarDecl(clang::VarDecl *d)
{
return true;
diff --git a/src/inst_visitor.h b/src/inst_visitor.h
@@ -35,9 +35,12 @@ public:
"Errors rewriting source code"
}),
m_TheRewriter(R),
- m_SM(R.getSourceMgr())
+ m_SM(R.getSourceMgr()),
+ m_lopt(R.getLangOpts())
{}
+ virtual bool TraverseStmt(clang::Stmt *);
+
bool VisitVarDecl(clang::VarDecl *d);
bool VisitStmt(clang::Stmt *s);
bool VisitFunctionDecl(clang::FunctionDecl *f);
@@ -52,5 +55,4 @@ private:
clang::Rewriter &m_TheRewriter;
clang::SourceManager &m_SM;
clang::LangOptions m_lopt;
-
};
diff --git a/t/inst_correct.t b/t/inst_correct.t
@@ -48,9 +48,9 @@ Totals:
1 Functions called 'main'
5 Function definitions
3 If statements
- 6 Return statement values
+ 5 Return statement values
4 Call expressions
- 198 Total statements
+ 58 Total statements
EOF
cc -o fib fib.c
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -45,8 +45,7 @@ Totals:
1 Functions called 'main'
4 Function definitions
1 For loops
- 1 Return statement values
- 155 Total statements
+ 15 Total statements
EOF
citrun-inst -c for.c
diff --git a/t/inst_if.t b/t/inst_if.t
@@ -59,9 +59,9 @@ Totals:
1 Functions called 'main'
4 Function definitions
3 If statements
- 4 Return statement values
+ 3 Return statement values
2 Call expressions
- 173 Total statements
+ 33 Total statements
EOF
citrun-inst -c if.c
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -57,9 +57,9 @@ Instrumentation of '' finished:
1 Functions called ''
5 Function definitions
2 If statements
- 5 Return statement values
+ 4 Return statement values
4 Call expressions
- 198 Total statements
+ 58 Total statements
Modified source written successfully.
Instrumentation successful.
Running native compiler on modified source code.
diff --git a/t/inst_stdout.t b/t/inst_stdout.t
@@ -31,10 +31,9 @@ Totals:
32 Lines of instrumentation header
1 Functions called 'main'
5 Function definitions
- 1 If statements
- 4 Return statement values
- 2 Call expressions
- 191 Total statements
+ 1 Return statement values
+ 1 Call expressions
+ 9 Total statements
EOF
cc -o hello hello.c