diff --git a/op-finder/OperationFinder.cpp b/op-finder/OperationFinder.cpp index 128d4ea..bc6eecf 100644 --- a/op-finder/OperationFinder.cpp +++ b/op-finder/OperationFinder.cpp @@ -31,19 +31,32 @@ StatementMatcher UnaryArithmeticMatcher = StatementMatcher CompoundMatcher = compoundStmt().bind("compound_stmt"); +//StatementMatcher ForStatementMatcher = +// forStmt(hasInitStatement(expr().bind("init"))).bind("for_stmt"); + template StringRef getOpcode(const TOp *op) { return op->getOpcodeStr(op->getOpcode()); } +SourceLocation ResolveOperationSourceLocation(const SourceManager& source_manager, const SourceLocation& original) +{ + if (source_manager.isMacroBodyExpansion(original)) + { + return source_manager.getExpansionLoc(original); + } + + return original; +} + } void OperationFinder::addMatcher(MatchFinder &finder) { finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, ArithmeticMatcher), this); finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, AssignmentMatcher), this); - finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, CompoundMatcher), this); + //finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, CompoundMatcher), this); finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, UnaryArithmeticMatcher), this); } @@ -73,9 +86,8 @@ void OperationFinder::_processAssignment(const clang::ast_matchers::MatchFinder: assert(op); - const auto& loc = op->getBeginLoc(); const auto& source_manager = *result.SourceManager; - + const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc()); llvm::outs() << source_manager.getFilename(loc) << ":" << source_manager.getSpellingLineNumber(loc) << ":" @@ -93,8 +105,8 @@ void OperationFinder::_processArithmetic(const MatchFinder::MatchResult& result) assert(op); - const auto& loc = op->getBeginLoc(); const auto& source_manager = *result.SourceManager; + const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc()); llvm::outs() << source_manager.getFilename(loc) << ":" << source_manager.getSpellingLineNumber(loc) << ":" @@ -117,8 +129,8 @@ void OperationFinder::_processCompoundStmt(const clang::ast_matchers::MatchFinde if (!op || !op->isCompoundAssignmentOp()) return; - const auto& loc = op->getBeginLoc(); const auto& source_manager = *result.SourceManager; + const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc()); llvm::outs() << source_manager.getFilename(loc) << ":" << source_manager.getSpellingLineNumber(loc) << ":" @@ -138,8 +150,8 @@ void OperationFinder::_processUnaryArithmetic(const MatchFinder::MatchResult &re assert(op); assert(lhs); - const auto& loc = lhs->getBeginLoc(); const auto& source_manager = *result.SourceManager; + const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc()); llvm::outs() << source_manager.getFilename(loc) << ":" << source_manager.getSpellingLineNumber(loc) << ":"