r183320 - clang-check: Enable specification of additional compiler arguments
Pavel Labath
labath at google.com
Wed Jun 5 09:23:30 PDT 2013
Author: labath
Date: Wed Jun 5 11:23:30 2013
New Revision: 183320
URL: http://llvm.org/viewvc/llvm-project?rev=183320&view=rev
Log:
clang-check: Enable specification of additional compiler arguments
Summary:
This adds two command-line parameters: -extra-arg and -extra-arg-before, which
enable the user to pass additional parameters to the compiler command.
Reviewers: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D919
Added:
cfe/trunk/test/Tooling/clang-check-extra-arg.cpp
Modified:
cfe/trunk/tools/clang-check/ClangCheck.cpp
Added: cfe/trunk/test/Tooling/clang-check-extra-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-extra-arg.cpp?rev=183320&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/clang-check-extra-arg.cpp (added)
+++ cfe/trunk/test/Tooling/clang-check-extra-arg.cpp Wed Jun 5 11:23:30 2013
@@ -0,0 +1,5 @@
+// RUN: clang-check "%s" -extra-arg=-Wunimplemented-warning -extra-arg-before=-Wunimplemented-warning-before -- -c 2>&1 | FileCheck %s
+
+// CHECK: unknown warning option '-Wunimplemented-warning-before'
+// CHECK: unknown warning option '-Wunimplemented-warning'
+int a(){}
Modified: cfe/trunk/tools/clang-check/ClangCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=183320&r1=183319&r2=183320&view=diff
==============================================================================
--- cfe/trunk/tools/clang-check/ClangCheck.cpp (original)
+++ cfe/trunk/tools/clang-check/ClangCheck.cpp Wed Jun 5 11:23:30 2013
@@ -70,6 +70,11 @@ static cl::opt<bool> FixWhatYouCan(
"fix-what-you-can",
cl::desc(Options->getOptionHelpText(options::OPT_fix_what_you_can)));
+static cl::list<std::string> ArgsAfter("extra-arg",
+ cl::desc("Additional argument to append to the compiler command line"));
+static cl::list<std::string> ArgsBefore("extra-arg-before",
+ cl::desc("Additional argument to prepend to the compiler command line"));
+
namespace {
// FIXME: Move FixItRewriteInPlace from lib/Rewrite/Frontend/FrontendActions.cpp
@@ -123,6 +128,35 @@ public:
}
};
+class InsertAdjuster: public clang::tooling::ArgumentsAdjuster {
+public:
+ enum Position { BEGIN, END };
+
+ InsertAdjuster(const CommandLineArguments &Extra, Position Pos)
+ : Extra(Extra), Pos(Pos) {
+ }
+
+ virtual CommandLineArguments
+ Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE {
+ CommandLineArguments Return(Args);
+
+ CommandLineArguments::iterator I;
+ if (Pos == END) {
+ I = Return.end();
+ } else {
+ I = Return.begin();
+ ++I; // To leave the program name in place
+ }
+
+ Return.insert(I, Extra.begin(), Extra.end());
+ return Return;
+ }
+
+private:
+ const CommandLineArguments Extra;
+ const Position Pos;
+};
+
} // namespace
// Anonymous namespace here causes problems with gcc <= 4.4 on MacOS 10.6.
@@ -147,6 +181,12 @@ int main(int argc, const char **argv) {
CommonOptionsParser OptionsParser(argc, argv);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
+
+ if (ArgsAfter.size() > 0)
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsAfter, InsertAdjuster::END));
+ if (ArgsBefore.size() > 0)
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsBefore, InsertAdjuster::BEGIN));
+
if (Fixit)
return Tool.run(newFrontendActionFactory<FixItAction>());
clang_check::ClangCheckActionFactory Factory;
More information about the cfe-commits
mailing list