diff options
author | Manuel Klimek <klimek@google.com> | 2011-05-31 23:49:32 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2011-05-31 23:49:32 +0000 |
commit | 64cbdf370984783911bb6d3bc25ec35a8b59e998 (patch) | |
tree | d9f1e5c11584852365aeef877c1f1a36db5548e3 /test/Tooling | |
parent | d65e091631cc521fcb95a16d6587c0fed8b7164b (diff) |
This patch implements an AST matching framework that allows to write
tools that match on the C++ ASTs. The main interface is in ASTMatchers.h,
an example implementation of a tool that removes redundant .c_str() calls
is in the example RemoveCStrCalls.cpp.
Various contributions:
Zhanyong Wan, Chandler Carruth, Marcin Kowalczyk, Wei Xu, James Dennett.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132374 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Tooling')
-rw-r--r-- | test/Tooling/remove-cstr-calls.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/Tooling/remove-cstr-calls.cpp b/test/Tooling/remove-cstr-calls.cpp new file mode 100644 index 0000000000..a43960aec5 --- /dev/null +++ b/test/Tooling/remove-cstr-calls.cpp @@ -0,0 +1,20 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo '[{"directory":".","command":"clang++ '$(llvm-config --cppflags all)' -c %s","file":"%s"}]' > %t/compile_commands.json +// RUN: remove-cstr-calls %t %s | FileCheck %s + +#include <string> + +namespace llvm { struct StringRef { StringRef(const char *p); }; } + +void f1(const std::string &s) { + f1(s.c_str()); // CHECK:remove-cstr-calls.cpp:11:6:11:14:s +} +void f2(const llvm::StringRef r) { + std::string s; + f2(s.c_str()); // CHECK:remove-cstr-calls.cpp:15:6:15:14:s +} +void f3(const llvm::StringRef &r) { + std::string s; + f3(s.c_str()); // CHECK:remove-cstr-calls.cpp:19:6:19:14:s +} |