[clang-tools-extra] r279516 - [clang-tidy] Fix the order of ExtraArgsBefore
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 23 07:13:31 PDT 2016
Author: alexfh
Date: Tue Aug 23 09:13:31 2016
New Revision: 279516
URL: http://llvm.org/viewvc/llvm-project?rev=279516&view=rev
Log:
[clang-tidy] Fix the order of ExtraArgsBefore
Added tests for the relative order of -extra-arg(-before) and ExtraArgs(Before).
Added:
clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=279516&r1=279515&r2=279516&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Tue Aug 23 09:13:31 2016
@@ -426,10 +426,14 @@ runClangTidy(std::unique_ptr<ClangTidyOp
ArgumentsAdjuster PerFileExtraArgumentsInserter =
[&Context](const CommandLineArguments &Args, StringRef Filename) {
ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
- CommandLineArguments AdjustedArgs;
- if (Opts.ExtraArgsBefore)
- AdjustedArgs = *Opts.ExtraArgsBefore;
- AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
+ CommandLineArguments AdjustedArgs = Args;
+ if (Opts.ExtraArgsBefore) {
+ auto I = AdjustedArgs.begin();
+ if (I != AdjustedArgs.end() && !StringRef(*I).startswith("-"))
+ ++I; // Skip compiler binary name, if it is there.
+ AdjustedArgs.insert(I, Opts.ExtraArgsBefore->begin(),
+ Opts.ExtraArgsBefore->end());
+ }
if (Opts.ExtraArgs)
AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
Opts.ExtraArgs->end());
Modified: clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp?rev=279516&r1=279515&r2=279516&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp Tue Aug 23 09:13:31 2016
@@ -1,7 +1,22 @@
// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' %s -- | count 0
+//
+// Enable warnings using -config:
// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
// RUN: -config='{ExtraArgs: ["-Wshadow","-Wno-unused-variable"], ExtraArgsBefore: ["-Wno-shadow","-Wfloat-conversion","-Wunused-variable"]}' %s -- \
// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
+//
+// ... -extra-arg:
+// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
+// RUN: -extra-arg=-Wshadow -extra-arg=-Wno-unused-variable \
+// RUN: -extra-arg-before=-Wno-shadow -extra-arg-before=-Wfloat-conversion \
+// RUN: -extra-arg-before=-Wunused-variable %s -- \
+// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
+//
+// ... a combination of -config and -extra-arg(-before):
+// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
+// RUN: -config='{ExtraArgs: ["-Wno-unused-variable"], ExtraArgsBefore: ["-Wno-shadow","-Wfloat-conversion"]}' \
+// RUN: -extra-arg=-Wshadow -extra-arg-before=-Wunused-variable %s -- \
+// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
void f(float x) {
int a;
Added: clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp?rev=279516&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp Tue Aug 23 09:13:31 2016
@@ -0,0 +1,7 @@
+// RUN: clang-tidy -checks='-*,modernize-use-override' \
+// RUN: -config='{ExtraArgs: ["-DTEST4"], ExtraArgsBefore: ["-DTEST1"]}' \
+// RUN: -extra-arg=-DTEST3 -extra-arg-before=-DTEST2 %s -- -v 2>&1 \
+// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
+
+// CHECK: {{^}}clang Invocation:{{$}}
+// CHECK-NEXT: {{"-D" "TEST1" .*"-D" "TEST2" .*"-D" "TEST3" .*"-D" "TEST4"}}
More information about the cfe-commits
mailing list