Re: [PATCH] D21298: [Clang-tidy] delete null check

2016-06-13 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

Some comments after a quick look to the code.



Comment at: clang-tidy/misc/DeleteNullCheck.cpp:22
@@ +21,3 @@
+void DeleteNullCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasDeleteExpr =
+  cxxDeleteExpr(hasDescendant(declRefExpr().bind("pointerToDelete")))

HasDeleteExpr -> DeleteExpr


Comment at: clang-tidy/misc/DeleteNullCheck.cpp:23
@@ +22,3 @@
+  const auto HasDeleteExpr =
+  cxxDeleteExpr(hasDescendant(declRefExpr().bind("pointerToDelete")))
+  .bind("deleteExpr");

The use of hasDescendant is Expensive. 
There is cast to ignore? You could probably just skip cast/parens.

If the intend of this match-statement is to match comparison against NULL, it 
should be expanded to be more precise.


Comment at: clang-tidy/misc/DeleteNullCheck.cpp:47
@@ +46,3 @@
+
+  if ((CastExpr->getCastKind() == CastKind::CK_PointerToBoolean) &&
+  (PointerToDelete->getDecl() == Cond->getDecl()) &&

This check could be moved to the matcher part above/
see ASTMatcher: hasCastKind


Comment at: clang-tidy/misc/DeleteNullCheck.cpp:48
@@ +47,3 @@
+  if ((CastExpr->getCastKind() == CastKind::CK_PointerToBoolean) &&
+  (PointerToDelete->getDecl() == Cond->getDecl()) &&
+  (!Compound || Compound->size() == 1)) {

see: equalsBoundNode


Comment at: clang-tidy/misc/DeleteNullCheck.cpp:49
@@ +48,3 @@
+  (PointerToDelete->getDecl() == Cond->getDecl()) &&
+  (!Compound || Compound->size() == 1)) {
+auto D = diag(

This check should be moved to the matcher part too.
see:statementCountIs


Repository:
  rL LLVM

http://reviews.llvm.org/D21298



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-15 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

I was wondering why we didn't created that Matcher: IgnoreImplicit

I believe it's more commonly used than 'ignoringExprWithCleanups'.

It can be implemented by calling 'Stmt.IgnoreImplicit'.

  /// Skip past any implicit AST nodes which might surround this
  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
  Stmt *IgnoreImplicit();



Comment at: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2018
@@ +2017,3 @@
+ ignoringParenImpCasts(unless(anything(;
+  EXPECT_TRUE(notMatches("float y = (float(0));",
+ varDecl(hasInitializer(ignoringExprWithCleanups(

nit: you can lift that expression to a local variable:

varDecl(hasInitializer(ignoringExprWithCleanups(
 ignoringParenImpCasts(integerLiteral()))

It's used 3 times.


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r272832 - Add support to clang-cl driver for /GS switch

2016-06-15 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed Jun 15 15:34:33 2016
New Revision: 272832

URL: http://llvm.org/viewvc/llvm-project?rev=272832&view=rev
Log:
Add support to clang-cl driver for /GS switch

Summary:
This patch is adding command-line support for the MSVC buffer security check.

The buffer security check is turned on with the '/GS' compiler switch.
https://msdn.microsoft.com/en-us/library/8dbf701c.aspx

The MSVC buffer security check in implemented here:
http://reviews.llvm.org/D20346

Reviewers: hans, rnk

Subscribers: chrisha, cfe-commits, rnk, hans, thakis

Differential Revision: http://reviews.llvm.org/D20347

Modified:
cfe/trunk/include/clang/Driver/CLCompatOptions.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cl-fallback.c
cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=272832&r1=272831&r2=272832&view=diff
==
--- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)
+++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Wed Jun 15 15:34:33 2016
@@ -77,6 +77,8 @@ def _SLASH_GR : CLFlag<"GR">, HelpText<"
 def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable emission of RTTI data">;
 def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">,
   Alias;
+def _SLASH_GS : CLFlag<"GS">, HelpText<"Enable buffer security check">;
+def _SLASH_GS_ : CLFlag<"GS-">, HelpText<"Disable buffer security check">;
 def _SLASH_Gs : CLJoined<"Gs">, HelpText<"Set stack probe size">,
   Alias;
 def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">,
@@ -287,7 +289,6 @@ def _SLASH_Fd : CLIgnoredJoined<"Fd">;
 def _SLASH_FC : CLIgnoredFlag<"FC">;
 def _SLASH_FS : CLIgnoredFlag<"FS">, HelpText<"Force synchronous PDB writes">;
 def _SLASH_GF : CLIgnoredFlag<"GF">;
-def _SLASH_GS_ : CLIgnoredFlag<"GS-">;
 def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">;
 def _SLASH_nologo : CLIgnoredFlag<"nologo">;
 def _SLASH_Ob1 : CLIgnoredFlag<"Ob1">;
@@ -329,7 +330,6 @@ def _SLASH_GL : CLFlag<"GL">;
 def _SLASH_GL_ : CLFlag<"GL-">;
 def _SLASH_Gm : CLFlag<"Gm">;
 def _SLASH_Gm_ : CLFlag<"Gm-">;
-def _SLASH_GS : CLFlag<"GS">;
 def _SLASH_GT : CLFlag<"GT">;
 def _SLASH_Guard : CLJoined<"guard:">;
 def _SLASH_GZ : CLFlag<"GZ">;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=272832&r1=272831&r2=272832&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jun 15 15:34:33 2016
@@ -6183,6 +6183,14 @@ void Clang::AddClangCLArgs(const ArgList
/*default=*/false))
 CmdArgs.push_back("-fno-rtti-data");
 
+  // This controls whether or not we emit stack-protector instrumentation.
+  // In MSVC, Buffer Security Check (/GS) is on by default.
+  if (Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
+   /*default=*/true)) {
+CmdArgs.push_back("-stack-protector");
+CmdArgs.push_back(Args.MakeArgString(Twine(LangOptions::SSPStrong)));
+  }
+
   // Emit CodeView if -Z7 is present.
   *EmitCodeView = Args.hasArg(options::OPT__SLASH_Z7);
   if (*EmitCodeView)
@@ -10022,6 +10030,11 @@ std::unique_ptr visualstudio::C
   if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
/*default=*/false))
 CmdArgs.push_back("/GR-");
+
+  if (Args.hasFlag(options::OPT__SLASH_GS_, options::OPT__SLASH_GS,
+   /*default=*/false))
+CmdArgs.push_back("/GS-");
+
   if (Arg *A = Args.getLastArg(options::OPT_ffunction_sections,
options::OPT_fno_function_sections))
 CmdArgs.push_back(A->getOption().getID() == options::OPT_ffunction_sections

Modified: cfe/trunk/test/Driver/cl-fallback.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-fallback.c?rev=272832&r1=272831&r2=272832&view=diff
==
--- cfe/trunk/test/Driver/cl-fallback.c (original)
+++ cfe/trunk/test/Driver/cl-fallback.c Wed Jun 15 15:34:33 2016
@@ -1,7 +1,7 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
-// RUN: %clang_cl --target=i686-pc-win32 /fallback /Dfoo=bar /Ubaz /Ifoo /O0 
/Ox /GR /GR- /Gy /Gy- \
+// RUN: %clang_cl --target=i686-pc-win32 /fallback /Dfoo=bar /Ubaz /Ifoo /O0 
/Ox /GR /GR- /GS /GS- /Gy /Gy- \
 // RUN:   /Gw /Gw- /LD /LDd /EHs /EHs- /Zl /MD /MDd /MTd /MT /FImyheader.h /Zi 
\
 // RUN:   -garbage -moregarbage \
 // RUN:   -### -- %s 2>&1 \
@@ -22,6 +22,7 @@
 // CHECK: "/Oy"
 // CHECK: "/GF"
 // CHECK: "/GR-"
+// CHECK: "/GS-"
 // CHECK: "/Gy-"
 // CHECK: "/Gw-"
 // CHECK: "/Z7"
@@ -41,6 +42,10 @@
 // GR: cl.exe
 /

Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-06-16 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 60982.
etienneb marked 7 inline comments as done.
etienneb added a comment.

address comments


http://reviews.llvm.org/D21392

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.h
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s misc-redundant-expression %t
+// RUN: %check_clang_tidy %s misc-redundant-expression %t -- -- -std=c++11
+
+typedef __INT64_TYPE__ I64;
 
 struct Point {
   int x;
@@ -64,7 +66,7 @@
 
   if ( + "dummy" == + "dummy") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
-  if (L"abc" == L"abc") return 1; 
+  if (L"abc" == L"abc") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
@@ -82,7 +84,7 @@
 
 int Valid(int X, int Y) {
   if (X != Y) return 1;
-  if (X == X + 0) return 1;
+  if (X == Y + 0) return 1;
   if (P.x == P.y) return 1;
   if (P.a[P.x] < P.a[P.y]) return 1;
   if (P.a[0] < P.a[1]) return 1;
@@ -160,3 +162,324 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
 }
 void TestTemplate() { TemplateCheck(); }
+
+int TestArithmetic(int X, int Y) {
+  if (X + 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X - 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1LL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+  if (X + 1ULL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
+
+  if (X == X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X == X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if (X != X - 1U) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X != X - 1LL) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if ((X+X) != (X+X) - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X - 1 == X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 != X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 == X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - (~0)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0U)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0ULL)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  // Should not match.
+  if (X + 0.5 == X) return 1;
+  if (X + 1 == Y) return 1;
+  if (X + 1 == Y + 1) return 1;
+  if (X + 1 == Y + 2) return 1;
+
+  return 0;
+}
+
+int TestBitwise(int X) {
+  if ((X & 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X & 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+  if ((X | 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X | 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+
+  if ((X | 0xFFULL) != 0xF

Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-06-16 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

thx Aaron.



Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:131
@@ +130,3 @@
+
+  // Handle the case where constants are off by one: x <= 4  <==>  x < 5.
+  llvm::APSInt ValueLHS_plus1 = ValueLHS;

aaron.ballman wrote:
> Why is off-by-one more useful than a stronger range analysis?
I don't get your point?

This function is comparing two ranges. Ranges are comparable only if they are 
compared to the same constant
OR, if they are off-by one and the operator contains "equality".

As the comment state, x <= 4 is equivalent to x < 5.

To avoid problem with wrap around, the left value is incremented (the left 
value must be the smaller one: canonical form).

I don't get why we should use a range analysis? Is there some utility functions 
I'm not aware of?


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:177
@@ +176,3 @@
+  // Handle cases where the constants are different.
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))

aaron.ballman wrote:
> Can this be done before doing the more expensive value comparisons?
it can be done before the previous if. But not the one at line 149 (which 
always returns).


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:267
@@ +266,3 @@
+Opcode = BO_Add;
+Value = -Value;
+  }

aaron.ballman wrote:
> I can never remember myself, but how well does APSInt handle this situation 
> if it causes overflow of the signed value? e.g., an 8-bit APSInt holding the 
> value -128 being negated to 128 (which is outside the range of an 8-bit 
> signed integer).
In this case  -128 (8-bits) will give -128.
The APSInt is behaving the same way than a real value of the same width and 
signedness.

I added an unittest to cover this case.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:294
@@ +293,3 @@
+// Returns a matcher for a generic expression (not a constant expression).
+static ast_matchers::internal::Matcher matchGenericExpr(StringRef Id) {
+  std::string SymId = (Id + "-gen").str();

aaron.ballman wrote:
> I'm not keen on this name because C11 has `_Generic`, for which we have a 
> `GenericSelectionExpr` which is awfully close to this name.
'Generic' is a too generic name :)


Comment at: clang-tidy/misc/RedundantExpressionCheck.h:31
@@ +30,3 @@
+private:
+  void checkArithmeticExpr(const ast_matchers::MatchFinder::MatchResult & R);
+  void checkBitwiseExpr(const ast_matchers::MatchFinder::MatchResult &R);

aaron.ballman wrote:
> `&` should bind to `R`.
> 
> Also, all of these functions can be marked `const`.
They can't be constant, they are calling 'diag' which is not const.

```
error: no matching function for call to 
‘clang::tidy::misc::RedundantExpressionCheck::diag(clang::SourceLocation, const 
char [35]) const
```


http://reviews.llvm.org/D21392



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-06-16 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 60983.
etienneb added a comment.

refactoring


http://reviews.llvm.org/D21392

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.h
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s misc-redundant-expression %t
+// RUN: %check_clang_tidy %s misc-redundant-expression %t -- -- -std=c++11
+
+typedef __INT64_TYPE__ I64;
 
 struct Point {
   int x;
@@ -64,7 +66,7 @@
 
   if ( + "dummy" == + "dummy") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
-  if (L"abc" == L"abc") return 1; 
+  if (L"abc" == L"abc") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
@@ -82,7 +84,7 @@
 
 int Valid(int X, int Y) {
   if (X != Y) return 1;
-  if (X == X + 0) return 1;
+  if (X == Y + 0) return 1;
   if (P.x == P.y) return 1;
   if (P.a[P.x] < P.a[P.y]) return 1;
   if (P.a[0] < P.a[1]) return 1;
@@ -160,3 +162,324 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
 }
 void TestTemplate() { TemplateCheck(); }
+
+int TestArithmetic(int X, int Y) {
+  if (X + 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X - 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1LL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+  if (X + 1ULL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
+
+  if (X == X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X == X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if (X != X - 1U) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X != X - 1LL) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if ((X+X) != (X+X) - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X - 1 == X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 != X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 == X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - (~0)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0U)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0ULL)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  // Should not match.
+  if (X + 0.5 == X) return 1;
+  if (X + 1 == Y) return 1;
+  if (X + 1 == Y + 1) return 1;
+  if (X + 1 == Y + 2) return 1;
+
+  return 0;
+}
+
+int TestBitwise(int X) {
+  if ((X & 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X & 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+  if ((X | 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X | 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+
+  if ((X | 0xFFULL) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]

Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-06-27 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 61984.
etienneb marked 12 inline comments as done.
etienneb added a comment.

address comments


http://reviews.llvm.org/D21392

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.h
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s misc-redundant-expression %t
+// RUN: %check_clang_tidy %s misc-redundant-expression %t -- -- -std=c++11
+
+typedef __INT64_TYPE__ I64;
 
 struct Point {
   int x;
@@ -64,7 +66,7 @@
 
   if ( + "dummy" == + "dummy") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
-  if (L"abc" == L"abc") return 1; 
+  if (L"abc" == L"abc") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
@@ -82,7 +84,7 @@
 
 int Valid(int X, int Y) {
   if (X != Y) return 1;
-  if (X == X + 0) return 1;
+  if (X == Y + 0) return 1;
   if (P.x == P.y) return 1;
   if (P.a[P.x] < P.a[P.y]) return 1;
   if (P.a[0] < P.a[1]) return 1;
@@ -160,3 +162,324 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
 }
 void TestTemplate() { TemplateCheck(); }
+
+int TestArithmetic(int X, int Y) {
+  if (X + 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X - 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1LL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+  if (X + 1ULL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
+
+  if (X == X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X == X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if (X != X - 1U) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X != X - 1LL) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if ((X+X) != (X+X) - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X - 1 == X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 != X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 == X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - (~0)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0U)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0ULL)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  // Should not match.
+  if (X + 0.5 == X) return 1;
+  if (X + 1 == Y) return 1;
+  if (X + 1 == Y + 1) return 1;
+  if (X + 1 == Y + 2) return 1;
+
+  return 0;
+}
+
+int TestBitwise(int X) {
+  if ((X & 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X & 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+  if ((X | 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X | 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+
+  if ((X | 0xFFULL) != 0x

Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-06-28 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:27
@@ -25,1 +26,3 @@
 
+static bool incrementWithoutOverflow(const llvm::APSInt &Value,
+ llvm::APSInt &Result) {

aaron.ballman wrote:
> I think this could be implemented using APInt overflow checks, no? 
> `APInt::sadd_ov()`?
It could be implemented using sadd_ov and uadd_ov.
The 'signedness' need to be take into account. The class 'APInt' doesn't not 
carry signedness.

Using the operator++ here let the instantiated type do the right increment and 
right comparison.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:274
@@ +273,3 @@
+Value = -Value;
+  }
+}

aaron.ballman wrote:
> > In this case -128 (8-bits) will give -128.
> 
> So negating -128 doesn't yield 128, it yields -128? That seems weird.
> 
> > The APSInt is behaving the same way than a real value of the same width and 
> > signedness.
> 
> A real value of the same width and signedness has UB with that case, which is 
> why I was asking. The range of an 8-bit signed int is -128 to 127, so 
> negating -128 yields an out-of-range value. I want to make sure we aren't 
> butchering that by canonicalizing the negate expression.
The value produced by 'canonicalNegateExpr' is the same value produced by 
executing the sub instruction on the CPU.
Even if the value make no sense in math.

Btw, there is a unittest to cover this case.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:364
@@ +363,3 @@
+
+  // A cast can be matched as a comparator to zero.
+  const auto CastExpr =

alexfh wrote:
> Not sure I understand this comment.
if ( implicit-int-to-bool(x) )   <<-- the implicit-int-to-bool(...) could be 
consider as  x != 0


http://reviews.llvm.org/D21392



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21392: [clang-tidy] Enhance redundant-expression check

2016-07-06 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 63020.
etienneb marked 2 inline comments as done.
etienneb added a comment.

nits


http://reviews.llvm.org/D21392

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.h
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s misc-redundant-expression %t
+// RUN: %check_clang_tidy %s misc-redundant-expression %t -- -- -std=c++11
+
+typedef __INT64_TYPE__ I64;
 
 struct Point {
   int x;
@@ -64,7 +66,7 @@
 
   if ( + "dummy" == + "dummy") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
-  if (L"abc" == L"abc") return 1; 
+  if (L"abc" == L"abc") return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
@@ -82,7 +84,7 @@
 
 int Valid(int X, int Y) {
   if (X != Y) return 1;
-  if (X == X + 0) return 1;
+  if (X == Y + 0) return 1;
   if (P.x == P.y) return 1;
   if (P.a[P.x] < P.a[P.y]) return 1;
   if (P.a[0] < P.a[1]) return 1;
@@ -160,3 +162,324 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
 }
 void TestTemplate() { TemplateCheck(); }
+
+int TestArithmetic(int X, int Y) {
+  if (X + 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X - 1 == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1LL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+  if (X + 1ULL == X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
+
+  if (X == X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X + 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X == X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always false
+  if (X != X - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if (X != X - 1U) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+  if (X != X - 1LL) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: logical expression is always true
+
+  if ((X+X) != (X+X) - 1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X + 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X - 1 == X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X - 1 != X - 2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 != X - -1) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 == X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always false
+  if (X + 1 != X - -2) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  if (X + 1 == X - (~0)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0U)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+  if (X + 1 == X - (~0ULL)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: logical expression is always true
+
+  // Should not match.
+  if (X + 0.5 == X) return 1;
+  if (X + 1 == Y) return 1;
+  if (X + 1 == Y + 1) return 1;
+  if (X + 1 == Y + 2) return 1;
+
+  return 0;
+}
+
+int TestBitwise(int X) {
+  if ((X & 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X & 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+  if ((X | 0xFF) == 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always false
+  if ((X | 0xFF) != 0xF00) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: logical expression is always true
+
+  if ((X | 0xFFULL) != 0xF00) return 1

[clang-tools-extra] r274731 - [clang-tidy] Enhance redundant-expression check

2016-07-06 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed Jul  6 23:03:05 2016
New Revision: 274731

URL: http://llvm.org/viewvc/llvm-project?rev=274731&view=rev
Log:
[clang-tidy] Enhance redundant-expression check

Summary: This patch is adding support to recognize more complex redundant 
expressions.

Reviewers: alexfh

Subscribers: aaron.ballman, cfe-commits, chrisha

Differential Revision: http://reviews.llvm.org/D21392

Modified:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.h
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=274731&r1=274730&r2=274731&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Wed 
Jul  6 23:03:05 2016
@@ -15,14 +15,25 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
 
 namespace clang {
 namespace tidy {
 namespace misc {
 
+namespace {
+using llvm::APSInt;
+} // namespace
+
 static const char KnownBannedMacroNames[] =
 "EAGAIN;EWOULDBLOCK;SIGCLD;SIGCHLD;";
 
+static bool incrementWithoutOverflow(const APSInt &Value, APSInt &Result) {
+  Result = Value;
+  ++Result;
+  return Value < Result;
+}
+
 static bool areEquivalentNameSpecifier(const NestedNameSpecifier *Left,
const NestedNameSpecifier *Right) {
   llvm::FoldingSetNodeID LeftID, RightID;
@@ -110,6 +121,302 @@ static bool areEquivalentExpr(const Expr
   }
 }
 
+// For a given expression 'x', returns whether the ranges covered by the
+// relational operators are equivalent (i.e.  x <= 4 is equivalent to x < 5).
+static bool areEquivalentRanges(BinaryOperatorKind OpcodeLHS,
+const APSInt &ValueLHS,
+BinaryOperatorKind OpcodeRHS,
+const APSInt &ValueRHS) {
+  assert(APSInt::compareValues(ValueLHS, ValueRHS) <= 0 &&
+ "Values must be ordered");
+  // Handle the case where constants are the same: x <= 4  <==>  x <= 4.
+  if (APSInt::compareValues(ValueLHS, ValueRHS) == 0)
+return OpcodeLHS == OpcodeRHS;
+
+  // Handle the case where constants are off by one: x <= 4  <==>  x < 5.
+  APSInt ValueLHS_plus1;
+  return ((OpcodeLHS == BO_LE && OpcodeRHS == BO_LT) ||
+  (OpcodeLHS == BO_GT && OpcodeRHS == BO_GE)) &&
+ incrementWithoutOverflow(ValueLHS, ValueLHS_plus1) &&
+ APSInt::compareValues(ValueLHS_plus1, ValueRHS) == 0;
+}
+
+// For a given expression 'x', returns whether the ranges covered by the
+// relational operators are fully disjoint (i.e. x < 4  and  x > 7).
+static bool areExclusiveRanges(BinaryOperatorKind OpcodeLHS,
+   const APSInt &ValueLHS,
+   BinaryOperatorKind OpcodeRHS,
+   const APSInt &ValueRHS) {
+  assert(APSInt::compareValues(ValueLHS, ValueRHS) <= 0 &&
+ "Values must be ordered");
+
+  // Handle cases where the constants are the same.
+  if (APSInt::compareValues(ValueLHS, ValueRHS) == 0) {
+switch (OpcodeLHS) {
+case BO_EQ:
+  return OpcodeRHS == BO_NE || OpcodeRHS == BO_GT || OpcodeRHS == BO_LT;
+case BO_NE:
+  return OpcodeRHS == BO_EQ;
+case BO_LE:
+  return OpcodeRHS == BO_GT;
+case BO_GE:
+  return OpcodeRHS == BO_LT;
+case BO_LT:
+  return OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE;
+case BO_GT:
+  return OpcodeRHS == BO_EQ || OpcodeRHS == BO_LT || OpcodeRHS == BO_LE;
+default:
+  return false;
+}
+  }
+
+  // Handle cases where the constants are different.
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
+return true;
+
+  // Handle the case where constants are off by one: x > 5 && x < 6.
+  APSInt ValueLHS_plus1;
+  if (OpcodeLHS == BO_GT && OpcodeRHS == BO_LT &&
+  incrementWithoutOverflow(ValueLHS, ValueLHS_plus1) &&
+  APSInt::compareValues(ValueLHS_plus1, ValueRHS) == 0)
+return true;
+
+  return false;
+}
+
+// Returns whether the ranges covered by the union of both relational
+// expressions covers the whole domain (i.e. x < 10  and  x > 0).
+static bool rangesFullyCoverDomain(BinaryOperatorKind OpcodeLHS,
+   const APSInt &ValueLHS,
+   BinaryOperatorKind OpcodeRHS,
+   const APSInt &ValueRHS) {
+  assert(APSInt::compareValues(ValueLHS, ValueRHS) <= 0 &&
+ "Values must be ordered");
+
+  // 

Re: [PATCH] D19941: [tooling] FixItHint Tooling refactoring

2016-05-10 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56825.
etienneb marked 5 inline comments as done.
etienneb added a comment.

address alexfh comments


http://reviews.llvm.org/D19941

Files:
  include/clang/Tooling/FixIt.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/FixIt.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/FixItTest.cpp

Index: unittests/Tooling/FixItTest.cpp
===
--- /dev/null
+++ unittests/Tooling/FixItTest.cpp
@@ -0,0 +1,238 @@
+//===- unittest/Tooling/FixitTest.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang;
+
+namespace {
+
+struct CallsVisitor : TestVisitor {
+  bool VisitCallExpr(CallExpr *Expr) {
+OnCall(Expr, Context);
+return true;
+  }
+
+  std::function OnCall;
+};
+
+std::string LocationToString(SourceLocation Loc, ASTContext *Context) {
+  return Loc.printToString(Context->getSourceManager());
+}
+
+TEST(FixitTest, getText) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [&](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("foo(x, y)", tooling::fixit::getText(*CE, *Context));
+EXPECT_EQ("foo(x, y)",
+  tooling::fixit::getText(CE->getSourceRange(), *Context));
+
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("y", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [&](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("APPLY(foo, x, y)", tooling::fixit::getText(*CE, *Context));
+  };
+  Visitor.runOver("#define APPLY(f, x, y) f(x, y)\n"
+  "void foo(int x, int y) { APPLY(foo, x, y); }");
+}
+
+TEST(FixitTest, getTextWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("F OO", tooling::fixit::getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("#define F foo(\n"
+  "#define OO x, y)\n"
+  "void foo(int x, int y) { F OO ; }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("", tooling::fixit::getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("y", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("#define FOO(x, y) (void)x; (void)y; foo(x, y);\n"
+  "void foo(int x, int y) { FOO(x,y) }");
+}
+
+TEST(FixitTest, createRemoval) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = tooling::fixit::createRemoval(*CE);
+EXPECT_EQ("foo(x, y)",
+  tooling::fixit::getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = tooling::fixit::createRemoval(*P0);
+EXPECT_EQ(
+"x", tooling::fixit::getText(Hint0.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint0.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint0.CodeToInsert.empty());
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = tooling::fixit::createRemoval(*P1);
+EXPECT_EQ(
+"y", tooling::fixit::getText(Hint1.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint1.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint1.CodeToInsert.empty());
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = tooling::fixit::createRemoval(*P0);
+EXPECT_EQ("x + y", tooling::fixit::getText(Hint0.RemoveRange.getAsRange(),
+   *Context));
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = tooling::fixit::createRemoval(*P1);
+EXPECT_EQ("y + x", tooling::fixit::getText(Hint1.RemoveRange.getAsRange(),
+   *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x + y, y + x); }");
+}
+
+TEST(FixitTest, createRemovalWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = tooling::fixit::createRemoval(*CE);
+EXPECT_EQ("FOO",
+  tooling::fixit::getText(Hint.RemoveRange.getAsRange(), *Context));
+E

Re: [PATCH] D19941: [tooling] FixItHint Tooling refactoring

2016-05-10 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56826.
etienneb added a comment.

nits


http://reviews.llvm.org/D19941

Files:
  include/clang/Tooling/FixIt.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/FixIt.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/FixItTest.cpp

Index: unittests/Tooling/FixItTest.cpp
===
--- /dev/null
+++ unittests/Tooling/FixItTest.cpp
@@ -0,0 +1,238 @@
+//===- unittest/Tooling/FixitTest.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang;
+
+namespace {
+
+struct CallsVisitor : TestVisitor {
+  bool VisitCallExpr(CallExpr *Expr) {
+OnCall(Expr, Context);
+return true;
+  }
+
+  std::function OnCall;
+};
+
+std::string LocationToString(SourceLocation Loc, ASTContext *Context) {
+  return Loc.printToString(Context->getSourceManager());
+}
+
+TEST(FixItTest, getText) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("foo(x, y)", tooling::fixit::getText(*CE, *Context));
+EXPECT_EQ("foo(x, y)",
+  tooling::fixit::getText(CE->getSourceRange(), *Context));
+
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("y", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("APPLY(foo, x, y)", tooling::fixit::getText(*CE, *Context));
+  };
+  Visitor.runOver("#define APPLY(f, x, y) f(x, y)\n"
+  "void foo(int x, int y) { APPLY(foo, x, y); }");
+}
+
+TEST(FixItTest, getTextWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("F OO", tooling::fixit::getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("#define F foo(\n"
+  "#define OO x, y)\n"
+  "void foo(int x, int y) { F OO ; }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("", tooling::fixit::getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", tooling::fixit::getText(*P0, *Context));
+EXPECT_EQ("y", tooling::fixit::getText(*P1, *Context));
+  };
+  Visitor.runOver("#define FOO(x, y) (void)x; (void)y; foo(x, y);\n"
+  "void foo(int x, int y) { FOO(x,y) }");
+}
+
+TEST(FixItTest, createRemoval) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = tooling::fixit::createRemoval(*CE);
+EXPECT_EQ("foo(x, y)",
+  tooling::fixit::getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = tooling::fixit::createRemoval(*P0);
+EXPECT_EQ(
+"x", tooling::fixit::getText(Hint0.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint0.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint0.CodeToInsert.empty());
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = tooling::fixit::createRemoval(*P1);
+EXPECT_EQ(
+"y", tooling::fixit::getText(Hint1.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint1.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint1.CodeToInsert.empty());
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = tooling::fixit::createRemoval(*P0);
+EXPECT_EQ("x + y", tooling::fixit::getText(Hint0.RemoveRange.getAsRange(),
+   *Context));
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = tooling::fixit::createRemoval(*P1);
+EXPECT_EQ("y + x", tooling::fixit::getText(Hint1.RemoveRange.getAsRange(),
+   *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x + y, y + x); }");
+}
+
+TEST(FixItTest, createRemovalWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = tooling::fixit::createRemoval(*CE);
+EXPECT_EQ("FOO",
+  tooling::fixit::getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(H

Re: [PATCH] D19941: [tooling] FixItHint Tooling refactoring

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56907.
etienneb marked an inline comment as done.
etienneb added a comment.

fix nits


http://reviews.llvm.org/D19941

Files:
  include/clang/Tooling/FixIt.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/FixIt.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/FixItTest.cpp

Index: unittests/Tooling/FixItTest.cpp
===
--- /dev/null
+++ unittests/Tooling/FixItTest.cpp
@@ -0,0 +1,232 @@
+//===- unittest/Tooling/FixitTest.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang;
+
+using tooling::fixit::getText;
+using tooling::fixit::createRemoval;
+using tooling::fixit::createReplacement;
+
+namespace {
+
+struct CallsVisitor : TestVisitor {
+  bool VisitCallExpr(CallExpr *Expr) {
+OnCall(Expr, Context);
+return true;
+  }
+
+  std::function OnCall;
+};
+
+std::string LocationToString(SourceLocation Loc, ASTContext *Context) {
+  return Loc.printToString(Context->getSourceManager());
+}
+
+TEST(FixItTest, getText) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("foo(x, y)", getText(*CE, *Context));
+EXPECT_EQ("foo(x, y)", getText(CE->getSourceRange(), *Context));
+
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", getText(*P0, *Context));
+EXPECT_EQ("y", getText(*P1, *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("APPLY(foo, x, y)", getText(*CE, *Context));
+  };
+  Visitor.runOver("#define APPLY(f, x, y) f(x, y)\n"
+  "void foo(int x, int y) { APPLY(foo, x, y); }");
+}
+
+TEST(FixItTest, getTextWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("F OO", getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("", getText(*P0, *Context));
+EXPECT_EQ("", getText(*P1, *Context));
+  };
+  Visitor.runOver("#define F foo(\n"
+  "#define OO x, y)\n"
+  "void foo(int x, int y) { F OO ; }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("", getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", getText(*P0, *Context));
+EXPECT_EQ("y", getText(*P1, *Context));
+  };
+  Visitor.runOver("#define FOO(x, y) (void)x; (void)y; foo(x, y);\n"
+  "void foo(int x, int y) { FOO(x,y) }");
+}
+
+TEST(FixItTest, createRemoval) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = createRemoval(*CE);
+EXPECT_EQ("foo(x, y)", getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("x", getText(Hint0.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint0.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint0.CodeToInsert.empty());
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = createRemoval(*P1);
+EXPECT_EQ("y", getText(Hint1.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint1.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint1.CodeToInsert.empty());
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("x + y", getText(Hint0.RemoveRange.getAsRange(), *Context));
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = createRemoval(*P1);
+EXPECT_EQ("y + x", getText(Hint1.RemoveRange.getAsRange(), *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x + y, y + x); }");
+}
+
+TEST(FixItTest, createRemovalWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = createRemoval(*CE);
+EXPECT_EQ("FOO", getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("input.cc:2:26 ",
+  LocationToString(Hint0.RemoveRange.getBegin(), Context));
+EXPECT_EQ("input.cc:2:26 ",
+  LocationToString(Hint0.RemoveRange.getEnd(), Context));
+EXPECT_TRUE(Hint0.InsertFromRange.isInvalid());
+ 

Re: [PATCH] D19941: [tooling] FixItHint Tooling refactoring

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

I added the "using statements".
landing.



Comment at: include/clang/Tooling/Fixit.h:35
@@ +34,3 @@
+///used by the following template abstractions.
+inline SourceRange getSourceRange(const SourceRange &Range) { return Range; }
+

alexfh wrote:
> Do we want to expose `getSourceRange` as an API? If no, it should also be in 
> the `namespace internal`.
Good question.
I moved it into the internal namespace.

If it's become needed, we can re-expose it.


Comment at: include/clang/Tooling/Fixit.h:55
@@ +54,3 @@
+// \brief Returns a FixItHint to remove \p Node.
+template  FixItHint createRemoval(const T &Node) {
+  return FixItHint::CreateRemoval(getSourceRange(Node));

alexfh wrote:
> I wonder whether we should later extend this to remove comments attached to 
> nodes like Stmt and FunctionDecl? It's out of this patches scope, but maybe 
> add a FIXME to sketch the further development plans.
I like the idea. I didn't think about comments and other syntactical elements 
that may be related to a Node. 
But, I believe we will have a other set of functions for Node and comments.

An other concept that I believe it's missing is to provide helper to append 
expression (operators) and stay semantically correct with operator precedence. 
Some cases needed to add parentheses.




Comment at: unittests/Tooling/FixitTest.cpp:53
@@ +52,3 @@
+
+TEST(FixitTest, getTextWithMacro) {
+  CallsVisitor Visitor;

alexfh wrote:
> Could you add a test where getText returns an empty string?
see line 68, already there!


Comment at: unittests/Tooling/FixitTest.cpp:119
@@ +118,3 @@
+  LocationToString(Hint0.RemoveRange.getBegin(), Context));
+EXPECT_EQ("input.cc:2:26 ",
+  LocationToString(Hint0.RemoveRange.getEnd(), Context));

alexfh wrote:
> One character range is boring. Can you make the parameter longer and also 
> verify whether the range is a token range or a character range?
In this case, it's not one character... it's one token.
As it's a "token range", the whole token is used.

But, I can use an expression too.
Not a bad idea: added but in 'createRemoval'

There is already a reand at line 138:
  EXPECT_EQ("input.cc:2:26 ",
  EXPECT_EQ("input.cc:2:26 ",


http://reviews.llvm.org/D19941



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56911.
etienneb marked an inline comment as done.
etienneb added a comment.
Herald added a subscriber: klimek.

use new API


http://reviews.llvm.org/D19703

Files:
  include/clang/Tooling/FixIt.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/FixIt.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/FixItTest.cpp

Index: unittests/Tooling/FixItTest.cpp
===
--- /dev/null
+++ unittests/Tooling/FixItTest.cpp
@@ -0,0 +1,232 @@
+//===- unittest/Tooling/FixitTest.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang;
+
+using tooling::fixit::getText;
+using tooling::fixit::createRemoval;
+using tooling::fixit::createReplacement;
+
+namespace {
+
+struct CallsVisitor : TestVisitor {
+  bool VisitCallExpr(CallExpr *Expr) {
+OnCall(Expr, Context);
+return true;
+  }
+
+  std::function OnCall;
+};
+
+std::string LocationToString(SourceLocation Loc, ASTContext *Context) {
+  return Loc.printToString(Context->getSourceManager());
+}
+
+TEST(FixItTest, getText) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("foo(x, y)", getText(*CE, *Context));
+EXPECT_EQ("foo(x, y)", getText(CE->getSourceRange(), *Context));
+
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", getText(*P0, *Context));
+EXPECT_EQ("y", getText(*P1, *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("APPLY(foo, x, y)", getText(*CE, *Context));
+  };
+  Visitor.runOver("#define APPLY(f, x, y) f(x, y)\n"
+  "void foo(int x, int y) { APPLY(foo, x, y); }");
+}
+
+TEST(FixItTest, getTextWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("F OO", getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("", getText(*P0, *Context));
+EXPECT_EQ("", getText(*P1, *Context));
+  };
+  Visitor.runOver("#define F foo(\n"
+  "#define OO x, y)\n"
+  "void foo(int x, int y) { F OO ; }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+EXPECT_EQ("", getText(*CE, *Context));
+Expr *P0 = CE->getArg(0);
+Expr *P1 = CE->getArg(1);
+EXPECT_EQ("x", getText(*P0, *Context));
+EXPECT_EQ("y", getText(*P1, *Context));
+  };
+  Visitor.runOver("#define FOO(x, y) (void)x; (void)y; foo(x, y);\n"
+  "void foo(int x, int y) { FOO(x,y) }");
+}
+
+TEST(FixItTest, createRemoval) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = createRemoval(*CE);
+EXPECT_EQ("foo(x, y)", getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("x", getText(Hint0.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint0.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint0.CodeToInsert.empty());
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = createRemoval(*P1);
+EXPECT_EQ("y", getText(Hint1.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint1.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint1.CodeToInsert.empty());
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x, y); }");
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("x + y", getText(Hint0.RemoveRange.getAsRange(), *Context));
+
+Expr *P1 = CE->getArg(1);
+FixItHint Hint1 = createRemoval(*P1);
+EXPECT_EQ("y + x", getText(Hint1.RemoveRange.getAsRange(), *Context));
+  };
+  Visitor.runOver("void foo(int x, int y) { foo(x + y, y + x); }");
+}
+
+TEST(FixItTest, createRemovalWithMacro) {
+  CallsVisitor Visitor;
+
+  Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) {
+FixItHint Hint = createRemoval(*CE);
+EXPECT_EQ("FOO", getText(Hint.RemoveRange.getAsRange(), *Context));
+EXPECT_TRUE(Hint.InsertFromRange.isInvalid());
+EXPECT_TRUE(Hint.CodeToInsert.empty());
+
+Expr *P0 = CE->getArg(0);
+FixItHint Hint0 = createRemoval(*P0);
+EXPECT_EQ("input.cc:2:26 ",
+  LocationToString(Hint0.RemoveRange.getBegin(), Context));
+EXPECT_EQ("input.cc:2:26 ",
+  LocationToString(Hint0.RemoveRange.getEnd(), Context));
+EXPECT_TRUE(

Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56912.
etienneb added a comment.

fix bad upload


http://reviews.llvm.org/D19703

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  docs/clang-tidy/checks/misc-redundant-expression.rst
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -68,14 +68,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
   if (foo(bar(0)) < (foo(bar((0) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
 
   if (P1.x < P2.x && P1.x < P2.x) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
   if (P2.a[P1.x + 2] < P2.x && P2.a[(P1.x) + (2)] < (P2.x)) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent
 
   return 0;
 }
@@ -100,13 +100,36 @@
   return 0;
 }
 
+int TestConditional(int x, int y) {
+  int k = 0;
+  k += (y < 0) ? x : x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 'true' and 'false' expression are equivalent
+  k += (y < 0) ? x + 1 : x + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'true' and 'false' expression are equivalent
+  return k;
+}
+
+struct MyStruct {
+  int x;
+} Q;
+bool operator==(const MyStruct& lhs, const MyStruct& rhs) { return lhs.x == rhs.x; }
+bool TestOperator(const MyStruct& S) {
+  if (S == Q) return false;
+  return S == S;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: both side of overloaded operator are equivalent
+}
+
 #define LT(x, y) (void)((x) < (y))
+#define COND(x, y, z) ((x)?(y):(z))
+#define EQUALS(x, y) (x) == (y)
 
 int TestMacro(int X, int Y) {
   LT(0, 0);
   LT(1, 0);
   LT(X, X);
   LT(X+1, X + 1);
+  COND(X < Y, X, X);
+  EQUALS(Q, Q);
 }
 
 int TestFalsePositive(int* A, int X, float F) {
@@ -118,3 +141,22 @@
   if (F != F && F == F) return 1;
   return 0;
 }
+
+int TestBannedMacros() {
+#define EAGAIN 3
+#define NOT_EAGAIN 3
+  if (EAGAIN == 0 | EAGAIN == 0) return 0;
+  if (NOT_EAGAIN == 0 | NOT_EAGAIN == 0) return 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: both side of operator are equivalent
+}
+
+struct MyClass {
+static const int Value = 42;
+};
+template 
+void TemplateCheck() {
+  static_assert(T::Value == U::Value, "should be identical");
+  static_assert(T::Value == T::Value, "should be identical");
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
+}
+void TestTemplate() { TemplateCheck(); }
Index: docs/clang-tidy/checks/misc-redundant-expression.rst
===
--- docs/clang-tidy/checks/misc-redundant-expression.rst
+++ docs/clang-tidy/checks/misc-redundant-expression.rst
@@ -12,6 +12,7 @@
   * always be a constant (zero or one)
 
 Example:
+
 .. code:: c++
 
   ((x+1) | (x+1)) // (x+1) is redundant
Index: clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -9,16 +9,30 @@
 
 #include "RedundantExpressionCheck.h"
 #include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
 namespace misc {
 
-static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+static const char KnownBannedMacroNames[] =
+"EAGAIN;EWOULDBLOCK;SIGCLD;SIGCHLD;";
+
+
+static bool AreEquivalentNameSpecifier(const NestedNameSpecifier *Left,
+   const NestedNameSpecifier *Right) {
+  llvm::FoldingSetNodeID LeftID, RightID;
+  Left->Profile(LeftID);
+  Right->Profile(RightID);
+  return LeftID == RightID;
+}
+
+static bool AreEquivalentExpr(const Expr *Left, const Expr *Right) {
   if (!Left || !Right)
 return !Left && !Right;
 
@@ -33,8 +47,8 @@
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-if (!AreIdenticalExpr(dyn_cast(*LeftIter),
-  dyn_cast(*RightIter)))
+if (!AreEquiva

r269188 - [tooling] FixItHint Tooling refactoring

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 09:31:39 2016
New Revision: 269188

URL: http://llvm.org/viewvc/llvm-project?rev=269188&view=rev
Log:
[tooling] FixItHint Tooling refactoring

Summary:
This is the refactoring to lift some FixItHint into tooling.
used by: http://reviews.llvm.org/D19807

Reviewers: klimek, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19941

Added:
cfe/trunk/include/clang/Tooling/FixIt.h
cfe/trunk/lib/Tooling/FixIt.cpp
cfe/trunk/unittests/Tooling/FixItTest.cpp
Modified:
cfe/trunk/lib/Tooling/CMakeLists.txt
cfe/trunk/unittests/Tooling/CMakeLists.txt

Added: cfe/trunk/include/clang/Tooling/FixIt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/FixIt.h?rev=269188&view=auto
==
--- cfe/trunk/include/clang/Tooling/FixIt.h (added)
+++ cfe/trunk/include/clang/Tooling/FixIt.h Wed May 11 09:31:39 2016
@@ -0,0 +1,72 @@
+//===--- FixIt.h - FixIt Hint utilities -*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file implements functions to ease source rewriting from AST-nodes.
+//
+//  Example swapping A and B expressions:
+//
+//Expr *A, *B;
+//tooling::fixit::createReplacement(*A, *B);
+//tooling::fixit::createReplacement(*B, *A);
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_FIXIT_H
+#define LLVM_CLANG_TOOLING_FIXIT_H
+
+#include "clang/AST/ASTContext.h"
+
+namespace clang {
+namespace tooling {
+namespace fixit {
+
+namespace internal {
+StringRef getText(SourceRange Range, const ASTContext &Context);
+
+/// \brief Returns the SourceRange of a SourceRange. This identity function is
+///used by the following template abstractions.
+inline SourceRange getSourceRange(const SourceRange &Range) { return Range; }
+
+/// \brief Returns the SourceRange of the token at Location \p Loc.
+inline SourceRange getSourceRange(const SourceLocation &Loc) {
+  return SourceRange(Loc);
+}
+
+/// \brief Returns the SourceRange of an given Node. \p Node is typically a
+///'Stmt', 'Expr' or a 'Decl'.
+template  SourceRange getSourceRange(const T &Node) {
+  return Node.getSourceRange();
+}
+} // end namespace internal
+
+// \brief Returns a textual representation of \p Node.
+template 
+StringRef getText(const T &Node, const ASTContext &Context) {
+  return internal::getText(internal::getSourceRange(Node), Context);
+}
+
+// \brief Returns a FixItHint to remove \p Node.
+// TODO: Add support for related syntactical elements (i.e. comments, ...).
+template  FixItHint createRemoval(const T &Node) {
+  return FixItHint::CreateRemoval(internal::getSourceRange(Node));
+}
+
+// \brief Returns a FixItHint to replace \p Destination by \p Source.
+template 
+FixItHint createReplacement(const D &Destination, const S &Source,
+const ASTContext &Context) {
+  return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
+  getText(Source, Context));
+}
+
+} // end namespace fixit
+} // end namespace tooling
+} // end namespace clang
+
+#endif // LLVM_CLANG_TOOLING_FIXINT_H

Modified: cfe/trunk/lib/Tooling/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CMakeLists.txt?rev=269188&r1=269187&r2=269188&view=diff
==
--- cfe/trunk/lib/Tooling/CMakeLists.txt (original)
+++ cfe/trunk/lib/Tooling/CMakeLists.txt Wed May 11 09:31:39 2016
@@ -7,6 +7,7 @@ add_clang_library(clangTooling
   CommonOptionsParser.cpp
   CompilationDatabase.cpp
   FileMatchTrie.cpp
+  FixIt.cpp
   JSONCompilationDatabase.cpp
   Refactoring.cpp
   RefactoringCallbacks.cpp

Added: cfe/trunk/lib/Tooling/FixIt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/FixIt.cpp?rev=269188&view=auto
==
--- cfe/trunk/lib/Tooling/FixIt.cpp (added)
+++ cfe/trunk/lib/Tooling/FixIt.cpp Wed May 11 09:31:39 2016
@@ -0,0 +1,31 @@
+//===--- FixIt.cpp - FixIt Hint utilities ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file contains implementations of utitilies to ease source code 
rewriting
+// by providing helper functions related to FixItHint.
+//
+//===--===//
+

Re: [PATCH] D19547: [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56919.
etienneb marked an inline comment as done.
etienneb added a comment.

use new API. code simplification


http://reviews.llvm.org/D19547

Files:
  clang-tidy/misc/StringConstructorCheck.cpp
  test/clang-tidy/misc-string-constructor.cpp

Index: test/clang-tidy/misc-string-constructor.cpp
===
--- test/clang-tidy/misc-string-constructor.cpp
+++ test/clang-tidy/misc-string-constructor.cpp
@@ -21,9 +21,11 @@
 
 void Test() {
   std::string str('x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are 
probably swapped [misc-string-constructor]
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters 
are probably swapped; expecting string(count, character) 
[misc-string-constructor]
+  // CHECK-FIXES: std::string str(4, 'x');  
   std::wstring wstr(L'x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are 
probably swapped
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters 
are probably swapped
+  // CHECK-FIXES: std::wstring wstr(4, L'x');
   std::string s0(0, 'x');
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty 
string
   std::string s1(-4, 'x');
Index: clang-tidy/misc/StringConstructorCheck.cpp
===
--- clang-tidy/misc/StringConstructorCheck.cpp
+++ clang-tidy/misc/StringConstructorCheck.cpp
@@ -10,6 +10,7 @@
 #include "StringConstructorCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -54,7 +55,7 @@
   isDefinition(),
   hasType(pointerType(pointee(isAnyCharacter(), isConstQualified(,
   hasInitializer(ignoringParenImpCasts(BoundStringLiteral)));
-  auto ConstStrLiteral = expr(ignoringParenImpCasts(anyOf(
+  const auto ConstStrLiteral = expr(ignoringParenImpCasts(anyOf(
   BoundStringLiteral, declRefExpr(hasDeclaration(anyOf(
   ConstPtrStrLiteralDecl, 
ConstStrLiteralDecl));
 
@@ -88,7 +89,7 @@
   // Detect the expression: string("...", 0);
   hasArgument(1, ZeroExpr.bind("empty-string")),
   // Detect the expression: string("...", -4);
-  hasArgument(1, NegativeExpr.bind("negative-length")),
  
+  hasArgument(1, NegativeExpr.bind("negative-length")),
   // Detect the expression: string("lit", 0x1234567);
   hasArgument(1, LargeLengthExpr.bind("large-length")),
   // Detect the expression: string("lit", 5)
@@ -100,11 +101,18 @@
 }
 
 void StringConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *E = Result.Nodes.getNodeAs("constructor");
+  const ASTContext &Ctx = *Result.Context;
+  const auto *E = Result.Nodes.getNodeAs("constructor");
+  assert(E && "missing constructor expression");
   SourceLocation Loc = E->getLocStart();
 
   if (Result.Nodes.getNodeAs("swapped-parameter")) {
-diag(Loc, "constructor parameters are probably swapped");
+const Expr* P0 = E->getArg(0);
+const Expr* P1 = E->getArg(1);
+diag(Loc, "string constructor parameters are probably swapped;"
+  " expecting string(count, character)")
+<< tooling::fixit::createReplacement(*P0, *P1, Ctx)
+<< tooling::fixit::createReplacement(*P1, *P0, Ctx);
   } else if (Result.Nodes.getNodeAs("empty-string")) {
 diag(Loc, "constructor creating an empty string");
   } else if (Result.Nodes.getNodeAs("negative-length")) {


Index: test/clang-tidy/misc-string-constructor.cpp
===
--- test/clang-tidy/misc-string-constructor.cpp
+++ test/clang-tidy/misc-string-constructor.cpp
@@ -21,9 +21,11 @@
 
 void Test() {
   std::string str('x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are probably swapped [misc-string-constructor]
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [misc-string-constructor]
+  // CHECK-FIXES: std::string str(4, 'x');  
   std::wstring wstr(L'x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are probably swapped
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
+  // CHECK-FIXES: std::wstring wstr(4, L'x');
   std::string s0(0, 'x');
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
   std::string s1(-4, 'x');
Index: clang-tidy/misc/StringConstructorCheck.cpp
===
--- clang-tidy/misc/StringConstructorCheck.cpp
+++ clang-tidy/misc/StringConstructorCheck.cpp
@@ -10,6 +10,7 @@
 #include "StringConstructorCheck.h"
 #include "clang/AST/ASTCo

Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.



> We should add a hasAnyOverloadedOperatorName matcher at some point.


I proposed it to sbenza@ and he told me that the reason he did HasAnyName was 
for speed issue.
I can't tell if that one has speed issue too.

But, otherwise, I agree... for code readability... we should do it.


http://reviews.llvm.org/D19703



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56935.
etienneb marked an inline comment as done.
etienneb added a comment.

remove useless set creation


http://reviews.llvm.org/D19703

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  docs/clang-tidy/checks/misc-redundant-expression.rst
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -68,14 +68,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
   if (foo(bar(0)) < (foo(bar((0) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
 
   if (P1.x < P2.x && P1.x < P2.x) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
   if (P2.a[P1.x + 2] < P2.x && P2.a[(P1.x) + (2)] < (P2.x)) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent
 
   return 0;
 }
@@ -100,13 +100,36 @@
   return 0;
 }
 
+int TestConditional(int x, int y) {
+  int k = 0;
+  k += (y < 0) ? x : x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 'true' and 'false' expression are equivalent
+  k += (y < 0) ? x + 1 : x + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'true' and 'false' expression are equivalent
+  return k;
+}
+
+struct MyStruct {
+  int x;
+} Q;
+bool operator==(const MyStruct& lhs, const MyStruct& rhs) { return lhs.x == rhs.x; }
+bool TestOperator(const MyStruct& S) {
+  if (S == Q) return false;
+  return S == S;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: both side of overloaded operator are equivalent
+}
+
 #define LT(x, y) (void)((x) < (y))
+#define COND(x, y, z) ((x)?(y):(z))
+#define EQUALS(x, y) (x) == (y)
 
 int TestMacro(int X, int Y) {
   LT(0, 0);
   LT(1, 0);
   LT(X, X);
   LT(X+1, X + 1);
+  COND(X < Y, X, X);
+  EQUALS(Q, Q);
 }
 
 int TestFalsePositive(int* A, int X, float F) {
@@ -118,3 +141,22 @@
   if (F != F && F == F) return 1;
   return 0;
 }
+
+int TestBannedMacros() {
+#define EAGAIN 3
+#define NOT_EAGAIN 3
+  if (EAGAIN == 0 | EAGAIN == 0) return 0;
+  if (NOT_EAGAIN == 0 | NOT_EAGAIN == 0) return 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: both side of operator are equivalent
+}
+
+struct MyClass {
+static const int Value = 42;
+};
+template 
+void TemplateCheck() {
+  static_assert(T::Value == U::Value, "should be identical");
+  static_assert(T::Value == T::Value, "should be identical");
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
+}
+void TestTemplate() { TemplateCheck(); }
Index: docs/clang-tidy/checks/misc-redundant-expression.rst
===
--- docs/clang-tidy/checks/misc-redundant-expression.rst
+++ docs/clang-tidy/checks/misc-redundant-expression.rst
@@ -12,6 +12,7 @@
   * always be a constant (zero or one)
 
 Example:
+
 .. code:: c++
 
   ((x+1) | (x+1)) // (x+1) is redundant
Index: clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -9,16 +9,29 @@
 
 #include "RedundantExpressionCheck.h"
 #include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
 namespace misc {
 
-static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+static const char KnownBannedMacroNames[] =
+"EAGAIN;EWOULDBLOCK;SIGCLD;SIGCHLD;";
+
+static bool AreEquivalentNameSpecifier(const NestedNameSpecifier *Left,
+   const NestedNameSpecifier *Right) {
+  llvm::FoldingSetNodeID LeftID, RightID;
+  Left->Profile(LeftID);
+  Right->Profile(RightID);
+  return LeftID == RightID;
+}
+
+static bool AreEquivalentExpr(const Expr *Left, const Expr *Right) {
   if (!Left || !Right)
 return !Left && !Right;
 
@@ -33,8 +46,8 @@
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-if (!AreIdenticalExpr(dyn_cast(*LeftIter),
-  

Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56937.
etienneb added a comment.

fix naming nits


http://reviews.llvm.org/D19703

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  docs/clang-tidy/checks/misc-redundant-expression.rst
  test/clang-tidy/misc-redundant-expression.cpp

Index: test/clang-tidy/misc-redundant-expression.cpp
===
--- test/clang-tidy/misc-redundant-expression.cpp
+++ test/clang-tidy/misc-redundant-expression.cpp
@@ -68,14 +68,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both side of operator are equivalent
 
   if (foo(0) - 2 < foo(0) - 2) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: both side of operator are equivalent
   if (foo(bar(0)) < (foo(bar((0) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
 
   if (P1.x < P2.x && P1.x < P2.x) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: both side of operator are equivalent
   if (P2.a[P1.x + 2] < P2.x && P2.a[(P1.x) + (2)] < (P2.x)) return 1;
-  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent  
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both side of operator are equivalent
 
   return 0;
 }
@@ -100,13 +100,36 @@
   return 0;
 }
 
+int TestConditional(int x, int y) {
+  int k = 0;
+  k += (y < 0) ? x : x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 'true' and 'false' expression are equivalent
+  k += (y < 0) ? x + 1 : x + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'true' and 'false' expression are equivalent
+  return k;
+}
+
+struct MyStruct {
+  int x;
+} Q;
+bool operator==(const MyStruct& lhs, const MyStruct& rhs) { return lhs.x == rhs.x; }
+bool TestOperator(const MyStruct& S) {
+  if (S == Q) return false;
+  return S == S;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: both side of overloaded operator are equivalent
+}
+
 #define LT(x, y) (void)((x) < (y))
+#define COND(x, y, z) ((x)?(y):(z))
+#define EQUALS(x, y) (x) == (y)
 
 int TestMacro(int X, int Y) {
   LT(0, 0);
   LT(1, 0);
   LT(X, X);
   LT(X+1, X + 1);
+  COND(X < Y, X, X);
+  EQUALS(Q, Q);
 }
 
 int TestFalsePositive(int* A, int X, float F) {
@@ -118,3 +141,22 @@
   if (F != F && F == F) return 1;
   return 0;
 }
+
+int TestBannedMacros() {
+#define EAGAIN 3
+#define NOT_EAGAIN 3
+  if (EAGAIN == 0 | EAGAIN == 0) return 0;
+  if (NOT_EAGAIN == 0 | NOT_EAGAIN == 0) return 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: both side of operator are equivalent
+}
+
+struct MyClass {
+static const int Value = 42;
+};
+template 
+void TemplateCheck() {
+  static_assert(T::Value == U::Value, "should be identical");
+  static_assert(T::Value == T::Value, "should be identical");
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: both side of overloaded operator are equivalent
+}
+void TestTemplate() { TemplateCheck(); }
Index: docs/clang-tidy/checks/misc-redundant-expression.rst
===
--- docs/clang-tidy/checks/misc-redundant-expression.rst
+++ docs/clang-tidy/checks/misc-redundant-expression.rst
@@ -12,6 +12,7 @@
   * always be a constant (zero or one)
 
 Example:
+
 .. code:: c++
 
   ((x+1) | (x+1)) // (x+1) is redundant
Index: clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -9,16 +9,29 @@
 
 #include "RedundantExpressionCheck.h"
 #include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
 namespace misc {
 
-static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+static const char KnownBannedMacroNames[] =
+"EAGAIN;EWOULDBLOCK;SIGCLD;SIGCHLD;";
+
+static bool areEquivalentNameSpecifier(const NestedNameSpecifier *Left,
+   const NestedNameSpecifier *Right) {
+  llvm::FoldingSetNodeID LeftID, RightID;
+  Left->Profile(LeftID);
+  Right->Profile(RightID);
+  return LeftID == RightID;
+}
+
+static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
   if (!Left || !Right)
 return !Left && !Right;
 
@@ -33,8 +46,8 @@
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-if (!AreIdenticalExpr(dyn_cast(*LeftIter),
-  dyn_cast(*RightIter)))
+if (!areEquival

Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

+ Removed copy of a vector to a set
+ Fixed some minor coding-style issues



Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:140
@@ +139,3 @@
+  const LangOptions &LO = Finder->getASTContext().getLangOpts();
+  std::set Names(NameRefs.begin(), NameRefs.end());
+  SourceLocation Loc = Node.getExprLoc();

alexfh wrote:
> Is there a way to not create a set on each call to the matcher? There also 
> might be a more suitable container in llvm/ADT.
Some ideas:
1) We may assume the vector is small and do the lookup.
2) We may assume a sorted vector and do a binary search.
3) The matcher could receive a set instead of a vector and lifting out the copy.

Implemented 3)


http://reviews.llvm.org/D19703



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r269208 - [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 12:32:12 2016
New Revision: 269208

URL: http://llvm.org/viewvc/llvm-project?rev=269208&view=rev
Log:
[clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.

Summary:
Arguments can be swapped using fixit when they are not in macros.
This is the same implementation than SwappedArguments. Some code 
got lifted to be reused.

Others checks are not safe to be fixed as they tend to be bugs or errors.
It is better to let the user manually review them.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19547

Modified:
clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp?rev=269208&r1=269207&r2=269208&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StringConstructorCheck.cpp Wed May 
11 12:32:12 2016
@@ -10,6 +10,7 @@
 #include "StringConstructorCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -54,7 +55,7 @@ void StringConstructorCheck::registerMat
   isDefinition(),
   hasType(pointerType(pointee(isAnyCharacter(), isConstQualified(,
   hasInitializer(ignoringParenImpCasts(BoundStringLiteral)));
-  auto ConstStrLiteral = expr(ignoringParenImpCasts(anyOf(
+  const auto ConstStrLiteral = expr(ignoringParenImpCasts(anyOf(
   BoundStringLiteral, declRefExpr(hasDeclaration(anyOf(
   ConstPtrStrLiteralDecl, 
ConstStrLiteralDecl));
 
@@ -88,7 +89,7 @@ void StringConstructorCheck::registerMat
   // Detect the expression: string("...", 0);
   hasArgument(1, ZeroExpr.bind("empty-string")),
   // Detect the expression: string("...", -4);
-  hasArgument(1, NegativeExpr.bind("negative-length")),
  
+  hasArgument(1, NegativeExpr.bind("negative-length")),
   // Detect the expression: string("lit", 0x1234567);
   hasArgument(1, LargeLengthExpr.bind("large-length")),
   // Detect the expression: string("lit", 5)
@@ -100,11 +101,18 @@ void StringConstructorCheck::registerMat
 }
 
 void StringConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *E = Result.Nodes.getNodeAs("constructor");
+  const ASTContext &Ctx = *Result.Context;
+  const auto *E = Result.Nodes.getNodeAs("constructor");
+  assert(E && "missing constructor expression");
   SourceLocation Loc = E->getLocStart();
 
   if (Result.Nodes.getNodeAs("swapped-parameter")) {
-diag(Loc, "constructor parameters are probably swapped");
+const Expr *P0 = E->getArg(0);
+const Expr *P1 = E->getArg(1);
+diag(Loc, "string constructor parameters are probably swapped;"
+  " expecting string(count, character)")
+<< tooling::fixit::createReplacement(*P0, *P1, Ctx)
+<< tooling::fixit::createReplacement(*P1, *P0, Ctx);
   } else if (Result.Nodes.getNodeAs("empty-string")) {
 diag(Loc, "constructor creating an empty string");
   } else if (Result.Nodes.getNodeAs("negative-length")) {

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp?rev=269208&r1=269207&r2=269208&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp Wed May 
11 12:32:12 2016
@@ -21,9 +21,11 @@ extern const char kText3[];
 
 void Test() {
   std::string str('x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are 
probably swapped [misc-string-constructor]
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters 
are probably swapped; expecting string(count, character) 
[misc-string-constructor]
+  // CHECK-FIXES: std::string str(4, 'x');  
   std::wstring wstr(L'x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are 
probably swapped
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters 
are probably swapped
+  // CHECK-FIXES: std::wstring wstr(4, L'x');
   std::string s0(0, 'x');
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty 
string
   std::string s1(-4, 'x');


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi

[clang-tools-extra] r269210 - [clang-tidy] Refactoring of FixHintUtils

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 12:38:22 2016
New Revision: 269210

URL: http://llvm.org/viewvc/llvm-project?rev=269210&view=rev
Log:
[clang-tidy] Refactoring of FixHintUtils

Summary:
Refactor some checkers to use the tooling re-writing API.
see: http://reviews.llvm.org/D19941

Reviewers: klimek, alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19807

Modified:
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-swapped-arguments.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp?rev=269210&r1=269209&r2=269210&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp Wed May 
11 12:38:22 2016
@@ -10,6 +10,7 @@
 #include "SwappedArgumentsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
 #include "llvm/ADT/SmallPtrSet.h"
 
 using namespace clang::ast_matchers;
@@ -46,25 +47,9 @@ static bool isImplicitCastCandidate(cons
  Cast->getCastKind() == CK_PointerToBoolean;
 }
 
-/// \brief Get a StringRef representing a SourceRange.
-static StringRef getAsString(const MatchFinder::MatchResult &Result,
- SourceRange R) {
-  const SourceManager &SM = *Result.SourceManager;
-  // Don't even try to resolve macro or include contraptions. Not worth 
emitting
-  // a fixit for.
-  if (R.getBegin().isMacroID() ||
-  !SM.isWrittenInSameFile(R.getBegin(), R.getEnd()))
-return StringRef();
-
-  const char *Begin = SM.getCharacterData(R.getBegin());
-  const char *End = SM.getCharacterData(Lexer::getLocForEndOfToken(
-  R.getEnd(), 0, SM, Result.Context->getLangOpts()));
-
-  return StringRef(Begin, End - Begin);
-}
-
 void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
-  auto *Call = Result.Nodes.getStmtAs("call");
+  const ASTContext &Ctx = *Result.Context;
+  const auto *Call = Result.Nodes.getStmtAs("call");
 
   llvm::SmallPtrSet UsedArgs;
   for (unsigned I = 1, E = Call->getNumArgs(); I < E; ++I) {
@@ -99,24 +84,14 @@ void SwappedArgumentsCheck::check(const
   continue;
 
 // Emit a warning and fix-its that swap the arguments.
-SourceRange LHSRange = LHS->getSourceRange(),
-RHSRange = RHS->getSourceRange();
-auto D =
-diag(Call->getLocStart(), "argument with implicit conversion from %0 "
-  "to %1 followed by argument converted from "
-  "%2 to %3, potentially swapped arguments.")
+diag(Call->getLocStart(), "argument with implicit conversion from %0 "
+  "to %1 followed by argument converted from "
+  "%2 to %3, potentially swapped arguments.")
 << LHS->getType() << LHSFrom->getType() << RHS->getType()
-<< RHSFrom->getType() << LHSRange << RHSRange;
-
-StringRef RHSString = getAsString(Result, RHSRange);
-StringRef LHSString = getAsString(Result, LHSRange);
-if (!LHSString.empty() && !RHSString.empty()) {
-  D << FixItHint::CreateReplacement(
-   CharSourceRange::getTokenRange(LHSRange), RHSString)
-<< FixItHint::CreateReplacement(
-   CharSourceRange::getTokenRange(RHSRange), LHSString);
-}
-
+<< RHSFrom->getType()
+<< tooling::fixit::createReplacement(*LHS, *RHS, Ctx)
+<< tooling::fixit::createReplacement(*RHS, *LHS, Ctx);
+
 // Remember that we emitted a warning for this argument.
 UsedArgs.insert(RHSCast);
   }

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp?rev=269210&r1=269209&r2=269210&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp Wed 
May 11 12:38:22 2016
@@ -10,6 +10,7 @@
 #include "ElseAfterReturnCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -28,20 +29,17 @@ void ElseAfterReturnCheck::registerMatch
   this);
 }
 
-static FixItHint removeToken(SourceLocation Loc) {
-  return FixItHint::CreateRemoval(CharSourceRange::getTokenRange(Loc, Loc));
-}
-
 void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *If = Result.Nodes.ge

Re: [PATCH] D19876: Add an AST matcher for string-literal length

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 56942.
etienneb added a comment.

re-generating doc


http://reviews.llvm.org/D19876

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/ASTMatchers/ASTMatchersInternal.h
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -51,7 +51,6 @@
 
   // Do not accept non-toplevel matchers.
   EXPECT_FALSE(Finder.addDynamicMatcher(isArrow(), nullptr));
-  EXPECT_FALSE(Finder.addDynamicMatcher(hasSize(2), nullptr));
   EXPECT_FALSE(Finder.addDynamicMatcher(hasName("x"), nullptr));
 }
 
@@ -2536,6 +2535,17 @@
   EXPECT_TRUE(notMatches("const char s[1] = {'a'};", Literal));
 }
 
+TEST(StringLiteral, HasSize) {
+  StatementMatcher Literal = stringLiteral(hasSize(4));
+  EXPECT_TRUE(matches("const char *s = \"abcd\";", Literal));
+  // wide string
+  EXPECT_TRUE(matches("const wchar_t *s = L\"abcd\";", Literal));
+  // with escaped characters
+  EXPECT_TRUE(matches("const char *s = \"\x05\x06\x07\x08\";", Literal));
+  // no matching, too small
+  EXPECT_TRUE(notMatches("const char *s = \"ab\";", Literal));
+}
+
 TEST(Matcher, CharacterLiterals) {
   StatementMatcher CharLiteral = characterLiteral();
   EXPECT_TRUE(matches("const char c = 'c';", CharLiteral));
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1651,6 +1651,19 @@
 }
 
 template 
+struct HasSizeMatcher {
+  static bool hasSize(const Ty &Node, unsigned int N) {
+return Node.getSize() == N;
+  }
+};
+
+template <>
+inline bool HasSizeMatcher::hasSize(
+const StringLiteral &Node, unsigned int N) {
+  return Node.getLength() == N;
+}
+
+template 
 struct GetSourceExpressionMatcher {
   static const Expr *get(const Ty &Node) {
 return Node.getSubExpr();
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1560,7 +1560,8 @@
 ///
 /// Example matches "abcd", L"abcd"
 /// \code
-///   char *s = "abcd"; wchar_t *ws = L"abcd"
+///   char *s = "abcd";
+///   wchar_t *ws = L"abcd";
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -1573,7 +1574,8 @@
 ///
 /// Example matches 'a', L'a'
 /// \code
-///   char ch = 'a'; wchar_t chw = L'a';
+///   char ch = 'a';
+///   wchar_t chw = L'a';
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -1609,7 +1611,8 @@
 ///
 /// Example match: {1}, (1, 2)
 /// \code
-///   int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+///   int array[4] = {1};
+///   vector int myvec = (vector int)(1, 2);
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -4228,18 +4231,26 @@
 ///   matches "int a[2]"
 AST_TYPE_MATCHER(ConstantArrayType, constantArrayType);
 
-/// \brief Matches \c ConstantArrayType nodes that have the specified size.
+/// \brief Matches nodes that have the specified size.
 ///
 /// Given
 /// \code
 ///   int a[42];
 ///   int b[2 * 21];
 ///   int c[41], d[43];
+///   char *s = "abcd";
+///   wchar_t *ws = L"abcd";
+///   char *w = "a";
 /// \endcode
 /// constantArrayType(hasSize(42))
 ///   matches "int a[42]" and "int b[2 * 21]"
-AST_MATCHER_P(ConstantArrayType, hasSize, unsigned, N) {
-  return Node.getSize() == N;
+/// stringLiteral(hasSize(4))
+///   matches "abcd", L"abcd"
+AST_POLYMORPHIC_MATCHER_P(hasSize,
+  AST_POLYMORPHIC_SUPPORTED_TYPES(ConstantArrayType,
+  StringLiteral),
+  unsigned, N) {
+  return internal::HasSizeMatcher::hasSize(Node, N);
 }
 
 /// \brief Matches C++ arrays whose size is a value-dependent expression.
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -644,15 +644,17 @@
 though.
 
 Example matches 'a', L'a'
-  char ch = 'a'; wchar_t chw = L'a';
+  char ch = 'a';
+  wchar_t chw = L'a';
 
 
 
 MatcherStmt>compoundLiteralExprMatcherCompoundLiteralExpr>...
 Matches compound (i.e. non-scalar) literals
 
 Example match: {1}, (1, 2)
-  int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+  int array[4] = {1};
+  vector int myvec = (vector int)(1, 2);
 
 
 
@@ -1217,7 +1219,8 @@
 Matches string literals (also matches wide string literals).
 
 Example matches "abcd", L"abcd"
-  char *s = "abcd"; wchar_t *ws = L"abcd"
+  char *s = "

[PATCH] D20180: [tooling] Fix missing inline keyworkd, breaking build bot.

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: rnk.
etienneb added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The missing keyword "inline" is causing some buildbot to fail.
The symbol is not available.

see: 
http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/2281/

http://reviews.llvm.org/D20180

Files:
  include/clang/Tooling/FixIt.h

Index: include/clang/Tooling/FixIt.h
===
--- include/clang/Tooling/FixIt.h
+++ include/clang/Tooling/FixIt.h
@@ -40,27 +40,27 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  SourceRange getSourceRange(const T &Node) {
+template  inline SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-StringRef getText(const T &Node, const ASTContext &Context) {
+inline StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  FixItHint createRemoval(const T &Node) {
+template  inline FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-FixItHint createReplacement(const D &Destination, const S &Source,
-const ASTContext &Context) {
+inline FixItHint createReplacement(const D &Destination, const S &Source,
+   const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
 }


Index: include/clang/Tooling/FixIt.h
===
--- include/clang/Tooling/FixIt.h
+++ include/clang/Tooling/FixIt.h
@@ -40,27 +40,27 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  SourceRange getSourceRange(const T &Node) {
+template  inline SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-StringRef getText(const T &Node, const ASTContext &Context) {
+inline StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  FixItHint createRemoval(const T &Node) {
+template  inline FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-FixItHint createReplacement(const D &Destination, const S &Source,
-const ASTContext &Context) {
+inline FixItHint createReplacement(const D &Destination, const S &Source,
+   const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269224 - [tooling] Fix missing inline keyworkd, breaking build bot.

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 15:09:17 2016
New Revision: 269224

URL: http://llvm.org/viewvc/llvm-project?rev=269224&view=rev
Log:
[tooling] Fix missing inline keyworkd, breaking build bot.

Summary:
The missing keyword "inline" is causing some buildbot to fail.
The symbol is not available.

see: 
http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/2281/

Reviewers: rnk

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20180

Modified:
cfe/trunk/include/clang/Tooling/FixIt.h

Modified: cfe/trunk/include/clang/Tooling/FixIt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/FixIt.h?rev=269224&r1=269223&r2=269224&view=diff
==
--- cfe/trunk/include/clang/Tooling/FixIt.h (original)
+++ cfe/trunk/include/clang/Tooling/FixIt.h Wed May 11 15:09:17 2016
@@ -40,27 +40,27 @@ inline SourceRange getSourceRange(const
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  SourceRange getSourceRange(const T &Node) {
+template  inline SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-StringRef getText(const T &Node, const ASTContext &Context) {
+inline StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  FixItHint createRemoval(const T &Node) {
+template  inline FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-FixItHint createReplacement(const D &Destination, const S &Source,
-const ASTContext &Context) {
+inline FixItHint createReplacement(const D &Destination, const S &Source,
+   const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20180: [tooling] Fix missing inline keyworkd, breaking build bot.

2016-05-11 Thread Etienne Bergeron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269224: [tooling] Fix missing inline keyworkd, breaking 
build bot. (authored by etienneb).

Changed prior to commit:
  http://reviews.llvm.org/D20180?vs=56949&id=56954#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20180

Files:
  cfe/trunk/include/clang/Tooling/FixIt.h

Index: cfe/trunk/include/clang/Tooling/FixIt.h
===
--- cfe/trunk/include/clang/Tooling/FixIt.h
+++ cfe/trunk/include/clang/Tooling/FixIt.h
@@ -40,27 +40,27 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  SourceRange getSourceRange(const T &Node) {
+template  inline SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-StringRef getText(const T &Node, const ASTContext &Context) {
+inline StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  FixItHint createRemoval(const T &Node) {
+template  inline FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-FixItHint createReplacement(const D &Destination, const S &Source,
-const ASTContext &Context) {
+inline FixItHint createReplacement(const D &Destination, const S &Source,
+   const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
 }


Index: cfe/trunk/include/clang/Tooling/FixIt.h
===
--- cfe/trunk/include/clang/Tooling/FixIt.h
+++ cfe/trunk/include/clang/Tooling/FixIt.h
@@ -40,27 +40,27 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  SourceRange getSourceRange(const T &Node) {
+template  inline SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-StringRef getText(const T &Node, const ASTContext &Context) {
+inline StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  FixItHint createRemoval(const T &Node) {
+template  inline FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-FixItHint createReplacement(const D &Destination, const S &Source,
-const ASTContext &Context) {
+inline FixItHint createReplacement(const D &Destination, const S &Source,
+   const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20182: [clang-tidy] Add missing dependency of libtooling to misc module

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added reviewers: alexfh, rnk.
etienneb added a subscriber: cfe-commits.

The new API for fixit is in libtooling and the library misc in clang-tidy
didn't had the appropriate dependency.

This commit was breaking some build bots:
http://reviews.llvm.org/D19547

This commit tried (but failed) to fix it:
http://reviews.llvm.org/D20180

To repro, you can make a build with these flags:
```
cmake -DBUILD_SHARED_LIBS=ON
```

Thanks rnk@ for helping figuring out.

http://reviews.llvm.org/D20182

Files:
  clang-tidy/misc/CMakeLists.txt

Index: clang-tidy/misc/CMakeLists.txt
===
--- clang-tidy/misc/CMakeLists.txt
+++ clang-tidy/misc/CMakeLists.txt
@@ -50,4 +50,5 @@
   clangLex
   clangTidy
   clangTidyUtils
+  clangTooling
   )


Index: clang-tidy/misc/CMakeLists.txt
===
--- clang-tidy/misc/CMakeLists.txt
+++ clang-tidy/misc/CMakeLists.txt
@@ -50,4 +50,5 @@
   clangLex
   clangTidy
   clangTidyUtils
+  clangTooling
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20182: [clang-tidy] Add missing dependency of libtooling to misc module

2016-05-11 Thread Etienne Bergeron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269240: [clang-tidy] Add missing dependency of libtooling to 
misc module (authored by etienneb).

Changed prior to commit:
  http://reviews.llvm.org/D20182?vs=56963&id=56966#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20182

Files:
  clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt

Index: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
@@ -50,4 +50,5 @@
   clangLex
   clangTidy
   clangTidyUtils
+  clangTooling
   )


Index: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
@@ -50,4 +50,5 @@
   clangLex
   clangTidy
   clangTidyUtils
+  clangTooling
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r269240 - [clang-tidy] Add missing dependency of libtooling to misc module

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 16:32:29 2016
New Revision: 269240

URL: http://llvm.org/viewvc/llvm-project?rev=269240&view=rev
Log:
[clang-tidy] Add missing dependency of libtooling to misc module

Summary:
The new API for fixit is in libtooling and the library misc in clang-tidy
didn't had the appropriate dependency.

This commit was breaking some build bots:
http://reviews.llvm.org/D19547

This commit tried (but failed) to fix it:
http://reviews.llvm.org/D20180

To repro, you can make a build with these flags:
```
cmake -DBUILD_SHARED_LIBS=ON
```

Thanks rnk@ for helping figuring out.

Reviewers: alexfh, rnk

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20182

Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=269240&r1=269239&r2=269240&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Wed May 11 16:32:29 
2016
@@ -50,4 +50,5 @@ add_clang_library(clangTidyMiscModule
   clangLex
   clangTidy
   clangTidyUtils
+  clangTooling
   )


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20180: [tooling] Fix missing inline keyworkd, breaking build bot.

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

I'm sure you're right: they are redundant keywords.
I'm preparing the revert patch, and I'm running tests over multiple build types.


Repository:
  rL LLVM

http://reviews.llvm.org/D20180



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20189: [tooling] Remove redundant inline keyword

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The inline keywords are redundant.
Introduce by this commit to try to fix broken build bots:
  http://reviews.llvm.org/D20180

Tested on Debug and Release build [linux].
Tested on Release + Shared (-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON) 
[linux]
Tested on Release [windows]

http://reviews.llvm.org/D20189

Files:
  include/clang/Tooling/FixIt.h

Index: include/clang/Tooling/FixIt.h
===
--- include/clang/Tooling/FixIt.h
+++ include/clang/Tooling/FixIt.h
@@ -40,26 +40,26 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  inline SourceRange getSourceRange(const T &Node) {
+template  SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-inline StringRef getText(const T &Node, const ASTContext &Context) {
+StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  inline FixItHint createRemoval(const T &Node) {
+template  FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-inline FixItHint createReplacement(const D &Destination, const S &Source,
+FixItHint createReplacement(const D &Destination, const S &Source,
const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));


Index: include/clang/Tooling/FixIt.h
===
--- include/clang/Tooling/FixIt.h
+++ include/clang/Tooling/FixIt.h
@@ -40,26 +40,26 @@
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  inline SourceRange getSourceRange(const T &Node) {
+template  SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-inline StringRef getText(const T &Node, const ASTContext &Context) {
+StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  inline FixItHint createRemoval(const T &Node) {
+template  FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-inline FixItHint createReplacement(const D &Destination, const S &Source,
+FixItHint createReplacement(const D &Destination, const S &Source,
const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20180: [tooling] Fix missing inline keyworkd, breaking build bot.

2016-05-11 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20180#427893, @rnk wrote:

> In http://reviews.llvm.org/D20180#427840, @alexfh wrote:
>
> > `inline` seems to be completely redundant here. Can you try removing it and 
> > running whatever build configurations were failing without 
> > http://reviews.llvm.org/D20182?
>
>
> My bad, it's explicit function template specializations that need to be 
> marked inline when in headers.


Hmm, it's my bad! I tried it to solve broken bot.
 I try it that way because it is implemented with "inline" in 
ASTMatcherInternal:

Example:

  template <>
  inline const Stmt *GetBodyMatcher::get(const FunctionDecl 
&Node) {
return Node.doesThisDeclarationHaveABody() ? Node.getBody() : nullptr;
  }

But, it's "explicit template specialisation" in the above case.

Revert patch is ready: http://reviews.llvm.org/D20189

Still thanks Reid for helping finding the repro case.


Repository:
  rL LLVM

http://reviews.llvm.org/D20180



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269257 - [tooling] Remove redundant inline keyword

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 19:22:28 2016
New Revision: 269257

URL: http://llvm.org/viewvc/llvm-project?rev=269257&view=rev
Log:
[tooling] Remove redundant inline keyword

Summary:
The inline keywords are redundant.
Introduce by this commit to try to fix broken build bots:
  http://reviews.llvm.org/D20180

Tested on Debug and Release build [linux].
Tested on Release + Shared (-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON) 
[linux]
Tested on Release [windows]

Reviewers: alexfh

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20189

Modified:
cfe/trunk/include/clang/Tooling/FixIt.h

Modified: cfe/trunk/include/clang/Tooling/FixIt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/FixIt.h?rev=269257&r1=269256&r2=269257&view=diff
==
--- cfe/trunk/include/clang/Tooling/FixIt.h (original)
+++ cfe/trunk/include/clang/Tooling/FixIt.h Wed May 11 19:22:28 2016
@@ -40,26 +40,26 @@ inline SourceRange getSourceRange(const
 
 /// \brief Returns the SourceRange of an given Node. \p Node is typically a
 ///'Stmt', 'Expr' or a 'Decl'.
-template  inline SourceRange getSourceRange(const T &Node) {
+template  SourceRange getSourceRange(const T &Node) {
   return Node.getSourceRange();
 }
 } // end namespace internal
 
 // \brief Returns a textual representation of \p Node.
 template 
-inline StringRef getText(const T &Node, const ASTContext &Context) {
+StringRef getText(const T &Node, const ASTContext &Context) {
   return internal::getText(internal::getSourceRange(Node), Context);
 }
 
 // \brief Returns a FixItHint to remove \p Node.
 // TODO: Add support for related syntactical elements (i.e. comments, ...).
-template  inline FixItHint createRemoval(const T &Node) {
+template  FixItHint createRemoval(const T &Node) {
   return FixItHint::CreateRemoval(internal::getSourceRange(Node));
 }
 
 // \brief Returns a FixItHint to replace \p Destination by \p Source.
 template 
-inline FixItHint createReplacement(const D &Destination, const S &Source,
+FixItHint createReplacement(const D &Destination, const S &Source,
const ASTContext &Context) {
   return FixItHint::CreateReplacement(internal::getSourceRange(Destination),
   getText(Source, Context));


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269274 - Add an AST matcher for string-literal length

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 23:20:04 2016
New Revision: 269274

URL: http://llvm.org/viewvc/llvm-project?rev=269274&view=rev
Log:
Add an AST matcher for string-literal length

Summary:
This patch is adding support for a matcher to check string literal length.

This matcher is used in clang-tidy checkers and is part of this refactoring:
  see: http://reviews.llvm.org/D19841

Reviewers: sbenza, klimek, aaron.ballman

Subscribers: alexfh, klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D19876

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=269274&r1=269273&r2=269274&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed May 11 23:20:04 2016
@@ -644,7 +644,8 @@ Not matching Hex-encoded chars (e.g. 0x1
 though.
 
 Example matches 'a', L'a'
-  char ch = 'a'; wchar_t chw = L'a';
+  char ch = 'a';
+  wchar_t chw = L'a';
 
 
 
@@ -652,7 +653,8 @@ Example matches 'a', L'a'
 Matches 
compound (i.e. non-scalar) literals
 
 Example match: {1}, (1, 2)
-  int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+  int array[4] = {1};
+  vector int myvec = (vector int)(1, 2);
 
 
 
@@ -1217,7 +1219,8 @@ Example match: ({ int X = 4; X; })
 Matches string 
literals (also matches wide string literals).
 
 Example matches "abcd", L"abcd"
-  char *s = "abcd"; wchar_t *ws = L"abcd"
+  char *s = "abcd";
+  wchar_t *ws = L"abcd";
 
 
 
@@ -2191,14 +2194,19 @@ compoundStmt(statementCountIs(0)))
 
 
 MatcherConstantArrayType>hasSizeunsigned N
-Matches ConstantArrayType 
nodes that have the specified size.
+Matches nodes that have the 
specified size.
 
 Given
   int a[42];
   int b[2 * 21];
   int c[41], d[43];
+  char *s = "abcd";
+  wchar_t *ws = L"abcd";
+  char *w = "a";
 constantArrayType(hasSize(42))
   matches "int a[42]" and "int b[2 * 21]"
+stringLiteral(hasSize(4))
+  matches "abcd", L"abcd"
 
 
 
@@ -2955,6 +2963,23 @@ Usable as: MatcherStringLiteral>hasSizeunsigned N
+Matches nodes that have the 
specified size.
+
+Given
+  int a[42];
+  int b[2 * 21];
+  int c[41], d[43];
+  char *s = "abcd";
+  wchar_t *ws = L"abcd";
+  char *w = "a";
+constantArrayType(hasSize(42))
+  matches "int a[42]" and "int b[2 * 21]"
+stringLiteral(hasSize(4))
+  matches "abcd", L"abcd"
+
+
+
 MatcherTagDecl>isDefinition
 Matches if a 
declaration has a body attached.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=269274&r1=269273&r2=269274&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed May 11 23:20:04 2016
@@ -1560,7 +1560,8 @@ const internal::VariadicDynCastAllOfMatc
 ///
 /// Example matches "abcd", L"abcd"
 /// \code
-///   char *s = "abcd"; wchar_t *ws = L"abcd"
+///   char *s = "abcd";
+///   wchar_t *ws = L"abcd";
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -1573,7 +1574,8 @@ const internal::VariadicDynCastAllOfMatc
 ///
 /// Example matches 'a', L'a'
 /// \code
-///   char ch = 'a'; wchar_t chw = L'a';
+///   char ch = 'a';
+///   wchar_t chw = L'a';
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -1609,7 +1611,8 @@ const internal::VariadicDynCastAllOfMatc
 ///
 /// Example match: {1}, (1, 2)
 /// \code
-///   int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+///   int array[4] = {1};
+///   vector int myvec = (vector int)(1, 2);
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<
   Stmt,
@@ -4228,18 +4231,26 @@ AST_TYPELOC_TRAVERSE_MATCHER(hasElementT
 ///   matches "int a[2]"
 AST_TYPE_MATCHER(ConstantArrayType, constantArrayType);
 
-/// \brief Matches \c ConstantArrayType nodes that have the specified size.
+/// \brief Matches nodes that have the specified size.
 ///
 /// Given
 /// \code
 ///   int a[42];
 ///   int b[2 * 21];
 ///   int c[41], d[43];
+///   char *s = "abcd";
+///   wchar_t *ws = L"abcd";
+///   char *w = "a";
 /// \endcode
 /// constantArrayType(hasSize(42))
 ///   matches "int a[42]" and "int b[2 * 21]"
-AST_MATCHER_P(ConstantArrayType, hasSize, unsigned, N) {
-  return Node.getSize() == N;
+/// stringLiteral(hasSize(4))
+///   matches "abcd", L"abcd"
+AST_POLYMO

[clang-tools-extra] r269275 - [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-11 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed May 11 23:32:47 2016
New Revision: 269275

URL: http://llvm.org/viewvc/llvm-project?rev=269275&view=rev
Log:
[clang-tidy] Improve misc-redundant-expression and decrease false-positive

Summary:
This patch is adding support for conditional expression and overloaded 
operators.

To decrease false-positive, this patch is adding a list of banned macro names 
that
has multiple variant with same integer value.

Also fixed support for template instantiation and added an unittest.

Reviewers: alexfh

Subscribers: klimek, Sarcasm, cfe-commits

Differential Revision: http://reviews.llvm.org/D19703

Modified:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-redundant-expression.rst
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=269275&r1=269274&r2=269275&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Wed 
May 11 23:32:47 2016
@@ -9,8 +9,10 @@
 
 #include "RedundantExpressionCheck.h"
 #include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -18,7 +20,18 @@ namespace clang {
 namespace tidy {
 namespace misc {
 
-static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+static const char KnownBannedMacroNames[] =
+"EAGAIN;EWOULDBLOCK;SIGCLD;SIGCHLD;";
+
+static bool areEquivalentNameSpecifier(const NestedNameSpecifier *Left,
+   const NestedNameSpecifier *Right) {
+  llvm::FoldingSetNodeID LeftID, RightID;
+  Left->Profile(LeftID);
+  Right->Profile(RightID);
+  return LeftID == RightID;
+}
+
+static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
   if (!Left || !Right)
 return !Left && !Right;
 
@@ -33,8 +46,8 @@ static bool AreIdenticalExpr(const Expr
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-if (!AreIdenticalExpr(dyn_cast(*LeftIter),
-  dyn_cast(*RightIter)))
+if (!areEquivalentExpr(dyn_cast(*LeftIter),
+   dyn_cast(*RightIter)))
   return false;
 ++LeftIter;
 ++RightIter;
@@ -53,7 +66,8 @@ static bool AreIdenticalExpr(const Expr
   case Stmt::IntegerLiteralClass: {
 llvm::APInt LeftLit = cast(Left)->getValue();
 llvm::APInt RightLit = cast(Right)->getValue();
-return LeftLit.getBitWidth() == RightLit.getBitWidth() && LeftLit == 
RightLit;
+return LeftLit.getBitWidth() == RightLit.getBitWidth() &&
+   LeftLit == RightLit;
   }
   case Stmt::FloatingLiteralClass:
 return cast(Left)->getValue().bitwiseIsEqual(
@@ -62,6 +76,13 @@ static bool AreIdenticalExpr(const Expr
 return cast(Left)->getBytes() ==
cast(Right)->getBytes();
 
+  case Stmt::DependentScopeDeclRefExprClass:
+if (cast(Left)->getDeclName() !=
+cast(Right)->getDeclName())
+  return false;
+return areEquivalentNameSpecifier(
+cast(Left)->getQualifier(),
+cast(Right)->getQualifier());
   case Stmt::DeclRefExprClass:
 return cast(Left)->getDecl() ==
cast(Right)->getDecl();
@@ -89,22 +110,52 @@ static bool AreIdenticalExpr(const Expr
   }
 }
 
-AST_MATCHER(BinaryOperator, OperandsAreEquivalent) {
-  return AreIdenticalExpr(Node.getLHS(), Node.getRHS());
+AST_MATCHER(BinaryOperator, operandsAreEquivalent) {
+  return areEquivalentExpr(Node.getLHS(), Node.getRHS());
+}
+
+AST_MATCHER(ConditionalOperator, expressionsAreEquivalent) {
+  return areEquivalentExpr(Node.getTrueExpr(), Node.getFalseExpr());
+}
+
+AST_MATCHER(CallExpr, parametersAreEquivalent) {
+  return Node.getNumArgs() == 2 &&
+ areEquivalentExpr(Node.getArg(0), Node.getArg(1));
 }
 
-AST_MATCHER(BinaryOperator, isInMacro) {
+AST_MATCHER(BinaryOperator, binaryOperatorIsInMacro) {
   return Node.getOperatorLoc().isMacroID();
 }
 
-AST_MATCHER(Expr, isInstantiationDependent) {
-  return Node.isInstantiationDependent();
+AST_MATCHER(ConditionalOperator, conditionalOperatorIsInMacro) {
+  return Node.getQuestionLoc().isMacroID() || Node.getColonLoc().isMacroID();
+}
+
+AST_MATCHER(Expr, isMacro) { return Node.getExprLoc().isMacroID(); }
+
+AST_MATCHER_P(Expr, expandedByMacro, std::set, Names) {
+  const SourceManager &SM = Finder->getASTContext().getSourceManager();
+  const LangOptions &LO = Finder->getASTContext().getLan

[PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added reviewers: klimek, aaron.ballman.
etienneb added subscribers: cfe-commits, alexfh, sbenza.

This patch moves the enum definitions to a definition (.def) file.

These modifications provide way to list enumerator of a given type.

As an example, this allow parsing of "kinds" in the dynamic matchers.
see: http://reviews.llvm.org/D19871
The dynamic matcher "ofKind" also required this patch to be fixed.

http://reviews.llvm.org/D20207

Files:
  include/clang/AST/OperationKinds.def
  include/clang/AST/OperationKinds.h
  include/clang/module.modulemap
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1084,20 +1084,8 @@
 /// corresponds to, e.g. "sizeof" or "[pre]++".
 StringRef UnaryOperator::getOpcodeStr(Opcode Op) {
   switch (Op) {
-  case UO_PostInc: return "++";
-  case UO_PostDec: return "--";
-  case UO_PreInc:  return "++";
-  case UO_PreDec:  return "--";
-  case UO_AddrOf:  return "&";
-  case UO_Deref:   return "*";
-  case UO_Plus:return "+";
-  case UO_Minus:   return "-";
-  case UO_Not: return "~";
-  case UO_LNot:return "!";
-  case UO_Real:return "__real";
-  case UO_Imag:return "__imag";
-  case UO_Extension: return "__extension__";
-  case UO_Coawait: return "co_await";
+#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
+#include "clang/AST/OperationKinds.def"
   }
   llvm_unreachable("Unknown unary operator");
 }
@@ -1608,120 +1596,9 @@
 
 const char *CastExpr::getCastKindName() const {
   switch (getCastKind()) {
-  case CK_Dependent:
-return "Dependent";
-  case CK_BitCast:
-return "BitCast";
-  case CK_LValueBitCast:
-return "LValueBitCast";
-  case CK_LValueToRValue:
-return "LValueToRValue";
-  case CK_NoOp:
-return "NoOp";
-  case CK_BaseToDerived:
-return "BaseToDerived";
-  case CK_DerivedToBase:
-return "DerivedToBase";
-  case CK_UncheckedDerivedToBase:
-return "UncheckedDerivedToBase";
-  case CK_Dynamic:
-return "Dynamic";
-  case CK_ToUnion:
-return "ToUnion";
-  case CK_ArrayToPointerDecay:
-return "ArrayToPointerDecay";
-  case CK_FunctionToPointerDecay:
-return "FunctionToPointerDecay";
-  case CK_NullToMemberPointer:
-return "NullToMemberPointer";
-  case CK_NullToPointer:
-return "NullToPointer";
-  case CK_BaseToDerivedMemberPointer:
-return "BaseToDerivedMemberPointer";
-  case CK_DerivedToBaseMemberPointer:
-return "DerivedToBaseMemberPointer";
-  case CK_ReinterpretMemberPointer:
-return "ReinterpretMemberPointer";
-  case CK_UserDefinedConversion:
-return "UserDefinedConversion";
-  case CK_ConstructorConversion:
-return "ConstructorConversion";
-  case CK_IntegralToPointer:
-return "IntegralToPointer";
-  case CK_PointerToIntegral:
-return "PointerToIntegral";
-  case CK_PointerToBoolean:
-return "PointerToBoolean";
-  case CK_ToVoid:
-return "ToVoid";
-  case CK_VectorSplat:
-return "VectorSplat";
-  case CK_IntegralCast:
-return "IntegralCast";
-  case CK_BooleanToSignedIntegral:
-return "BooleanToSignedIntegral";
-  case CK_IntegralToBoolean:
-return "IntegralToBoolean";
-  case CK_IntegralToFloating:
-return "IntegralToFloating";
-  case CK_FloatingToIntegral:
-return "FloatingToIntegral";
-  case CK_FloatingCast:
-return "FloatingCast";
-  case CK_FloatingToBoolean:
-return "FloatingToBoolean";
-  case CK_MemberPointerToBoolean:
-return "MemberPointerToBoolean";
-  case CK_CPointerToObjCPointerCast:
-return "CPointerToObjCPointerCast";
-  case CK_BlockPointerToObjCPointerCast:
-return "BlockPointerToObjCPointerCast";
-  case CK_AnyPointerToBlockPointerCast:
-return "AnyPointerToBlockPointerCast";
-  case CK_ObjCObjectLValueCast:
-return "ObjCObjectLValueCast";
-  case CK_FloatingRealToComplex:
-return "FloatingRealToComplex";
-  case CK_FloatingComplexToReal:
-return "FloatingComplexToReal";
-  case CK_FloatingComplexToBoolean:
-return "FloatingComplexToBoolean";
-  case CK_FloatingComplexCast:
-return "FloatingComplexCast";
-  case CK_FloatingComplexToIntegralComplex:
-return "FloatingComplexToIntegralComplex";
-  case CK_IntegralRealToComplex:
-return "IntegralRealToComplex";
-  case CK_IntegralComplexToReal:
-return "IntegralComplexToReal";
-  case CK_IntegralComplexToBoolean:
-return "IntegralComplexToBoolean";
-  case CK_IntegralComplexCast:
-return "IntegralComplexCast";
-  case CK_IntegralComplexToFloatingComplex:
-return "IntegralComplexToFloatingComplex";
-  case CK_ARCConsumeObject:
-return "ARCConsumeObject";
-  case CK_ARCProduceObject:
-return "ARCProduceObject";
-  case CK_ARCReclaimReturnedObject:
-return "ARCReclaimReturnedObject";
-  case CK_ARCExtendBlockObject:
-return "ARCExtendBlockObject";
-  case CK_AtomicToNonAtomic:
-return "AtomicToNonAtomic";
-

Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57043.
etienneb added a comment.
Herald added a subscriber: klimek.

rebase over AST modifications


http://reviews.llvm.org/D20207

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return 

Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57044.
etienneb marked an inline comment as done.
etienneb added a comment.

rebase over AST modifications


http://reviews.llvm.org/D19871

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+   

Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57045.
etienneb added a comment.

remove incorrect patch upload (sorry)


http://reviews.llvm.org/D20207

Files:
  include/clang/AST/OperationKinds.def
  include/clang/AST/OperationKinds.h
  include/clang/module.modulemap
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1084,20 +1084,8 @@
 /// corresponds to, e.g. "sizeof" or "[pre]++".
 StringRef UnaryOperator::getOpcodeStr(Opcode Op) {
   switch (Op) {
-  case UO_PostInc: return "++";
-  case UO_PostDec: return "--";
-  case UO_PreInc:  return "++";
-  case UO_PreDec:  return "--";
-  case UO_AddrOf:  return "&";
-  case UO_Deref:   return "*";
-  case UO_Plus:return "+";
-  case UO_Minus:   return "-";
-  case UO_Not: return "~";
-  case UO_LNot:return "!";
-  case UO_Real:return "__real";
-  case UO_Imag:return "__imag";
-  case UO_Extension: return "__extension__";
-  case UO_Coawait: return "co_await";
+#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
+#include "clang/AST/OperationKinds.def"
   }
   llvm_unreachable("Unknown unary operator");
 }
@@ -1608,120 +1596,9 @@
 
 const char *CastExpr::getCastKindName() const {
   switch (getCastKind()) {
-  case CK_Dependent:
-return "Dependent";
-  case CK_BitCast:
-return "BitCast";
-  case CK_LValueBitCast:
-return "LValueBitCast";
-  case CK_LValueToRValue:
-return "LValueToRValue";
-  case CK_NoOp:
-return "NoOp";
-  case CK_BaseToDerived:
-return "BaseToDerived";
-  case CK_DerivedToBase:
-return "DerivedToBase";
-  case CK_UncheckedDerivedToBase:
-return "UncheckedDerivedToBase";
-  case CK_Dynamic:
-return "Dynamic";
-  case CK_ToUnion:
-return "ToUnion";
-  case CK_ArrayToPointerDecay:
-return "ArrayToPointerDecay";
-  case CK_FunctionToPointerDecay:
-return "FunctionToPointerDecay";
-  case CK_NullToMemberPointer:
-return "NullToMemberPointer";
-  case CK_NullToPointer:
-return "NullToPointer";
-  case CK_BaseToDerivedMemberPointer:
-return "BaseToDerivedMemberPointer";
-  case CK_DerivedToBaseMemberPointer:
-return "DerivedToBaseMemberPointer";
-  case CK_ReinterpretMemberPointer:
-return "ReinterpretMemberPointer";
-  case CK_UserDefinedConversion:
-return "UserDefinedConversion";
-  case CK_ConstructorConversion:
-return "ConstructorConversion";
-  case CK_IntegralToPointer:
-return "IntegralToPointer";
-  case CK_PointerToIntegral:
-return "PointerToIntegral";
-  case CK_PointerToBoolean:
-return "PointerToBoolean";
-  case CK_ToVoid:
-return "ToVoid";
-  case CK_VectorSplat:
-return "VectorSplat";
-  case CK_IntegralCast:
-return "IntegralCast";
-  case CK_BooleanToSignedIntegral:
-return "BooleanToSignedIntegral";
-  case CK_IntegralToBoolean:
-return "IntegralToBoolean";
-  case CK_IntegralToFloating:
-return "IntegralToFloating";
-  case CK_FloatingToIntegral:
-return "FloatingToIntegral";
-  case CK_FloatingCast:
-return "FloatingCast";
-  case CK_FloatingToBoolean:
-return "FloatingToBoolean";
-  case CK_MemberPointerToBoolean:
-return "MemberPointerToBoolean";
-  case CK_CPointerToObjCPointerCast:
-return "CPointerToObjCPointerCast";
-  case CK_BlockPointerToObjCPointerCast:
-return "BlockPointerToObjCPointerCast";
-  case CK_AnyPointerToBlockPointerCast:
-return "AnyPointerToBlockPointerCast";
-  case CK_ObjCObjectLValueCast:
-return "ObjCObjectLValueCast";
-  case CK_FloatingRealToComplex:
-return "FloatingRealToComplex";
-  case CK_FloatingComplexToReal:
-return "FloatingComplexToReal";
-  case CK_FloatingComplexToBoolean:
-return "FloatingComplexToBoolean";
-  case CK_FloatingComplexCast:
-return "FloatingComplexCast";
-  case CK_FloatingComplexToIntegralComplex:
-return "FloatingComplexToIntegralComplex";
-  case CK_IntegralRealToComplex:
-return "IntegralRealToComplex";
-  case CK_IntegralComplexToReal:
-return "IntegralComplexToReal";
-  case CK_IntegralComplexToBoolean:
-return "IntegralComplexToBoolean";
-  case CK_IntegralComplexCast:
-return "IntegralComplexCast";
-  case CK_IntegralComplexToFloatingComplex:
-return "IntegralComplexToFloatingComplex";
-  case CK_ARCConsumeObject:
-return "ARCConsumeObject";
-  case CK_ARCProduceObject:
-return "ARCProduceObject";
-  case CK_ARCReclaimReturnedObject:
-return "ARCReclaimReturnedObject";
-  case CK_ARCExtendBlockObject:
-return "ARCExtendBlockObject";
-  case CK_AtomicToNonAtomic:
-return "AtomicToNonAtomic";
-  case CK_NonAtomicToAtomic:
-return "NonAtomicToAtomic";
-  case CK_CopyAndAutoreleaseBlockObject:
-return "CopyAndAutoreleaseBlockObject";
-  case CK_BuiltinFnToFnPtr:
-return "BuiltinFnToFnPtr";
-  case CK_ZeroToOCLEvent:
-return "ZeroToOCLEvent";
-  case CK_AddressSpaceConversion:
-return "AddressSpaceConversion

Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb marked 3 inline comments as done.
etienneb added a comment.

This patch has been modified to support dynamic matchers.
It rely on : http://reviews.llvm.org/D20207

Comments?



Comment at: lib/ASTMatchers/Dynamic/Marshallers.h:102
@@ +101,3 @@
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)

moved to that solution. (let try it)


Comment at: lib/ASTMatchers/Dynamic/Registry.cpp:78
@@ -77,2 +77,3 @@
   // Need Variant/Parser fixes:
+  // hasCastKind  
   // ofKind

sbenza wrote:
> Is it registered or not?
> You add this comment, but also add the matcher in the registry below.
bad revert.
I'm making a patch to allow dynamic matcher, and I'll come back fixing this CL.


http://reviews.llvm.org/D19871



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb marked an inline comment as done.
etienneb added a comment.





Comment at: include/clang/AST/OperationKinds.def:15
@@ +14,3 @@
+//
+/// @file OperationKinds.def
+///

aaron.ballman wrote:
> Do we use @file doxygen comments usually? I'm not certain if I've never seen 
> them, or if I'm just unobservant.
I can't tell if it's largely used.

I based my modifications on 'include/clang/Basic/OperatorKinds.def'

https://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/OperatorKinds.def
And there are doxygen comments.


http://reviews.llvm.org/D20207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20196: [clang-tidy] Inefficient string operation

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

drive-by, some nits.



Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:31
@@ +30,3 @@
+void InefficientStringAdditionCheck::registerMatchers(MatchFinder *Finder) {
+  auto BasicStringType = 
hasType(cxxRecordDecl(hasName("::std::basic_string")));
+

nits: I kind of prefer :

const auto BasicStringType

here and below.


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:74
@@ +73,3 @@
+Finder->addMatcher(WholeMatcher, this);
+
+Finder->addMatcher(exprWithCleanups(hasDescendant(PlusOperatorMatcher),

nits: remove this line


Comment at: docs/clang-tidy/checks/performance-inefficient-string-addition.rst:4
@@ +3,3 @@
+performance-inefficient-string-addition
+=
+

line with "===" should be the same length than title.


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:11
@@ +10,3 @@
+.. code:: c++
+
+

nits: delete one blank line


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:19
@@ +18,3 @@
+.. code:: c++
+
+   

remove extra blank line (only one)


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:45
@@ +44,3 @@
+   {
+   f(a+"Bar"+b);
+   }

nits: spaces between operator "+"


http://reviews.llvm.org/D20196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20218: [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

There virtual destructor can't be found and cause a compilation error
on a shared build.

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Which produce this error:
```
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ToolingTest.cpp.o: In 
function 
`clang::tooling::newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test::TestBody()':
ToolingTest.cpp:(.text._ZN5clang7tooling66newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test8TestBodyEv+0x49):
 undefined reference to `clang::SyntaxOnlyAction::~SyntaxOnlyAction()'
```

http://reviews.llvm.org/D20218

Files:
  include/clang/Frontend/FrontendActions.h
  lib/Frontend/FrontendActions.cpp

Index: lib/Frontend/FrontendActions.cpp
===
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -401,6 +401,9 @@
   return OS;
 }
 
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
 std::unique_ptr
 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   return llvm::make_unique();
Index: include/clang/Frontend/FrontendActions.h
===
--- include/clang/Frontend/FrontendActions.h
+++ include/clang/Frontend/FrontendActions.h
@@ -129,6 +129,7 @@
  StringRef InFile) override;
 
 public:
+  ~SyntaxOnlyAction() override;
   bool hasCodeCompletionSupport() const override { return true; }
 };
 


Index: lib/Frontend/FrontendActions.cpp
===
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -401,6 +401,9 @@
   return OS;
 }
 
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
 std::unique_ptr
 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   return llvm::make_unique();
Index: include/clang/Frontend/FrontendActions.h
===
--- include/clang/Frontend/FrontendActions.h
+++ include/clang/Frontend/FrontendActions.h
@@ -129,6 +129,7 @@
  StringRef InFile) override;
 
 public:
+  ~SyntaxOnlyAction() override;
   bool hasCodeCompletionSupport() const override { return true; }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20218: [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

note: To repro, you must compile the tests.

  % ninja check-all


http://reviews.llvm.org/D20218



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

drive by



Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:40
@@ +39,3 @@
+   unsigned &Len) {
+  SourceManager &SM = *Result.SourceManager;
+  const ASTContext &Context = *Result.Context;

nit: const


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:97
@@ +96,3 @@
+void UseNoexceptCheck::check(const MatchFinder::MatchResult &Result) {
+  auto FuncDecl = Result.Nodes.getNodeAs("functionDecl");
+  if (!FuncDecl)

nit:  const auto FuncDecl* 


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:114
@@ +113,3 @@
+"specification '%1'; use '%2' instead")
+  << FuncDecl->getNameInfo().getAsString()
+  << StringRef(

I'm not sure, but I think you can replace

FuncDecl->getNameInfo().getAsString() by FuncDecl.

IIRC, there is a automatic conversion for the name.


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:120
@@ +119,3 @@
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(FileMoveRange.getBegin(),
+FileMoveRange.getEnd()),

FileMoveRange is a CharSourceRange, so why to you need to do getTokenRange?

```
 CharSourceRange FileMoveRange;
```


Comment at: clang-tidy/utils/LexerUtils.cpp:38
@@ -37,1 +37,3 @@
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,

I like having lexer functions lifted out.
But 'ParseTokens' doesn't reflect that it stop when reaching a semicolon or a 
brace.

```
if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
```


Comment at: test/clang-tidy/modernize-use-noexcept.cpp:4
@@ +3,3 @@
+
+class A{};
+class B{};

nits: space after A and B
class A {};


http://reviews.llvm.org/D18575



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269334 - [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Thu May 12 14:51:18 2016
New Revision: 269334

URL: http://llvm.org/viewvc/llvm-project?rev=269334&view=rev
Log:
[Tooling] Fix broken dependency for shared build

Summary:
There virtual destructor can't be found and cause a compilation error
on a shared build.

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Which produce this error:
```
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ToolingTest.cpp.o: In 
function 
`clang::tooling::newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test::TestBody()':
ToolingTest.cpp:(.text._ZN5clang7tooling66newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test8TestBodyEv+0x49):
 undefined reference to `clang::SyntaxOnlyAction::~SyntaxOnlyAction()'
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20218

Modified:
cfe/trunk/include/clang/Frontend/FrontendActions.h
cfe/trunk/lib/Frontend/FrontendActions.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=269334&r1=269333&r2=269334&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Thu May 12 14:51:18 2016
@@ -129,6 +129,7 @@ protected:
  StringRef InFile) override;
 
 public:
+  ~SyntaxOnlyAction() override;
   bool hasCodeCompletionSupport() const override { return true; }
 };
 

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=269334&r1=269333&r2=269334&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu May 12 14:51:18 2016
@@ -401,6 +401,9 @@ raw_pwrite_stream *GenerateModuleAction:
   return OS;
 }
 
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
 std::unique_ptr
 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   return llvm::make_unique();


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.


Comment at: clang-tidy/utils/TypeTraits.cpp:35
@@ +34,3 @@
+return false;
+  for (const CXXConstructorDecl *Constructor : Record->ctors()) {
+if (Constructor->isCopyConstructor() && Constructor->isDeleted())

aaron.ballman wrote:
> Can just use `const auto *` for this, but I'm fine either way.
I prefer const auto *  too


Comment at: clang-tidy/utils/TypeTraits.cpp:44
@@ -27,3 +43,3 @@
 
 llvm::Optional isExpensiveToCopy(QualType Type, ASTContext &Context) {
   if (Type->isDependentType())

nit: const ASTContext &Context


http://reviews.llvm.org/D20170



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:24
@@ -20,2 +23,3 @@
+
 bool classHasTrivialCopyAndDestroy(QualType Type) {
   auto *Record = Type->getAsCXXRecordDecl();

Should this be lifted to 'type_traits' ?


The same function exists into clang-tidy/utils/TypeTraits.cpp
```
namespace {
bool classHasTrivialCopyAndDestroy(QualType Type) {
  auto *Record = Type->getAsCXXRecordDecl();
  return Record && Record->hasDefinition() &&
 !Record->hasNonTrivialCopyConstructor() &&
 !Record->hasNonTrivialDestructor();
}
} // namespace
```

 Alex, any toughs?


Comment at: clang-tidy/utils/TypeTraits.cpp:31
@@ +30,3 @@
+
+bool hasDeletedCopyConstructor(QualType Type, ASTContext &Context) {
+  auto *Record = Type->getAsCXXRecordDecl();

aaron.ballman wrote:
> No need to pass in `Context` any longer.
ditto, to be lifted or not?


http://reviews.llvm.org/D20170



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:32
@@ +31,3 @@
+
+  diag(MatchedDecl->getLocStart(), "use using instead of typedef")
+  << FixItHint::CreateReplacement(

I think 'using' should be quote.
This message is hard to read and understand from a user point of view.


Comment at: test/clang-tidy/modernize-use-using.cpp:48
@@ +47,3 @@
+};
+
+using balba = long long;

Could you add test with macro:

#define CODE \
  typedef int INT; \
  []

CODE;


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20053: [clang-tidy] Add misc-unnecessary-mutable check.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:38
@@ +37,3 @@
+
+  void RunSearch(Decl *Declaration) {
+auto *Body = Declaration->getBody();

nit: Decl *Declaration -> const Decl *Declaration

and other visitor functions.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:40
@@ +39,3 @@
+auto *Body = Declaration->getBody();
+ParMap = new ParentMap(Body);
+TraverseStmt(Body);

Why not using stack memory instead of allocating memory?

ParentMap LocalMap;
ParMap = &LocalMap;
TraverseStmt(Body);
ParMap = nullptr;/// <-- I also prefer seeing this variable being after 
recursion.



Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:46
@@ +45,3 @@
+  bool VisitExpr(Expr *GenericExpr) {
+MemberExpr *Expression = dyn_cast(GenericExpr);
+if (Expression == nullptr)

Could we shortcut the recursion if "FoundNonConstUse" is true.
There is already a case found.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:50
@@ +49,3 @@
+
+if (Expression->getMemberDecl() != SoughtField)
+  return true;

this "if" and the previous one should be merged.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:66
@@ +65,3 @@
+// It's something weird. Just to be sure, assume we're const.
+IsConstObj = true;
+  } else {

As soon as something is "IsConstObj", they must be an early exit.
No need to continue iterations.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:80
@@ +79,3 @@
+// whose parent is ImplicitCastExpr to rvalue or something constant.
+bool HasRvalueCast = false;
+bool HasConstCast = false;

nit: HasRvalueCast  -> HasRValueCast 


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:85
@@ +84,3 @@
+  dyn_cast(ParMap->getParent(Expression));
+  if (Cast != nullptr) {
+HasRvalueCast = Cast->getCastKind() == CastKind::CK_LValueToRValue;

if (Cast != nullptr) {

replace by

if (const auto* Cast =  
dyn_cast(ParMap->getParent(Expression)) {

and remove previous line.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:99
@@ +98,3 @@
+
+  bool IsNonConstUseFound() const { return FoundNonConstUse; }
+

nit: IsNonConstUseFound -> isNonConstUseFound
coding style wants lower case as first letter.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:121
@@ +120,3 @@
+FunctionDecl *Declaration = dyn_cast(GenericDecl);
+
+if (Declaration == nullptr)

nit: remove this empty line


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:167
@@ +166,3 @@
+
+if (DeclToken.getKind() == tok::TokenKind::semi) {
+  break;

nit: remove { }


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:171
@@ +170,3 @@
+
+if (DeclToken.getKind() == tok::TokenKind::comma) {
+  return false;

nit: remove { }


http://reviews.llvm.org/D20053



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269347 - [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Thu May 12 15:58:56 2016
New Revision: 269347

URL: http://llvm.org/viewvc/llvm-project?rev=269347&view=rev
Log:
[AST] Move operations enum to a definition file.

Summary:
This patch moves the enum definitions to a definition (.def) file.

These modifications provide way to list enumerators of a given type.

As an example, this allow parsing of "kinds" in the dynamic matchers.
see: http://reviews.llvm.org/D19871
The dynamic matcher "ofKind" also required this patch to be fixed.

Reviewers: klimek, aaron.ballman, rsmith

Subscribers: klimek, sbenza, alexfh, cfe-commits

Differential Revision: http://reviews.llvm.org/D20207

Added:
cfe/trunk/include/clang/AST/OperationKinds.def
Modified:
cfe/trunk/include/clang/AST/OperationKinds.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/AST/Expr.cpp

Added: cfe/trunk/include/clang/AST/OperationKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.def?rev=269347&view=auto
==
--- cfe/trunk/include/clang/AST/OperationKinds.def (added)
+++ cfe/trunk/include/clang/AST/OperationKinds.def Thu May 12 15:58:56 2016
@@ -0,0 +1,406 @@
+//===--- OperationKinds.def - Operations Database ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file enumerates the different kinds of operations that can be
+// performed by various expressions.
+//
+//===--===//
+//
+/// @file OperationKinds.def
+///
+/// In this file, each of the C/C++ operations is enumerated CAST_OPERATION,
+/// BINARY_OPERATION or UNARY_OPERATION macro, each of which can be specified 
by
+/// the code including this file.
+///
+/// Macros had one or two arguments:
+///
+/// Name: The name of the operation. Name (prefixed with CK_, UO_ or BO_) will
+/// be the name of the corresponding enumerator (see OperationsKinds.h).
+///
+/// Spelling: A string that provides a canonical spelling for the operation.
+
+#ifndef CAST_OPERATION
+#  define CAST_OPERATION(Name)
+#endif
+
+#ifndef BINARY_OPERATION
+#  define BINARY_OPERATION(Name, Spelling)
+#endif
+
+#ifndef UNARY_OPERATION
+#  define UNARY_OPERATION(Name, Spelling)
+#endif
+
+//===- Cast Operations  
---===//
+
+/// CK_Dependent - A conversion which cannot yet be analyzed because
+/// either the expression or target type is dependent.  These are
+/// created only for explicit casts; dependent ASTs aren't required
+/// to even approximately type-check.
+///   (T*) malloc(sizeof(T))
+///   reinterpret_cast(A::alloc());
+CAST_OPERATION(Dependent)
+
+/// CK_BitCast - A conversion which causes a bit pattern of one type
+/// to be reinterpreted as a bit pattern of another type.  Generally
+/// the operands must have equivalent size and unrelated types.
+///
+/// The pointer conversion char* -> int* is a bitcast.  A conversion
+/// from any pointer type to a C pointer type is a bitcast unless
+/// it's actually BaseToDerived or DerivedToBase.  A conversion to a
+/// block pointer or ObjC pointer type is a bitcast only if the
+/// operand has the same type kind; otherwise, it's one of the
+/// specialized casts below.
+///
+/// Vector coercions are bitcasts.
+CAST_OPERATION(BitCast)
+
+/// CK_LValueBitCast - A conversion which reinterprets the address of
+/// an l-value as an l-value of a different kind.  Used for
+/// reinterpret_casts of l-value expressions to reference types.
+///bool b; reinterpret_cast(b) = 'a';
+CAST_OPERATION(LValueBitCast)
+
+/// CK_LValueToRValue - A conversion which causes the extraction of
+/// an r-value from the operand gl-value.  The result of an r-value
+/// conversion is always unqualified.
+CAST_OPERATION(LValueToRValue)
+
+/// CK_NoOp - A conversion which does not affect the type other than
+/// (possibly) adding qualifiers.
+///   int-> int
+///   char** -> const char * const *
+CAST_OPERATION(NoOp)
+
+/// CK_BaseToDerived - A conversion from a C++ class pointer/reference
+/// to a derived class pointer/reference.
+///   B *b = static_cast(a);
+CAST_OPERATION(BaseToDerived)
+
+/// CK_DerivedToBase - A conversion from a C++ class pointer
+/// to a base class pointer.
+///   A *a = new B();
+CAST_OPERATION(DerivedToBase)
+
+/// CK_UncheckedDerivedToBase - A conversion from a C++ class
+/// pointer/reference to a base class that can assume that the
+/// derived pointer is not null.
+///   const A &a = B();
+///   b->method_from_a();
+CAST_OPERATION(UncheckedDerivedToBase)
+
+/// CK_Dynamic - A C++ dynamic_cast.
+CAST_OPERATION(Dynamic)
+
+/// CK_ToUnion - The GCC cast-to-union extension.
+///   int   -> unio

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:98
@@ +97,3 @@
+  const auto *FuncDecl = Result.Nodes.getNodeAs("functionDecl");
+  if (!FuncDecl)
+return;

I'm not saying to use 'const *FuncDecl', but 'const auto*'


Comment at: clang-tidy/utils/LexerUtils.cpp:38
@@ -37,1 +37,3 @@
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,

If you call ParseTokens, it will parse tokens until it reach a 
semicolon/lbrace? exact?



http://reviews.llvm.org/D18575



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57101.
etienneb marked an inline comment as done.
etienneb added a comment.

regenerate doc


http://reviews.llvm.org/D19871

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2159,6 +2159,15 @@
 
 
 
+MatcherCastExpr>hasCastKindCastKind Kind
+Matches casts that has a given cast kind.
+
+Example: matches the implicit cast around 0
+(matcher = castExpr(hasCastKind(CK_NullToPointer)))
+  int *p = 0;
+
+
+
 MatcherCharacterLiteral>equalsValueT  Value
 Matches literals that are equal to the given value.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57123.
etienneb added a comment.

add unittest


http://reviews.llvm.org/D19871

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,15 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+  EXPECT_TRUE(matches("char *p = 0;",
+  implicitCastExpr(hasCastKind(CK_NullToPointer;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2159,6 +2159,15 @@
 
 
 
+MatcherCastExpr>hasCastKindCastKind Kind
+Matches casts that has a given cast kind.
+
+Example: matches the implicit cast around 0
+(matcher = castExpr(hasCastKind(CK_NullToPointer)))
+  int *p = 0;
+
+
+
 MatcherCharacterLiteral>equalsValueT  Value
 Matches literals that are equal to the given value.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D19871#428997, @jroelofs wrote:

> Drive-by thought: I think it would be useful to be able to match implicit 
> casts separately from explicit casts when using this new matcher.


Jonathan, I think what you are asking for is already supported.
I added an unittest to confirm it.

  EXPECT_TRUE(matches("char *p = 0;",
  implicitCastExpr(hasCastKind(CK_NullToPointer;

If I misunderstood your comment, could you provide an example.


http://reviews.llvm.org/D19871



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57124.
etienneb added a comment.

nit: indentation


http://reviews.llvm.org/D19871

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,15 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+  EXPECT_TRUE(matches("char *p = 0;",
+  implicitCastExpr(hasCastKind(CK_NullToPointer;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2159,6 +2159,15 @@
 
 
 
+MatcherCastExpr>hasCastKindCastKind Kind
+Matches casts that has a given cast kind.
+
+Example: matches the implicit cast around 0
+(matcher = castExpr(hasCastKind(CK_NullToPointer)))
+  int *p = 0;
+
+
+
 MatcherCharacterLiteral>equalsValueT  Value
 Matches literals that are equal to the given value.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:22
@@ -20,2 +21,3 @@
+
 bool classHasTrivialCopyAndDestroy(QualType Type) {
   auto *Record = Type->getAsCXXRecordDecl();

My bad! I didn't saw the file change when reading. Forget about it.


Comment at: clang-tidy/utils/TypeTraits.cpp:29
@@ +28,3 @@
+
+bool hasDeletedCopyConstructor(QualType Type) {
+  auto *Record = Type->getAsCXXRecordDecl();

ditto. I was thinking this was in the checker file.
ignore it.


http://reviews.llvm.org/D20170



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20226: [AST] Add missing const qualifiers to AstContext in Type.cpp

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: rsmith.
etienneb added a subscriber: cfe-commits.

Add some missing const qualifiers to AstContext.
The ASTContext can't be modified with accessors.

There is no behavior change. This patch is cleanup only.

http://reviews.llvm.org/D20226

Files:
  include/clang/AST/Type.h
  lib/AST/Type.cpp

Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -64,7 +64,7 @@
   return nullptr;
 }
 
-bool QualType::isConstant(QualType T, ASTContext &Ctx) {
+bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
   if (T.isConstQualified())
 return true;
 
@@ -74,7 +74,7 @@
   return T.getAddressSpace() == LangAS::opencl_constant;
 }
 
-unsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context,
+unsigned ConstantArrayType::getNumAddressingBits(const ASTContext &Context,
  QualType ElementType,
const llvm::APInt &NumElements) {
   uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity();
@@ -109,7 +109,7 @@
   return TotalSize.getActiveBits();
 }
 
-unsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) {
+unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) {
   unsigned Bits = Context.getTypeSize(Context.getSizeType());
   
   // Limit the number of bits in size_t so that maximal bit size fits 64 bit
@@ -1616,7 +1616,7 @@
 /// \param Ctx The context in which this type occurs.
 ///
 /// \returns true if the type is considered an integral type, false otherwise.
-bool Type::isIntegralType(ASTContext &Ctx) const {
+bool Type::isIntegralType(const ASTContext &Ctx) const {
   if (const BuiltinType *BT = dyn_cast(CanonicalType))
 return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Int128;
@@ -1958,15 +1958,15 @@
   }
 }
 
-bool QualType::isPODType(ASTContext &Context) const {
+bool QualType::isPODType(const ASTContext &Context) const {
   // C++11 has a more relaxed definition of POD.
   if (Context.getLangOpts().CPlusPlus11)
 return isCXX11PODType(Context);
 
   return isCXX98PODType(Context);
 }
 
-bool QualType::isCXX98PODType(ASTContext &Context) const {
+bool QualType::isCXX98PODType(const ASTContext &Context) const {
   // The compiler shouldn't query this for incomplete types, but the user might.
   // We return false for that case. Except for incomplete arrays of PODs, which
   // are PODs according to the standard.
@@ -2026,7 +2026,7 @@
   }
 }
 
-bool QualType::isTrivialType(ASTContext &Context) const {
+bool QualType::isTrivialType(const ASTContext &Context) const {
   // The compiler shouldn't query this for incomplete types, but the user might.
   // We return false for that case. Except for incomplete arrays of PODs, which
   // are PODs according to the standard.
@@ -2089,7 +2089,7 @@
   return false;
 }
 
-bool QualType::isTriviallyCopyableType(ASTContext &Context) const {
+bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
   if ((*this)->isArrayType())
 return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
 
@@ -2249,7 +2249,7 @@
 // This is effectively the intersection of isTrivialType and
 // isStandardLayoutType. We implement it directly to avoid redundant
 // conversions from a type to a CXXRecordDecl.
-bool QualType::isCXX11PODType(ASTContext &Context) const {
+bool QualType::isCXX11PODType(const ASTContext &Context) const {
   const Type *ty = getTypePtr();
   if (ty->isDependentType())
 return false;
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -722,27 +722,27 @@
   /// applied to this type.
   unsigned getCVRQualifiers() const;
 
-  bool isConstant(ASTContext& Ctx) const {
+  bool isConstant(const ASTContext& Ctx) const {
 return QualType::isConstant(*this, Ctx);
   }
 
   /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
-  bool isPODType(ASTContext &Context) const;
+  bool isPODType(const ASTContext &Context) const;
 
   /// Return true if this is a POD type according to the rules of the C++98
   /// standard, regardless of the current compilation's language.
-  bool isCXX98PODType(ASTContext &Context) const;
+  bool isCXX98PODType(const ASTContext &Context) const;
 
   /// Return true if this is a POD type according to the more relaxed rules
   /// of the C++11 standard, regardless of the current compilation's language.
   /// (C++0x [basic.types]p9)
-  bool isCXX11PODType(ASTContext &Context) const;
+  bool isCXX11PODType(const ASTContext &Context) const;
 
   /// Return true if this is a trivial type per (C++0x [basic.types]p9)
-  bool isTrivialType(ASTContext &Context) const;
+  bool isTrivialType(const ASTContext &Context) const;
 
   /// Return true if th

Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:42
@@ -27,3 +41,3 @@
 
 llvm::Optional isExpensiveToCopy(QualType Type, ASTContext &Context) {
   if (Type->isDependentType())

You're right too.
But, it's possible to fix these prototypes:
http://reviews.llvm.org/D20226


http://reviews.llvm.org/D20170



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269418 - [AST] Add missing const qualifiers to AstContext in Type.cpp

2016-05-13 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Fri May 13 09:31:44 2016
New Revision: 269418

URL: http://llvm.org/viewvc/llvm-project?rev=269418&view=rev
Log:
[AST] Add missing const qualifiers to AstContext in Type.cpp

Summary:
Add some missing const qualifiers to AstContext.
The ASTContext can't be modified with accessors.

There is no behavior change. This patch is cleanup only.

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20226

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=269418&r1=269417&r2=269418&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri May 13 09:31:44 2016
@@ -722,27 +722,27 @@ public:
   /// applied to this type.
   unsigned getCVRQualifiers() const;
 
-  bool isConstant(ASTContext& Ctx) const {
+  bool isConstant(const ASTContext& Ctx) const {
 return QualType::isConstant(*this, Ctx);
   }
 
   /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 
3.9p10).
-  bool isPODType(ASTContext &Context) const;
+  bool isPODType(const ASTContext &Context) const;
 
   /// Return true if this is a POD type according to the rules of the C++98
   /// standard, regardless of the current compilation's language.
-  bool isCXX98PODType(ASTContext &Context) const;
+  bool isCXX98PODType(const ASTContext &Context) const;
 
   /// Return true if this is a POD type according to the more relaxed rules
   /// of the C++11 standard, regardless of the current compilation's language.
   /// (C++0x [basic.types]p9)
-  bool isCXX11PODType(ASTContext &Context) const;
+  bool isCXX11PODType(const ASTContext &Context) const;
 
   /// Return true if this is a trivial type per (C++0x [basic.types]p9)
-  bool isTrivialType(ASTContext &Context) const;
+  bool isTrivialType(const ASTContext &Context) const;
 
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
-  bool isTriviallyCopyableType(ASTContext &Context) const;
+  bool isTriviallyCopyableType(const ASTContext &Context) const;
 
   // Don't promise in the API that anything besides 'const' can be
   // easily added.
@@ -1084,7 +1084,7 @@ private:
   // These methods are implemented in a separate translation unit;
   // "static"-ize them to avoid creating temporary QualTypes in the
   // caller.
-  static bool isConstant(QualType T, ASTContext& Ctx);
+  static bool isConstant(QualType T, const ASTContext& Ctx);
   static QualType getDesugaredType(QualType T, const ASTContext &Context);
   static SplitQualType getSplitDesugaredType(QualType T);
   static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
@@ -1619,7 +1619,7 @@ public:
   bool isChar16Type() const;
   bool isChar32Type() const;
   bool isAnyCharacterType() const;
-  bool isIntegralType(ASTContext &Ctx) const;
+  bool isIntegralType(const ASTContext &Ctx) const;
 
   /// Determine whether this type is an integral or enumeration type.
   bool isIntegralOrEnumerationType() const;
@@ -2513,13 +2513,13 @@ public:
 
   /// \brief Determine the number of bits required to address a member of
   // an array with the given element type and number of elements.
-  static unsigned getNumAddressingBits(ASTContext &Context,
+  static unsigned getNumAddressingBits(const ASTContext &Context,
QualType ElementType,
const llvm::APInt &NumElements);
 
   /// \brief Determine the maximum number of active bits that an array's size
   /// can require, which limits the maximum size of the array.
-  static unsigned getMaxSizeBits(ASTContext &Context);
+  static unsigned getMaxSizeBits(const ASTContext &Context);
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, getElementType(), getSize(),
@@ -3004,7 +3004,7 @@ public:
 
   /// \brief Determine the type of an expression that calls a function of
   /// this type.
-  QualType getCallResultType(ASTContext &Context) const {
+  QualType getCallResultType(const ASTContext &Context) const {
 return getReturnType().getNonLValueExprType(Context);
   }
 

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=269418&r1=269417&r2=269418&view=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri May 13 09:31:44 2016
@@ -64,7 +64,7 @@ const IdentifierInfo* QualType::getBaseT
   return nullptr;
 }
 
-bool QualType::isConstant(QualType T, ASTContext &Ctx) {
+bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
   if (T.isConstQualified())
 return true;
 
@@ -74,7 +74,7 @@ bool QualType::isConstant(QualType T, AS
   return T.getAddressSpace() == LangAS::ope

Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D19871#429466, @Prazek wrote:

> +1 I will probably also use this.
>
> Does hasCastKind works for implicitCastExpr?


Yes, there is a unittest with the code.


http://reviews.llvm.org/D19871



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20240: [clang-rename] Fix broken dependency on shared build.

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

The build is broken due to a missing dependency.

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Which produce this error:
```
tools/clang/tools/extra/clang-rename/CMakeFiles/clangRename.dir/USRLocFinder.cpp.o:
 In function `clang::RecursiveASTVisitor::TraverseCXXConstructorDecl(clang::CXXConstructorDecl*)':
USRLocFinder.cpp:(.text._ZN5clang19RecursiveASTVisitorINS_6rename12_GLOBAL__N_123USRLocFindingASTVisitorEE26TraverseCXXConstructorDeclEPNS_18CXXConstructorDeclE+0x170):
 undefined reference to `clang::Lexer::getSourceText(clang::CharSourceRange, 
clang::SourceManager const&, clang::LangOptions const&, bool*)'
```

http://reviews.llvm.org/D20240

Files:
  clang-rename/CMakeLists.txt

Index: clang-rename/CMakeLists.txt
===
--- clang-rename/CMakeLists.txt
+++ clang-rename/CMakeLists.txt
@@ -10,6 +10,7 @@
   clangAST
   clangBasic
   clangIndex
+  clangLex
   clangToolingCore
   )
 


Index: clang-rename/CMakeLists.txt
===
--- clang-rename/CMakeLists.txt
+++ clang-rename/CMakeLists.txt
@@ -10,6 +10,7 @@
   clangAST
   clangBasic
   clangIndex
+  clangLex
   clangToolingCore
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20240: [clang-rename] Fix broken dependency on shared build.

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

thanks, landing as soon as my other checkouts complete their tests (few 
minutes).


http://reviews.llvm.org/D20240



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r269429 - [clang-rename] Fix broken dependency on shared build.

2016-05-13 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Fri May 13 10:38:54 2016
New Revision: 269429

URL: http://llvm.org/viewvc/llvm-project?rev=269429&view=rev
Log:
[clang-rename] Fix broken dependency on shared build.

Summary:
The build is broken due to a missing dependency.

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Which produce this error:
```
tools/clang/tools/extra/clang-rename/CMakeFiles/clangRename.dir/USRLocFinder.cpp.o:
 In function `clang::RecursiveASTVisitor::TraverseCXXConstructorDecl(clang::CXXConstructorDecl*)':
USRLocFinder.cpp:(.text._ZN5clang19RecursiveASTVisitorINS_6rename12_GLOBAL__N_123USRLocFindingASTVisitorEE26TraverseCXXConstructorDeclEPNS_18CXXConstructorDeclE+0x170):
 undefined reference to `clang::Lexer::getSourceText(clang::CharSourceRange, 
clang::SourceManager const&, clang::LangOptions const&, bool*)'
```

Reviewers: alexfh, yaron.keren

Subscribers: yaron.keren, cfe-commits

Differential Revision: http://reviews.llvm.org/D20240

Modified:
clang-tools-extra/trunk/clang-rename/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/CMakeLists.txt?rev=269429&r1=269428&r2=269429&view=diff
==
--- clang-tools-extra/trunk/clang-rename/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-rename/CMakeLists.txt Fri May 13 10:38:54 2016
@@ -10,6 +10,7 @@ add_clang_library(clangRename
   clangAST
   clangBasic
   clangIndex
+  clangLex
   clangToolingCore
   )
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20245: [include-fixer] Fix broken dependency shared build

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added reviewers: bkramer, hokein.
etienneb added a subscriber: cfe-commits.

The shared build is broken (again).

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Errors:
```
tools/clang/tools/extra/include-fixer/tool/CMakeFiles/clang-include-fixer.dir/ClangIncludeFixer.cpp.o:
 In function `(anonymous namespace)::includeFixerMain(int, char const**)':
ClangIncludeFixer.cpp:(.text._ZN12_GLOBAL__N_116includeFixerMainEiPPKc+0xbe9): 
undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
collect2: error: ld returned 1 exit status
```

```
tools/clang/tools/extra/unittests/include-fixer/CMakeFiles/IncludeFixerTests.dir/IncludeFixerTest.cpp.o:
 In function `clang::include_fixer::(anonymous 
namespace)::runIncludeFixer(llvm::StringRef, std::vector > const&)':
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x10e):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x1dc):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x2f3):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x40e):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x526):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
```

http://reviews.llvm.org/D20245

Files:
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/tool/CMakeLists.txt
  unittests/include-fixer/CMakeLists.txt

Index: unittests/include-fixer/CMakeLists.txt
===
--- unittests/include-fixer/CMakeLists.txt
+++ unittests/include-fixer/CMakeLists.txt
@@ -22,6 +22,7 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
 
 add_subdirectory(find-all-symbols)
Index: include-fixer/tool/CMakeLists.txt
===
--- include-fixer/tool/CMakeLists.txt
+++ include-fixer/tool/CMakeLists.txt
@@ -8,4 +8,5 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
Index: include-fixer/find-all-symbols/SymbolInfo.h
===
--- include-fixer/find-all-symbols/SymbolInfo.h
+++ include-fixer/find-all-symbols/SymbolInfo.h
@@ -47,7 +47,7 @@
 
   // The default constructor is required by YAML traits in
   // LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
-  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {};
+  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
 
   SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
  int LineNumber, const std::vector &Contexts);


Index: unittests/include-fixer/CMakeLists.txt
===
--- unittests/include-fixer/CMakeLists.txt
+++ unittests/include-fixer/CMakeLists.txt
@@ -22,6 +22,7 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
 
 add_subdirectory(find-all-symbols)
Index: include-fixer/tool/CMakeLists.txt
===
--- include-fixer/tool/CMakeLists.txt
+++ include-fixer/tool/CMakeLists.txt
@@ -8,4 +8,5 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
Index: include-fixer/find-all-symbols/SymbolInfo.h
===
--- include-fixer/find-all-symbols/SymbolInfo.h
+++ include-fixer/find-all-symbols/SymbolInfo.h
@@ -47,7 +47,7 @@
 
   // The default constructor is required by YAML traits in
   // LLVM_YAML_IS_DOCUMENT_LIST_V

[clang-tools-extra] r269441 - [include-fixer] Fix broken dependency shared build

2016-05-13 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Fri May 13 12:38:22 2016
New Revision: 269441

URL: http://llvm.org/viewvc/llvm-project?rev=269441&view=rev
Log:
[include-fixer] Fix broken dependency shared build

Summary:
The shared build is broken (again).

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Errors:
```
tools/clang/tools/extra/include-fixer/tool/CMakeFiles/clang-include-fixer.dir/ClangIncludeFixer.cpp.o:
 In function `(anonymous namespace)::includeFixerMain(int, char const**)':
ClangIncludeFixer.cpp:(.text._ZN12_GLOBAL__N_116includeFixerMainEiPPKc+0xbe9): 
undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
collect2: error: ld returned 1 exit status
```

```
tools/clang/tools/extra/unittests/include-fixer/CMakeFiles/IncludeFixerTests.dir/IncludeFixerTest.cpp.o:
 In function `clang::include_fixer::(anonymous 
namespace)::runIncludeFixer(llvm::StringRef, std::vector > const&)':
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x10e):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x1dc):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x2f3):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x40e):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x526):
 undefined reference to 
`clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, 
clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, 
std::vector, 
std::allocator > > const&)'
```

Reviewers: bkramer, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20245

Modified:
clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt

Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h?rev=269441&r1=269440&r2=269441&view=diff
==
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h 
(original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h Fri May 
13 12:38:22 2016
@@ -47,7 +47,7 @@ public:
 
   // The default constructor is required by YAML traits in
   // LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
-  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {};
+  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
 
   SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
  int LineNumber, const std::vector &Contexts);

Modified: clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt?rev=269441&r1=269440&r2=269441&view=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt Fri May 13 
12:38:22 2016
@@ -8,4 +8,5 @@ target_link_libraries(clang-include-fixe
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )

Modified: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt?rev=269441&r1=269440&r2=269441&view=diff
==
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt

Re: [PATCH] D20245: [include-fixer] Fix broken dependency shared build

2016-05-13 Thread Etienne Bergeron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269441: [include-fixer] Fix broken dependency shared build 
(authored by etienneb).

Changed prior to commit:
  http://reviews.llvm.org/D20245?vs=57208&id=57221#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20245

Files:
  clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
  clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
  clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt

Index: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
@@ -22,6 +22,7 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
 
 add_subdirectory(find-all-symbols)
Index: clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
===
--- clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
+++ clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
@@ -8,4 +8,5 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
@@ -47,7 +47,7 @@
 
   // The default constructor is required by YAML traits in
   // LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
-  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {};
+  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
 
   SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
  int LineNumber, const std::vector &Contexts);


Index: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
@@ -22,6 +22,7 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
 
 add_subdirectory(find-all-symbols)
Index: clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
===
--- clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
+++ clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
@@ -8,4 +8,5 @@
   clangRewrite
   clangTooling
   clangToolingCore
+  findAllSymbols
   )
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
@@ -47,7 +47,7 @@
 
   // The default constructor is required by YAML traits in
   // LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
-  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {};
+  SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
 
   SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
  int LineNumber, const std::vector &Contexts);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20240: [clang-rename] Fix broken dependency on shared build.

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20240#429910, @vmiklos wrote:

> Thanks for fixing the problem I introduced. :-)


No worries, I did the same twice this week.


http://reviews.llvm.org/D20240



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r269460 - Add an AST matcher for CastExpr kind

2016-05-13 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Fri May 13 14:36:55 2016
New Revision: 269460

URL: http://llvm.org/viewvc/llvm-project?rev=269460&view=rev
Log:
Add an AST matcher for CastExpr kind

Summary:
This AST matcher will match a given CastExpr kind.
It's an narrowing matcher on CastExpr.

Reviewers: klimek, alexfh, sbenza, aaron.ballman

Subscribers: Prazek, jroelofs, aaron.ballman, klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D19871

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=269460&r1=269459&r2=269460&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri May 13 14:36:55 2016
@@ -2159,6 +2159,15 @@ Example matches f(0, 0) (matcher = callE
 
 
 
+MatcherCastExpr>hasCastKindCastKind Kind
+Matches casts that has 
a given cast kind.
+
+Example: matches the implicit cast around 0
+(matcher = castExpr(hasCastKind(CK_NullToPointer)))
+  int *p = 0;
+
+
+
 MatcherCharacterLiteral>equalsValueT  Value
 Matches literals that are 
equal to the given value.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=269460&r1=269459&r2=269460&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri May 13 14:36:55 2016
@@ -3551,6 +3551,17 @@ AST_POLYMORPHIC_MATCHER_P(hasSourceExpre
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=269460&r1=269459&r2=269460&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Fri May 13 14:36:55 2016
@@ -96,6 +96,28 @@ public:
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=269460&r1=269459&r2=269460&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri May 13 14:36:55 2016
@@ -210,6 +210,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=269460&r1=269459&r2=269460&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Fri May 13 14:36:55 2016
@@ -3485,6 +

[PATCH] D20261: [compiler-rt] Fix multi-configuration output paths

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: rnk.
etienneb added a subscriber: cfe-commits.

When using a multi-configuration build (i.e. MSVC) the output path where
libraries are dropped is incorrect.

Example:
```
C:\src\llvm\examples>d:\src\llvm\build\Release\bin\clang-cl.exe 
-fsanitize=address test.cc
LINK : fatal error LNK1181: cannot open input file 
'd:\src\llvm\build\Release\bin\..\lib\clang\3.9.0\lib\windows\clang_rt.asan-i386.lib'
```

The dropped executable path contains the configuration 'Release':
'd:\src\llvm\build\Release\bin\..\lib\clang\3.9.0\lib\windows\Release\clang_rt.asan-i386.lib'


The variable 'RUNTIME_OUTPUT_DIRECTORY' is used to specify the output directory.
But CMAKE is appending the current configuration (i.e. Debug, Release).

see: https://cmake.org/cmake/help/v3.0/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
```
"Multi-configuration generators (VS, Xcode) append a per-configuration 
subdirectory to the specified directory."
```

To avoid this problem, the configuration specific variable must be set:
'RUNTIME_OUTPUT_DIRECTORY_DEBUG', 'RUNTIME_OUTPUT_DIRECTORY_RELEASE', and so on.

http://reviews.llvm.org/D20261

Files:
  cmake/Modules/AddCompilerRT.cmake

Index: cmake/Modules/AddCompilerRT.cmake
===
--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -155,10 +155,27 @@
 set_target_link_flags(${libname} ${extra_linkflags_${libname}})
 set_property(TARGET ${libname} APPEND PROPERTY 
 COMPILE_DEFINITIONS ${LIB_DEFS})
-set_target_properties(${libname} PROPERTIES
-ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
-LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
-RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+
+# For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators
+# append a per-configuration subdirectory to the specified directory.
+# To avoid the appended folder, the configuration specific variable must be
+# set 'RUNTIME_OUTPUT_DIRECTORY_${CONF}':
+# ARCHIVE_OUTPUT_DIRECTORY_DEBUG, ARCHIVE_OUTPUT_DIRECTORY_RELEASE, ...
+if(CMAKE_CONFIGURATION_TYPES)
+  foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
+string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
+set_target_properties(${libname} PROPERTIES
+"ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" 
${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+"LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" 
${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+"RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" 
${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+  endforeach()
+else()
+  set_target_properties(${libname} PROPERTIES
+  ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+  LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+  RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+endif()
+
 set_target_properties(${libname} PROPERTIES
 OUTPUT_NAME ${output_name_${libname}})
 if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED")


Index: cmake/Modules/AddCompilerRT.cmake
===
--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -155,10 +155,27 @@
 set_target_link_flags(${libname} ${extra_linkflags_${libname}})
 set_property(TARGET ${libname} APPEND PROPERTY 
 COMPILE_DEFINITIONS ${LIB_DEFS})
-set_target_properties(${libname} PROPERTIES
-ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
-LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
-RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+
+# For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators
+# append a per-configuration subdirectory to the specified directory.
+# To avoid the appended folder, the configuration specific variable must be
+# set 'RUNTIME_OUTPUT_DIRECTORY_${CONF}':
+# ARCHIVE_OUTPUT_DIRECTORY_DEBUG, ARCHIVE_OUTPUT_DIRECTORY_RELEASE, ...
+if(CMAKE_CONFIGURATION_TYPES)
+  foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
+string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
+set_target_properties(${libname} PROPERTIES
+"ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+"LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+"RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+  endforeach()
+else()
+  set_target_properties(${libname} PROPERTIES
+  ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+  LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+  RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+endif()
+
 set_target_properties(${libname} PROPERTIES
 OUTPUT_NAME ${output_name_

Re: [PATCH] D20261: [compiler-rt] Fix multi-configuration output paths

2016-05-13 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20261#430151, @rnk wrote:

> Will this put the libraries in build/Release/bin/../lib/. aka 
> build/Release/lib, or will they collide between build types?


If I get your question correctly, they won't collide since the first folder 
below build is the configuration (a.k.a Debug/Release).

Before the patch, this is the output directory:

  build/Release/lib/clang/3.9.0/lib/windows/Release

The value in MSVC is:

  C:\src\llvm\build\$(Configuration)\lib\clang\3.9.0\lib\windows\Release\

The last `Release` folder is redundant.

After applying this patch, the MSVC value is:

  C:\src\llvm\build\$(Configuration)\lib\clang\3.9.0\lib\windows\

Library files are produced in this folder:

  build/Release/lib/clang/3.9.0/lib/windows


http://reviews.llvm.org/D20261



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20196: [clang-tidy] Inefficient string operation

2016-05-15 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:35
@@ +34,3 @@
+  
cxxOperatorCallExpr(hasAnyArgument(ignoringImpCasts(declRefExpr(BasicStringType))),
+  hasOverloadedOperatorName("+"));
+

you should swap the  two parameters

```
hasOverloadedOperatorName("+"),
hasAnyArgument(...)
```

matching 'hasOverloadedOperatorName' is less expensive


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:41
@@ +40,3 @@
+  cxxOperatorCallExpr(hasDescendant(BasicStringPlusOperator),
+  
hasAnyArgument(ignoringImpCasts(declRefExpr(BasicStringType))),
+  hasOverloadedOperatorName("+"))

this is not indented correctly.
could you run 
```
  % clang-format -style=file  -i
```


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:47
@@ +46,3 @@
+  const auto AssingOperator = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("="),hasDescendant(BasicStringPlusOperator),
+  allOf(hasArgument(

space after ","


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:54
@@ +53,3 @@
+1, stmt(hasDescendant(declRefExpr(hasDeclaration(decl(
+   equalsBoundNode("lhsStrT" 
/*.bind("rhs-self")*/);
+

You forgot a comment here?


http://reviews.llvm.org/D20196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-15 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:22
@@ +21,3 @@
+static StringRef
+MakeDynamicExceptionString(const SourceManager &SM,
+   const CharSourceRange &FileMoveRange) {

coding style:
MakeDynamicExceptionString -> makeDynamicExceptionString


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:34
@@ +33,3 @@
+
+static CharSourceRange MakeMoveRange(const SourceManager &SM,
+ const LangOptions &LangOps,

MakeMoveRange -> makeMoveRange

(and all other occurrences below)


http://reviews.llvm.org/D18575



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19841: [clang-tidy] Lift common matchers to utils namespace

2016-05-15 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57314.
etienneb marked an inline comment as done.
etienneb added a comment.

rebase over trunk. matchers are lifted to ASTMatchers.


http://reviews.llvm.org/D19841

Files:
  clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/performance/FasterStringFindCheck.cpp
  clang-tidy/readability/ImplicitBoolCastCheck.cpp
  clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tidy/utils/Matchers.h

Index: clang-tidy/utils/Matchers.h
===
--- clang-tidy/utils/Matchers.h
+++ clang-tidy/utils/Matchers.h
@@ -17,6 +17,11 @@
 namespace tidy {
 namespace matchers {
 
+AST_MATCHER_P(Expr, ignoringImplicit,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
+}
+
 AST_MATCHER(BinaryOperator, isRelationalOperator) {
   return Node.isRelationalOp();
 }
Index: clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -8,25 +8,16 @@
 //===--===//
 
 #include "RedundantStringInitCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
 
 namespace clang {
 namespace tidy {
 namespace readability {
 
-namespace {
-
-AST_MATCHER(StringLiteral, lengthIsZero) { return Node.getLength() == 0; }
-
-AST_MATCHER_P(Expr, ignoringImplicit,
-  ast_matchers::internal::Matcher, InnerMatcher) {
-  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
-}
-
-} // namespace
-
 void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
 return;
@@ -45,7 +36,7 @@
   const auto EmptyStringCtorExpr =
   cxxConstructExpr(StringConstructorExpr,
   hasArgument(0, ignoringParenImpCasts(
- stringLiteral(lengthIsZero();
+ stringLiteral(hasSize(0);
 
   const auto EmptyStringCtorExprWithTemporaries =
   expr(ignoringImplicit(
Index: clang-tidy/readability/ImplicitBoolCastCheck.cpp
===
--- clang-tidy/readability/ImplicitBoolCastCheck.cpp
+++ clang-tidy/readability/ImplicitBoolCastCheck.cpp
@@ -20,10 +20,6 @@
 
 namespace {
 
-AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
-  return Node.getCastKind() == Kind;
-}
-
 AST_MATCHER(Stmt, isMacroExpansion) {
   SourceManager &SM = Finder->getASTContext().getSourceManager();
   SourceLocation Loc = Node.getLocStart();
Index: clang-tidy/performance/FasterStringFindCheck.cpp
===
--- clang-tidy/performance/FasterStringFindCheck.cpp
+++ clang-tidy/performance/FasterStringFindCheck.cpp
@@ -38,8 +38,6 @@
   return Result;
 }
 
-AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
-
 AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher,
  hasSubstitutedType) {
   return hasType(qualType(anyOf(substTemplateTypeParmType(),
@@ -65,7 +63,7 @@
 return;
 
   const auto SingleChar =
-  expr(ignoringParenCasts(stringLiteral(lengthIsOne()).bind("literal")));
+  expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
 
   const auto StringFindFunctions =
   anyOf(hasName("find"), hasName("rfind"), hasName("find_first_of"),
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -24,20 +24,6 @@
 
 const char CastSequence[] = "sequence";
 
-/// \brief Matches cast expressions that have a cast kind of CK_NullToPointer
-/// or CK_NullToMemberPointer.
-///
-/// Given
-/// \code
-///   int *p = 0;
-/// \endcode
-/// implicitCastExpr(isNullToPointer()) matches the implicit cast clang adds
-/// around \c 0.
-AST_MATCHER(CastExpr, isNullToPointer) {
-  return Node.getCastKind() == CK_NullToPointer ||
- Node.getCastKind() == CK_NullToMemberPointer;
-}
-
 AST_MATCHER(Type, sugaredNullptrType) {
   const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
   if (const BuiltinType *BT = dyn_cast(DesugaredType))
@@ -52,7 +38,8 @@
 /// can be replaced instead of just the inner-most implicit cast.
 StatementMatcher makeCastSequenceMatcher() {
   StatementMatcher ImplicitCastToNull = implicitCastExpr(
-  isNullToPointer(),
+  anyOf(hasCastKind(CK_NullToPointer),
+hasCastKind(CK_NullToMemberPointer)),
   unless(hasSourceExpression(hasType(sugaredNullptrType();
 
   return castExpr(anyOf(ImplicitCastToNull,

Re: [PATCH] D19841: [clang-tidy] Lift common matchers to utils namespace

2016-05-15 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57316.
etienneb added a comment.

nits: indent


http://reviews.llvm.org/D19841

Files:
  clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/performance/FasterStringFindCheck.cpp
  clang-tidy/readability/ImplicitBoolCastCheck.cpp
  clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tidy/utils/Matchers.h

Index: clang-tidy/utils/Matchers.h
===
--- clang-tidy/utils/Matchers.h
+++ clang-tidy/utils/Matchers.h
@@ -17,6 +17,11 @@
 namespace tidy {
 namespace matchers {
 
+AST_MATCHER_P(Expr, ignoringImplicit,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
+}
+
 AST_MATCHER(BinaryOperator, isRelationalOperator) {
   return Node.isRelationalOp();
 }
Index: clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -8,25 +8,16 @@
 //===--===//
 
 #include "RedundantStringInitCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
 
 namespace clang {
 namespace tidy {
 namespace readability {
 
-namespace {
-
-AST_MATCHER(StringLiteral, lengthIsZero) { return Node.getLength() == 0; }
-
-AST_MATCHER_P(Expr, ignoringImplicit,
-  ast_matchers::internal::Matcher, InnerMatcher) {
-  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
-}
-
-} // namespace
-
 void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
 return;
@@ -45,7 +36,7 @@
   const auto EmptyStringCtorExpr =
   cxxConstructExpr(StringConstructorExpr,
   hasArgument(0, ignoringParenImpCasts(
- stringLiteral(lengthIsZero();
+ stringLiteral(hasSize(0);
 
   const auto EmptyStringCtorExprWithTemporaries =
   expr(ignoringImplicit(
Index: clang-tidy/readability/ImplicitBoolCastCheck.cpp
===
--- clang-tidy/readability/ImplicitBoolCastCheck.cpp
+++ clang-tidy/readability/ImplicitBoolCastCheck.cpp
@@ -20,10 +20,6 @@
 
 namespace {
 
-AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
-  return Node.getCastKind() == Kind;
-}
-
 AST_MATCHER(Stmt, isMacroExpansion) {
   SourceManager &SM = Finder->getASTContext().getSourceManager();
   SourceLocation Loc = Node.getLocStart();
Index: clang-tidy/performance/FasterStringFindCheck.cpp
===
--- clang-tidy/performance/FasterStringFindCheck.cpp
+++ clang-tidy/performance/FasterStringFindCheck.cpp
@@ -38,8 +38,6 @@
   return Result;
 }
 
-AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
-
 AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher,
  hasSubstitutedType) {
   return hasType(qualType(anyOf(substTemplateTypeParmType(),
@@ -65,7 +63,7 @@
 return;
 
   const auto SingleChar =
-  expr(ignoringParenCasts(stringLiteral(lengthIsOne()).bind("literal")));
+  expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
 
   const auto StringFindFunctions =
   anyOf(hasName("find"), hasName("rfind"), hasName("find_first_of"),
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -24,20 +24,6 @@
 
 const char CastSequence[] = "sequence";
 
-/// \brief Matches cast expressions that have a cast kind of CK_NullToPointer
-/// or CK_NullToMemberPointer.
-///
-/// Given
-/// \code
-///   int *p = 0;
-/// \endcode
-/// implicitCastExpr(isNullToPointer()) matches the implicit cast clang adds
-/// around \c 0.
-AST_MATCHER(CastExpr, isNullToPointer) {
-  return Node.getCastKind() == CK_NullToPointer ||
- Node.getCastKind() == CK_NullToMemberPointer;
-}
-
 AST_MATCHER(Type, sugaredNullptrType) {
   const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
   if (const BuiltinType *BT = dyn_cast(DesugaredType))
@@ -52,7 +38,8 @@
 /// can be replaced instead of just the inner-most implicit cast.
 StatementMatcher makeCastSequenceMatcher() {
   StatementMatcher ImplicitCastToNull = implicitCastExpr(
-  isNullToPointer(),
+  anyOf(hasCastKind(CK_NullToPointer),
+hasCastKind(CK_NullToMemberPointer)),
   unless(hasSourceExpression(hasType(sugaredNullptrType();
 
   return castExpr(anyOf(ImplicitCastToNull,
Index: clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
===

[PATCH] D20279: [clang-tidy] Cleanups utils files

2016-05-15 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

Cleanup some code by using appropriate APIs.
Some coding style cleanups.

There is no behavior changes.

http://reviews.llvm.org/D20279

Files:
  clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tidy/utils/HeaderFileExtensionsUtils.cpp
  clang-tidy/utils/HeaderFileExtensionsUtils.h
  clang-tidy/utils/HeaderGuard.cpp
  clang-tidy/utils/IncludeInserter.cpp
  clang-tidy/utils/IncludeInserter.h
  clang-tidy/utils/IncludeSorter.cpp
  clang-tidy/utils/IncludeSorter.h
  clang-tidy/utils/TypeTraits.cpp

Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -77,7 +77,8 @@
 }
 
 // Based on QualType::isTrivial.
-bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
+bool isTriviallyDefaultConstructible(QualType Type,
+ const ASTContext &Context) {
   if (Type.isNull())
 return false;
 
Index: clang-tidy/utils/IncludeSorter.h
===
--- clang-tidy/utils/IncludeSorter.h
+++ clang-tidy/utils/IncludeSorter.h
@@ -15,7 +15,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 
 // Class used by IncludeSorterCallback and IncludeInserterCallback to record the
 // names of the inclusions in a given source file being processed and generate
@@ -66,10 +66,6 @@
 private:
   typedef SmallVector SourceRangeVector;
 
-  // Creates a fix-it for the given replacements.
-  // Takes the the source location that will be replaced, and the new text.
-  FixItHint CreateFixIt(SourceRange EditRange, const std::string &NewText);
-
   const SourceManager *SourceMgr;
   const LangOptions *LangOpts;
   const IncludeStyle Style;
Index: clang-tidy/utils/IncludeSorter.cpp
===
--- clang-tidy/utils/IncludeSorter.cpp
+++ clang-tidy/utils/IncludeSorter.cpp
@@ -12,7 +12,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 
 namespace {
 
@@ -254,7 +254,8 @@
   // Otherwise report the current block edit and start a new block.
 } else {
   if (CurrentEndLine) {
-Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
+Fixes.push_back(
+FixItHint::CreateReplacement(CurrentRange, CurrentText));
   }
 
   CurrentEndLine = LineEdit.first;
@@ -264,25 +265,15 @@
   }
   // Finally, report the current block edit if there is one.
   if (CurrentEndLine) {
-Fixes.push_back(CreateFixIt(CurrentRange, CurrentText));
+Fixes.push_back(FixItHint::CreateReplacement(CurrentRange, CurrentText));
   }
 
   // Reset the remaining internal state.
   SourceLocations.clear();
   IncludeLocations.clear();
   return Fixes;
 }
 
-// Creates a fix-it for the given replacements.
-// Takes the the source location that will be replaced, and the new text.
-FixItHint IncludeSorter::CreateFixIt(SourceRange EditRange,
- const std::string &NewText) {
-  FixItHint Fix;
-  Fix.RemoveRange = CharSourceRange::getCharRange(EditRange);
-  Fix.CodeToInsert = NewText;
-  return Fix;
-}
-
 IncludeSorter::IncludeStyle
 IncludeSorter::parseIncludeStyle(const std::string &Value) {
   return Value == "llvm" ? IS_LLVM : IS_Google;
Index: clang-tidy/utils/IncludeInserter.h
===
--- clang-tidy/utils/IncludeInserter.h
+++ clang-tidy/utils/IncludeInserter.h
@@ -60,8 +60,8 @@
   CreateIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
 
 private:
-  void AddInclude(StringRef file_name, bool IsAngled,
-  SourceLocation hash_location, SourceLocation end_location);
+  void AddInclude(StringRef FileName, bool IsAngled,
+  SourceLocation HashLocation, SourceLocation EndLocation);
 
   llvm::DenseMap> IncludeSorterByFile;
   llvm::DenseMap> InsertedHeaders;
Index: clang-tidy/utils/IncludeInserter.cpp
===
--- clang-tidy/utils/IncludeInserter.cpp
+++ clang-tidy/utils/IncludeInserter.cpp
@@ -67,18 +67,18 @@
   return IncludeSorterByFile[FileID]->CreateIncludeInsertion(Header, IsAngled);
 }
 
-void IncludeInserter::AddInclude(StringRef file_name, bool IsAngled,
+void IncludeInserter::AddInclude(StringRef FileName, bool IsAngled,
  SourceLocation HashLocation,
- SourceLocation end_location) {
+ SourceLocation EndLocation) {
   FileID FileID = SourceMgr.getFileID(HashLocation);
   if (IncludeSorterByFile.find(FileID) == IncludeSorterByFile.end()) {
 IncludeSorterByFile.insert(std::make_pair(
 FileID, llvm::make_unique(
 &SourceMgr, &LangOpts, File

[clang-tools-extra] r269656 - [clang-tidy] Cleanups utils files

2016-05-16 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Mon May 16 09:34:20 2016
New Revision: 269656

URL: http://llvm.org/viewvc/llvm-project?rev=269656&view=rev
Log:
[clang-tidy] Cleanups utils files

Summary:
Cleanup some code by using appropriate APIs.
Some coding style cleanups.

There is no behavior changes.

 - Function `IncludeSorter::CreateFixIt` can be replaced by 
`FixItHint::CreateReplacement`.
 - Function `cleanPath` is a wrapper for `llvm::sys::path::remove_dots`.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20279

Modified:
clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h
clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.cpp
clang-tools-extra/trunk/clang-tidy/utils/IncludeSorter.h
clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp

Modified: clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp?rev=269656&r1=269655&r2=269656&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/DeclRefExprUtils.cpp Mon May 16 
09:34:20 2016
@@ -15,7 +15,7 @@
 
 namespace clang {
 namespace tidy {
-namespace utils {  
+namespace utils {
 namespace decl_ref_expr {
 
 using namespace ::clang::ast_matchers;

Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp?rev=269656&r1=269655&r2=269656&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp Mon 
May 16 09:34:20 2016
@@ -9,6 +9,7 @@
 
 #include "HeaderFileExtensionsUtils.h"
 #include "clang/Basic/CharInfo.h"
+#include "llvm/Support/Path.h"
 
 namespace clang {
 namespace tidy {

Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h?rev=269656&r1=269655&r2=269656&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h Mon 
May 16 09:34:20 2016
@@ -10,13 +10,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADER_FILE_EXTENSIONS_UTILS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADER_FILE_EXTENSIONS_UTILS_H
 
-#include 
-
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/SmallSet.h"
-#include "llvm/Support/Path.h"
 
 namespace clang {
 namespace tidy {

Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp?rev=269656&r1=269655&r2=269656&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp Mon May 16 
09:34:20 2016
@@ -19,29 +19,16 @@ namespace tidy {
 namespace utils {
 
 /// \brief canonicalize a path by removing ./ and ../ components.
-// FIXME: Consider moving this to llvm::sys::path.
 static std::string cleanPath(StringRef Path) {
-  SmallString<256> NewPath;
-  for (auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
-   I != E; ++I) {
-if (*I == ".")
-  continue;
-if (*I == "..") {
-  // Drop the last component.
-  NewPath.resize(llvm::sys::path::parent_path(NewPath).size());
-} else {
-  if (!NewPath.empty() && !NewPath.endswith("/"))
-NewPath += '/';
-  NewPath += *I;
-}
-  }
-  return NewPath.str();
+  SmallString<256> Result =  Path;
+  llvm::sys::path::remove_dots(Result, true);
+  return Result.str();
 }
 
 namespace {
 class HeaderGuardPPCallbacks : public PPCallbacks {
 public:
-  explicit HeaderGuardPPCallbacks(Preprocessor *PP, HeaderGuardCheck *Check)
+  HeaderGuardPPCallbacks(Preprocessor *PP, HeaderGuardCheck *Check)
   : PP(PP), Check(Check) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,

Modified: clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
URL: 
http://llvm.o

[clang-tools-extra] r269804 - [clang-tidy] Lift common matchers to utils namespace

2016-05-17 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Tue May 17 14:36:09 2016
New Revision: 269804

URL: http://llvm.org/viewvc/llvm-project?rev=269804&view=rev
Log:
[clang-tidy] Lift common matchers to utils namespace

Summary:
This patch is lifting matchers used by more than one checkers
to the common namespace.

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D19841

Modified:

clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/Matchers.h

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp?rev=269804&r1=269803&r2=269804&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
Tue May 17 14:36:09 2016
@@ -15,14 +15,6 @@ namespace clang {
 namespace tidy {
 namespace misc {
 
-namespace {
-
-AST_MATCHER(CastExpr, isPointerToBoolean) {
-  return Node.getCastKind() == CK_PointerToBoolean;
-}
-
-} // namespace
-
 void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *Finder) 
{
   // Look for ifs that have an implicit bool* to bool conversion in the
   // condition. Filter negations.
@@ -32,7 +24,7 @@ void BoolPointerImplicitConversionCheck:
hasSourceExpression(expr(
hasType(pointerType(pointee(booleanType(,
ignoringParenImpCasts(declRefExpr().bind("expr",
-   isPointerToBoolean(),
+   hasCastKind(CK_PointerToBoolean),
  unless(isInTemplateInstantiation())).bind("if"),
   this);
 }

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=269804&r1=269803&r2=269804&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Tue May 17 
14:36:09 2016
@@ -24,20 +24,6 @@ namespace {
 
 const char CastSequence[] = "sequence";
 
-/// \brief Matches cast expressions that have a cast kind of CK_NullToPointer
-/// or CK_NullToMemberPointer.
-///
-/// Given
-/// \code
-///   int *p = 0;
-/// \endcode
-/// implicitCastExpr(isNullToPointer()) matches the implicit cast clang adds
-/// around \c 0.
-AST_MATCHER(CastExpr, isNullToPointer) {
-  return Node.getCastKind() == CK_NullToPointer ||
- Node.getCastKind() == CK_NullToMemberPointer;
-}
-
 AST_MATCHER(Type, sugaredNullptrType) {
   const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
   if (const BuiltinType *BT = dyn_cast(DesugaredType))
@@ -52,7 +38,8 @@ AST_MATCHER(Type, sugaredNullptrType) {
 /// can be replaced instead of just the inner-most implicit cast.
 StatementMatcher makeCastSequenceMatcher() {
   StatementMatcher ImplicitCastToNull = implicitCastExpr(
-  isNullToPointer(),
+  anyOf(hasCastKind(CK_NullToPointer),
+hasCastKind(CK_NullToMemberPointer)),
   unless(hasSourceExpression(hasType(sugaredNullptrType();
 
   return castExpr(anyOf(ImplicitCastToNull,

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp?rev=269804&r1=269803&r2=269804&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp 
Tue May 17 14:36:09 2016
@@ -38,8 +38,6 @@ llvm::Optional MakeCharacte
   return Result;
 }
 
-AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
-
 AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher,
  hasSubstitutedType) {
   return hasType(qualType(anyOf(substTemplateTypeParmType(),
@@ -65,7 +63,7 @@ void FasterStringFindCheck::registerMatc
 return;
 
   const auto SingleChar =
-  expr(ignoringParenCasts(stringLiteral(lengthIsOne()).bind("literal")));
+  expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
 
   const auto StringFindFunctions =
   anyOf(h

Re: [PATCH] D20347: Add support to clang-cl driver for /GS switch

2016-05-25 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 58502.
etienneb marked an inline comment as done.
etienneb added a comment.

more tests


http://reviews.llvm.org/D20347

Files:
  include/clang/Driver/CLCompatOptions.td
  lib/Driver/Tools.cpp
  test/Driver/cl-fallback.c
  test/Driver/cl-options.c

Index: test/Driver/cl-options.c
===
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -59,6 +59,16 @@
 // RUN: %clang_cl /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR_ %s
 // GR_: -fno-rtti
 
+// Security Buffer Check is on by default.
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=GS-default %s
+// GS-default: "-stack-protector" "2"
+
+// RUN: %clang_cl /GS -### -- %s 2>&1 | FileCheck -check-prefix=GS %s
+// GS: "-stack-protector" "2"
+
+// RUN: %clang_cl /GS- -### -- %s 2>&1 | FileCheck -check-prefix=GS_ %s
+// GS_-NOT: -stack-protector
+
 // RUN: %clang_cl /Gy -### -- %s 2>&1 | FileCheck -check-prefix=Gy %s
 // Gy: -ffunction-sections
 
Index: test/Driver/cl-fallback.c
===
--- test/Driver/cl-fallback.c
+++ test/Driver/cl-fallback.c
@@ -1,7 +1,7 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
-// RUN: %clang_cl --target=i686-pc-win32 /fallback /Dfoo=bar /Ubaz /Ifoo /O0 /Ox /GR /GR- /Gy /Gy- \
+// RUN: %clang_cl --target=i686-pc-win32 /fallback /Dfoo=bar /Ubaz /Ifoo /O0 /Ox /GR /GR- /GS /GS- /Gy /Gy- \
 // RUN:   /Gw /Gw- /LD /LDd /EHs /EHs- /Zl /MD /MDd /MTd /MT /FImyheader.h /Zi \
 // RUN:   -garbage -moregarbage \
 // RUN:   -### -- %s 2>&1 \
@@ -22,6 +22,7 @@
 // CHECK: "/Oy"
 // CHECK: "/GF"
 // CHECK: "/GR-"
+// CHECK: "/GS-"
 // CHECK: "/Gy-"
 // CHECK: "/Gw-"
 // CHECK: "/Z7"
@@ -41,6 +42,10 @@
 // GR: cl.exe
 // GR: "/GR-"
 
+// RUN: %clang_cl /fallback /GS- -### -- %s 2>&1 | FileCheck -check-prefix=GS %s
+// GS: cl.exe
+// GS: "/GS-"
+
 // RUN: %clang_cl /fallback /Od -### -- %s 2>&1 | FileCheck -check-prefix=O0 %s
 // O0: cl.exe
 // O0: "/Od"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6146,6 +6146,14 @@
/*default=*/false))
 CmdArgs.push_back("-fno-rtti-data");
 
+  // This controls whether or not we emit stack-protector instrumentation.
+  // In MSVC, Buffer Security Check (/GS) is on by default.
+  if (Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
+   /*default=*/true)) {
+CmdArgs.push_back("-stack-protector");
+CmdArgs.push_back(Args.MakeArgString(Twine(LangOptions::SSPStrong)));
+  }
+
   // Emit CodeView if -Z7 is present.
   *EmitCodeView = Args.hasArg(options::OPT__SLASH_Z7);
   if (*EmitCodeView)
@@ -9976,6 +9984,11 @@
   if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
/*default=*/false))
 CmdArgs.push_back("/GR-");
+
+  if (Args.hasFlag(options::OPT__SLASH_GS_, options::OPT__SLASH_GS,
+   /*default=*/false))
+CmdArgs.push_back("/GS-");
+
   if (Arg *A = Args.getLastArg(options::OPT_ffunction_sections,
options::OPT_fno_function_sections))
 CmdArgs.push_back(A->getOption().getID() == options::OPT_ffunction_sections
Index: include/clang/Driver/CLCompatOptions.td
===
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -77,6 +77,8 @@
 def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable emission of RTTI data">;
 def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">,
   Alias;
+def _SLASH_GS : CLFlag<"GS">, HelpText<"Enable buffer security check">;
+def _SLASH_GS_ : CLFlag<"GS-">, HelpText<"Disable buffer security check">;
 def _SLASH_Gs : CLJoined<"Gs">, HelpText<"Set stack probe size">,
   Alias;
 def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">,
@@ -287,7 +289,6 @@
 def _SLASH_FC : CLIgnoredFlag<"FC">;
 def _SLASH_FS : CLIgnoredFlag<"FS">, HelpText<"Force synchronous PDB writes">;
 def _SLASH_GF : CLIgnoredFlag<"GF">;
-def _SLASH_GS_ : CLIgnoredFlag<"GS-">;
 def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">;
 def _SLASH_nologo : CLIgnoredFlag<"nologo">;
 def _SLASH_Ob1 : CLIgnoredFlag<"Ob1">;
@@ -329,7 +330,6 @@
 def _SLASH_GL_ : CLFlag<"GL-">;
 def _SLASH_Gm : CLFlag<"Gm">;
 def _SLASH_Gm_ : CLFlag<"Gm-">;
-def _SLASH_GS : CLFlag<"GS">;
 def _SLASH_GT : CLFlag<"GT">;
 def _SLASH_Guard : CLJoined<"guard:">;
 def _SLASH_GZ : CLFlag<"GZ">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20347: Add support to clang-cl driver for /GS switch

2016-05-25 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

This patch needs land after http://reviews.llvm.org/D20346.
thx for the review.


http://reviews.llvm.org/D20347



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20766: [clang-tidy] Fix script adding new clang-tidy check

2016-05-27 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

The `getName()` call is useless. It's better to show a better example
as tutorial.

http://reviews.llvm.org/D20766

Files:
  clang-tidy/add_new_check.py

Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -138,7 +138,7 @@
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
-  << MatchedDecl->getName()
+  << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -138,7 +138,7 @@
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
-  << MatchedDecl->getName()
+  << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20767: [ASTMatchers] Add support of hasCondition for SwitchStmt.

2016-05-27 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added reviewers: aaron.ballman, sbenza.
etienneb added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The switch statement could be added to the hasCondition matcher.

Example:
```
clang-query> match switchStmt(hasCondition(ignoringImpCasts(declRefExpr(
```

Output:
```
Match #1:

Binding for "root":
SwitchStmt 0x2f9b528 
|-<<>>
|-ImplicitCastExpr 0x2f9b510  'int' 
| `-ImplicitCastExpr 0x2f9b4f8  'enum Color' 
|   `-DeclRefExpr 0x2f9b4d0  'enum Color' lvalue Var 0x2f9a118 'C' 
'enum Color'
`-CompoundStmt 0x2f9b610 
  |-CaseStmt 0x2f9b578 
  | |-ImplicitCastExpr 0x2f9b638  'int' 
  | | `-DeclRefExpr 0x2f9b550  'enum Size' EnumConstant 0x2f99e40 
'Small' 'enum Size'
  | |-<<>>
  | `-ReturnStmt 0x2f9b5d0 
  |   `-IntegerLiteral 0x2f9b5b0  'int' 1
  `-DefaultStmt 0x2f9b5f0 
`-BreakStmt 0x2f9b5e8 

1 match.
```

http://reviews.llvm.org/D20767

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -958,6 +958,28 @@
   callee(cxxMethodDecl(hasName("x";
 }
 
+TEST(Matcher, HasCondition) {
+  StatementMatcher IfStmt =
+ifStmt(hasCondition(cxxBoolLiteral(equals(true;
+  EXPECT_TRUE(matches("void x() { if (true) {} }", IfStmt));
+  EXPECT_TRUE(notMatches("void x() { if (false) {} }", IfStmt));
+
+  StatementMatcher ForStmt =
+forStmt(hasCondition(cxxBoolLiteral(equals(true;
+  EXPECT_TRUE(matches("void x() { for (;true;) {} }", ForStmt));
+  EXPECT_TRUE(notMatches("void x() { for (;false;) {} }", ForStmt));
+
+  StatementMatcher WhileStmt =
+whileStmt(hasCondition(cxxBoolLiteral(equals(true;
+  EXPECT_TRUE(matches("void x() { while (true) {} }", WhileStmt));
+  EXPECT_TRUE(notMatches("void x() { while (false) {} }", WhileStmt));
+
+  StatementMatcher SwitchStmt =
+switchStmt(hasCondition(integerLiteral(equals(42;
+  EXPECT_TRUE(matches("void x() { switch (42) {case 42:;} }", SwitchStmt));
+  EXPECT_TRUE(notMatches("void x() { switch (43) {case 43:;} }", SwitchStmt));
+}
+
 TEST(For, ForLoopInternals) {
   EXPECT_TRUE(matches("void f(){ int i; for (; i < 3 ; ); }",
   forStmt(hasCondition(anything();
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3299,16 +3299,16 @@
 }
 
 /// \brief Matches the condition expression of an if statement, for loop,
-/// or conditional operator.
+/// switch statement or conditional operator.
 ///
 /// Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
 /// \code
 ///   if (true) {}
 /// \endcode
 AST_POLYMORPHIC_MATCHER_P(
 hasCondition,
 AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, ForStmt, WhileStmt, DoStmt,
-AbstractConditionalOperator),
+SwitchStmt, AbstractConditionalOperator),
 internal::Matcher, InnerMatcher) {
   const Expr *const Condition = Node.getCond();
   return (Condition != nullptr &&
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3536,9 +3536,9 @@
 
 
 
-MatcherAbstractConditionalOperator>hasConditionMatcherExpr> InnerMatcher
-Matches the condition expression of an if statement, for loop,
-or conditional operator.
+MatcherAbstractConditionalOperator>hasConditionMatcherExpr> InnerMatcher
+Matches the condition expression of an if statement, for loop,
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -4293,7 +4293,7 @@
 
 MatcherDoStmt>hasConditionMatcherExpr> InnerMatcher
 Matches the condition expression of an if statement, for loop,
-or conditional operator.
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -4476,7 +4476,7 @@
 
 MatcherForStmt>hasConditionMatcherExpr> InnerMatcher
 Matches the condition expression of an if statement, for loop,
-or co

[PATCH] D20773: [Sema] Fix incorrect enum token namespace

2016-05-28 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: rsmith.
etienneb added a subscriber: cfe-commits.

This patch fix the scoping of enum literal. They were not resolving
to the right type.

It was not causing any problem as one is a copy of the other one.

The literal in the switch are resolving to Sema.h:5527
```
  enum AccessResult {
AR_accessible,
AR_inaccessible,
AR_dependent,
AR_delayed
  };
```

Instead of SemaAccess.cpp:27
```
/// A copy of Sema's enum without AR_delayed.
enum AccessResult {
  AR_accessible,
  AR_inaccessible,
  AR_dependent
};
```

This issue was found by a new clang-tidy check (still on-going).

http://reviews.llvm.org/D20773

Files:
  lib/Sema/SemaAccess.cpp

Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1766,9 +1766,9 @@
   // while the ParsingDeclarator is active.
   EffectiveContext EC(CurContext);
   switch (CheckEffectiveAccess(*this, EC, target->getLocation(), entity)) {
-  case AR_accessible: return Sema::AR_accessible;
-  case AR_inaccessible: return Sema::AR_inaccessible;
-  case AR_dependent: return Sema::AR_dependent;
+  case ::AR_accessible: return Sema::AR_accessible;
+  case ::AR_inaccessible: return Sema::AR_inaccessible;
+  case ::AR_dependent: return Sema::AR_dependent;
   }
   llvm_unreachable("invalid access result");
 }


Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1766,9 +1766,9 @@
   // while the ParsingDeclarator is active.
   EffectiveContext EC(CurContext);
   switch (CheckEffectiveAccess(*this, EC, target->getLocation(), entity)) {
-  case AR_accessible: return Sema::AR_accessible;
-  case AR_inaccessible: return Sema::AR_inaccessible;
-  case AR_dependent: return Sema::AR_dependent;
+  case ::AR_accessible: return Sema::AR_accessible;
+  case ::AR_inaccessible: return Sema::AR_inaccessible;
+  case ::AR_dependent: return Sema::AR_dependent;
   }
   llvm_unreachable("invalid access result");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r271207 - [clang-tidy] Fix script adding new clang-tidy check

2016-05-30 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Mon May 30 10:05:10 2016
New Revision: 271207

URL: http://llvm.org/viewvc/llvm-project?rev=271207&view=rev
Log:
[clang-tidy] Fix script adding new clang-tidy check

Summary:
The `getName()` call is useless. It's better to show a better example
as tutorial.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20766

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=271207&r1=271206&r2=271207&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Mon May 30 10:05:10 2016
@@ -138,7 +138,7 @@ void %(check_name)s::check(const MatchFi
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
-  << MatchedDecl->getName()
+  << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20766: [clang-tidy] Fix script adding new clang-tidy check

2016-05-30 Thread Etienne Bergeron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL271207: [clang-tidy] Fix script adding new clang-tidy check 
(authored by etienneb).

Changed prior to commit:
  http://reviews.llvm.org/D20766?vs=58878&id=58958#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20766

Files:
  clang-tools-extra/trunk/clang-tidy/add_new_check.py

Index: clang-tools-extra/trunk/clang-tidy/add_new_check.py
===
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py
@@ -138,7 +138,7 @@
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
-  << MatchedDecl->getName()
+  << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 


Index: clang-tools-extra/trunk/clang-tidy/add_new_check.py
===
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py
@@ -138,7 +138,7 @@
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
-  << MatchedDecl->getName()
+  << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r271208 - [ASTMatchers] Add support of hasCondition for SwitchStmt.

2016-05-30 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Mon May 30 10:25:25 2016
New Revision: 271208

URL: http://llvm.org/viewvc/llvm-project?rev=271208&view=rev
Log:
[ASTMatchers] Add support of hasCondition for SwitchStmt.

Summary:
The switch statement could be added to the hasCondition matcher.

Example:
```
clang-query> match switchStmt(hasCondition(ignoringImpCasts(declRefExpr(
```

Output:
```
Match #1:

Binding for "root":
SwitchStmt 0x2f9b528 
|-<<>>
|-ImplicitCastExpr 0x2f9b510  'int' 
| `-ImplicitCastExpr 0x2f9b4f8  'enum Color' 
|   `-DeclRefExpr 0x2f9b4d0  'enum Color' lvalue Var 0x2f9a118 'C' 
'enum Color'
`-CompoundStmt 0x2f9b610 
  |-CaseStmt 0x2f9b578 
  | |-ImplicitCastExpr 0x2f9b638  'int' 
  | | `-DeclRefExpr 0x2f9b550  'enum Size' EnumConstant 0x2f99e40 
'Small' 'enum Size'
  | |-<<>>
  | `-ReturnStmt 0x2f9b5d0 
  |   `-IntegerLiteral 0x2f9b5b0  'int' 1
  `-DefaultStmt 0x2f9b5f0 
`-BreakStmt 0x2f9b5e8 

1 match.
```

Reviewers: aaron.ballman, sbenza, klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D20767

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=271208&r1=271207&r2=271208&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Mon May 30 10:25:25 2016
@@ -3536,9 +3536,9 @@ Usable as: Any Matcher
 
 
 
-MatcherAbstractConditionalOperator>hasConditionMatcherExpr> 
InnerMatcher
-Matches the condition 
expression of an if statement, for loop,
-or conditional operator.
+MatcherAbstractConditionalOperator>hasConditionMatcherExpr> 
InnerMatcher
+Matches the condition 
expression of an if statement, for loop,
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -4293,7 +4293,7 @@ with compoundStmt()
 
 MatcherDoStmt>hasConditionMatcherExpr> 
InnerMatcher
 Matches the condition 
expression of an if statement, for loop,
-or conditional operator.
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -4476,7 +4476,7 @@ with compoundStmt()
 
 MatcherForStmt>hasConditionMatcherExpr> 
InnerMatcher
 Matches the condition 
expression of an if statement, for loop,
-or conditional operator.
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -4554,7 +4554,7 @@ cxxMethodDecl(returns(asString("int")))
 
 MatcherIfStmt>hasConditionMatcherExpr> 
InnerMatcher
 Matches the condition 
expression of an if statement, for loop,
-or conditional operator.
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}
@@ -5052,6 +5052,15 @@ switchStmt(forEachSwitchCase(caseStmt().
 
 
 
+MatcherSwitchStmt>hasConditionMatcherExpr> 
InnerMatcher
+Matches the condition 
expression of an if statement, for loop,
+switch statement or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
+  if (true) {}
+
+
+
 MatcherTagType>hasDeclarationMatcherDecl>  
InnerMatcher
 Matches a node if 
the declaration associated with that node
 matches the given matcher.
@@ -5385,7 +5394,7 @@ with compoundStmt()
 
 MatcherWhileStmt>hasConditionMatcherExpr> 
InnerMatcher
 Matches the condition 
expression of an if statement, for loop,
-or conditional operator.
+switch statement or conditional operator.
 
 Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true
   if (true) {}

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm

[PATCH] D20792: [clang-tidy] Remove redundant quote in add_new_check script

2016-05-30 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: bkramer.
etienneb added a subscriber: cfe-commits.

Remove redundant quote.
These quotes were added here: http://reviews.llvm.org/D20766

http://reviews.llvm.org/D20792

Files:
  clang-tidy/add_new_check.py
  clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -41,11 +41,11 @@
   if (const auto *Using = Result.Nodes.getNodeAs("using")) {
 // Ignores using-declarations defined in macros.
 if (Using->getLocation().isMacroID())
-  return ;
+  return;
 
 // Ignores using-declarations defined in class definition.
 if (isa(Using->getDeclContext()))
-  return ;
+  return;
 
 UsingDeclContext Context(Using);
 Context.UsingDeclRange = CharSourceRange::getCharRange(
Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -137,7 +137,7 @@
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
-  diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
+  diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }


Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -41,11 +41,11 @@
   if (const auto *Using = Result.Nodes.getNodeAs("using")) {
 // Ignores using-declarations defined in macros.
 if (Using->getLocation().isMacroID())
-  return ;
+  return;
 
 // Ignores using-declarations defined in class definition.
 if (isa(Using->getDeclContext()))
-  return ;
+  return;
 
 UsingDeclContext Context(Using);
 Context.UsingDeclRange = CharSourceRange::getCharRange(
Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -137,7 +137,7 @@
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
-  diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
+  diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20792: [clang-tidy] Remove redundant quote in add_new_check script

2016-05-30 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 58969.
etienneb added a comment.

nits


http://reviews.llvm.org/D20792

Files:
  clang-tidy/add_new_check.py

Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -137,7 +137,7 @@
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
-  diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
+  diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -137,7 +137,7 @@
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
-  diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
+  diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r271210 - [clang-tidy] Remove redundant quote in add_new_check script

2016-05-30 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Mon May 30 10:42:08 2016
New Revision: 271210

URL: http://llvm.org/viewvc/llvm-project?rev=271210&view=rev
Log:
[clang-tidy] Remove redundant quote in add_new_check script

Summary:
Remove redundant quote.
These quotes were added here: http://reviews.llvm.org/D20766

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20792

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=271210&r1=271209&r2=271210&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Mon May 30 10:42:08 2016
@@ -137,7 +137,7 @@ void %(check_name)s::check(const MatchFi
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
   if (MatchedDecl->getName().startswith("awesome_"))
 return;
-  diag(MatchedDecl->getLocation(), "function '%%0' is insufficiently awesome")
+  diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20714: [Clang-tidy] Fix some Include What You Use warnings; other minor fixes

2016-05-30 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

drive-by



Comment at: clang-tidy/ClangTidy.cpp:24
@@ -24,2 +23,3 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"

This one is for sure included by 'clang/Basic/Diagnostic.h'.


Comment at: clang-tidy/ClangTidy.h:17
@@ -16,4 +16,3 @@
 #include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Tooling/Refactoring.h"
-#include "llvm/ADT/StringExtras.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/LangOptions.h"

This one is for sure included by 'clang/Basic/Diagnostic.h'.


Comment at: clang-tidy/ClangTidyDiagnosticConsumer.h:17
@@ -14,1 +16,3 @@
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/LangOptions.h"

This one is for sure included by 'clang/Basic/Diagnostic.h'.


Comment at: clang-tidy/ClangTidyModule.h:13
@@ -12,3 +12,3 @@
 
 #include "ClangTidy.h"
 #include "llvm/ADT/StringRef.h"

There is an issue with includes ordering here and/or line 20.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:15
@@ -14,1 +14,3 @@
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"

There is always the tradeoff between including separate files, or including 
AST.h

I'm not sure I prefer expanding them.
alexfh? toughs?


Comment at: clang-tidy/utils/OptionsUtils.cpp:1
@@ -1,2 +1,2 @@
 //===--- DanglingHandleCheck.cpp - 
clang-tidy--===//
 //

Could you fix this 'DanglingHandleCheck.cpp' -> 'OptionsUtils.cpp'



Repository:
  rL LLVM

http://reviews.llvm.org/D20714



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20714: [Clang-tidy] Fix some Include What You Use warnings; other minor fixes

2016-05-31 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20714#444802, @Eugene.Zelenko wrote:

> Point of Include What You Use suggestions to rely on explicit dependencies, 
> not implicit ones.


It's true most of the time.
In some case,  splitting the header file is for maintainability and including 
the root is still the right coding-style to use.

I can't tell about what clang/llvm community will prefer. Both approaches make 
sense and it's matter of choice.

As an example, look to "ast.h"... there is no needs at all for the existence of 
that file if you only rely on your current rules.

  14 #ifndef LLVM_CLANG_AST_AST_H
  15 #define LLVM_CLANG_AST_AST_H
  16 
  17 // This header exports all AST interfaces.
  18 #include "clang/AST/ASTContext.h"
  19 #include "clang/AST/Decl.h"
  20 #include "clang/AST/DeclCXX.h"
  21 #include "clang/AST/DeclObjC.h"
  22 #include "clang/AST/DeclTemplate.h"
  23 #include "clang/AST/Expr.h"
  24 #include "clang/AST/ExprObjC.h"
  25 #include "clang/AST/StmtVisitor.h"
  26 #include "clang/AST/Type.h"
  27 
  28 #endif

On my side, having the include statement for every AST file is over-kill.


Repository:
  rL LLVM

http://reviews.llvm.org/D20714



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20714: [Clang-tidy] Fix some Include What You Use warnings; other minor fixes

2016-06-01 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20714#445911, @Eugene.Zelenko wrote:

> There is a way to tell IWYU about compound headers with pragmas 
> .
>  I also suggested to make this possible via file with compound headers list.
>
> But person who knows LLVM/Clang code base better then me should define such 
> headers.


I spent time thinking about that problem months ago and I've found so many 
strange cases.
It seems an easy problem on the surface, but when you dig you realized there is 
so many corner cases.

My comment on this patch is not related to the tool or how the tool is working.
It's more a question about whether or not we should "compound" some headers you 
expanded.
Most of the include you added are right and must be present.

A general question on your tool is: can we specify the IWYU pragma somewhere 
else than in the code.
I'm not in favor of building xmas tree with your header files.

  IWYU pragma:

I don't know how common they will be.


Repository:
  rL LLVM

http://reviews.llvm.org/D20714



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.

2016-06-01 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

I wonder if these two checks should not be merge in one checker.

  modernize-explicit-conversion-operator



Comment at: clang-tidy/modernize/ExplicitOperatorBoolCheck.cpp:21
@@ +20,3 @@
+void ExplicitOperatorBoolCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  // FIXME: Use some kind of isConversionToType("bool") here,

As you state later "available since C++11",
you should check for the current language.

Example from other checkers:
```
  if (!getLangOpts().CPlusPlus)
return;
```



Comment at: clang-tidy/modernize/ExplicitOperatorBoolCheck.cpp:36
@@ +35,3 @@
+  // Or can we at least use a constant here?
+  if (CanonicalType.getAsString() != "_Bool") {
+return;

This check should be part of the matcher above.
see:booleanType

```
Matches type bool.

Given
 struct S { bool func(); };
functionDecl(returns(booleanType()))
  matches "bool func();"
```


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:30
@@ +29,3 @@
+void OperatorVoidPointerCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto MatchedDecl =
+  Result.Nodes.getNodeAs("operator-void-pointer");

nit: const auto *MatchedDecl
and below...


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:37
@@ +36,3 @@
+  // Or can we at least use a constant here?
+  if (CanonicalType.getAsString() != "const void *") {
+return;

nit: no { }


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:37
@@ +36,3 @@
+  // Or can we at least use a constant here?
+  if (CanonicalType.getAsString() != "const void *") {
+return;

etienneb wrote:
> nit: no { }
should be part of the matcher.


Comment at: docs/clang-tidy/checks/list.rst:7
@@ -6,3 +6,2 @@
 .. toctree::
-
boost-use-to-string

why removing this line?


Comment at: docs/clang-tidy/checks/modernize-explicit-operator-bool.rst:11
@@ +10,3 @@
+be compared accidentally. For instance, even when objects a and b have no
+operator = overloads, an implicit operator bool would allow `a == b` to compile
+because both a and b can be implictly converted to bool.

operator =  --> operator ==  ???


Repository:
  rL LLVM

http://reviews.llvm.org/D20857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r271431 - [Sema] Fix incorrect enum token namespace

2016-06-01 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed Jun  1 16:17:32 2016
New Revision: 271431

URL: http://llvm.org/viewvc/llvm-project?rev=271431&view=rev
Log:
[Sema] Fix incorrect enum token namespace

Summary:
This patch fix the scoping of enum literal. They were not resolving
to the right type.

It was not causing any problem as one is a copy of the other one.

The literal in the switch are resolving to Sema.h:5527
```
  enum AccessResult {
AR_accessible,
AR_inaccessible,
AR_dependent,
AR_delayed
  };
```

Instead of SemaAccess.cpp:27
```
/// A copy of Sema's enum without AR_delayed.
enum AccessResult {
  AR_accessible,
  AR_inaccessible,
  AR_dependent
};
```

This issue was found by a new clang-tidy check (still on-going).

Reviewers: rsmith, aaron.ballman

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20773

Modified:
cfe/trunk/lib/Sema/SemaAccess.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=271431&r1=271430&r2=271431&view=diff
==
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Wed Jun  1 16:17:32 2016
@@ -1766,9 +1766,9 @@ Sema::AccessResult Sema::CheckFriendAcce
   // while the ParsingDeclarator is active.
   EffectiveContext EC(CurContext);
   switch (CheckEffectiveAccess(*this, EC, target->getLocation(), entity)) {
-  case AR_accessible: return Sema::AR_accessible;
-  case AR_inaccessible: return Sema::AR_inaccessible;
-  case AR_dependent: return Sema::AR_dependent;
+  case ::AR_accessible: return Sema::AR_accessible;
+  case ::AR_inaccessible: return Sema::AR_inaccessible;
+  case ::AR_dependent: return Sema::AR_dependent;
   }
   llvm_unreachable("invalid access result");
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.

2016-06-02 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20857#446654, @murrayc wrote:

> In http://reviews.llvm.org/D20857#446101, @etienneb wrote:
>
> > I wonder if these two checks should not be merge in one checker.
>
>
> Personally I find it cleaner to keep them separate, but I would be happy to 
> combine them if that's wanted. I guessed that it would be easier to accept 
> the explicit bool check than the operator void pointer check, and didn't want 
> to make acceptance harder. I can also imagine someone wanting to disable one 
> but not the other.


Enabling/disabling can be done with options (see SizeofExpressionCheck).

  WarnOnSizeOfConstant(Options.get("WarnOnSizeOfConstant", 1) != 0),
  WarnOnSizeOfThis(Options.get("WarnOnSizeOfThis", 1) != 0),
  WarnOnSizeOfCompareToConstant(
  Options.get("WarnOnSizeOfCompareToConstant", 1) != 0) {}



Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:20
@@ +19,3 @@
+
+AST_MATCHER(QualType, isVoid) {
+return Node->isVoidType();

this matcher exists? ***voidType***

```
Matches type void.

Given
 struct S { void func(); };
functionDecl(returns(voidType()))
  matches "void func();"
```


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:21
@@ +20,3 @@
+AST_MATCHER(QualType, isVoid) {
+return Node->isVoidType();
+}

nit: indent + 2


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:31
@@ +30,3 @@
+  cxxConversionDecl(
+  returns(pointerType(pointee(isConstQualified(), isVoid(, 
   
unless(isExplicit())).bind("operator-void-pointer"), this);
+}

indentation is wrong.
Run clang-format over it

% clang-format -style=file  -i


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:35
@@ +34,3 @@
+void OperatorVoidPointerCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto* MatchedDecl =
+  Result.Nodes.getNodeAs("operator-void-pointer");

pointer lean to right:

```
const auto* MatchedDecl
  -->
const auto *MatchedDecl
```


http://reviews.llvm.org/D20857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.

2016-06-02 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D20857#446784, @murrayc wrote:

> In http://reviews.llvm.org/D20857#446732, @etienneb wrote:
>
> > Enabling/disabling can be done with options (see SizeofExpressionCheck).
>
>
> Thanks. Am I being asked to combine the checks?


I'll let alexfh@ take decision. He will maintain this code.
It's a matter of preference, and not a blocker to me.

I can still help you to make it conform to the coding style.



Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:27
@@ +26,3 @@
+  Finder->addMatcher(cxxConversionDecl(returns(pointerType(pointee(
+   isConstQualified(), voidType(,
+   unless(isExplicit()))

I'm curious, why: isConstQualified() ?
I'm probably missing something.


Comment at: clang-tidy/modernize/OperatorVoidPointerCheck.cpp:40
@@ +39,3 @@
+
+  // FIXME: This tries to change the type and add explicit, but
+  // MatchedDecl->getTypeSpecStartLoc() gets the start of void, not the start

The FIXME only apply to the fixtit statements.
  << FIxItHint(...)

you can still output a diag message.


http://reviews.llvm.org/D20857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20857: [clang-tidy] Add modernize-explicit-operator-bool check.

2016-06-02 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: test/clang-tidy/modernize-operator-void-pointer.cpp:39
@@ +38,3 @@
+class SomethingGoodNonConstVoidPtr {
+  // A non-const void* is unlikely to to be meant as operator bool before C++11
+  // let us use explicit.

You know you can add test for C++11 specifically.

```
readability-redundant-string-cstr.cpp:// RUN: %check_clang_tidy %s 
readability-redundant-string-cstr %t -- -- -std=c++11
```


http://reviews.llvm.org/D20857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20053: [clang-tidy] Add misc-unnecessary-mutable check.

2016-06-03 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:23
@@ +22,3 @@
+
+// Matcher checking if the declaration is non-macro existent mutable which is
+// not dependent on context.

add an anonymous namespace around this declaration.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:26
@@ +25,3 @@
+AST_MATCHER(FieldDecl, isSubstantialMutable) {
+  return Node.getDeclName() && Node.isMutable() &&
+ !Node.getLocation().isMacroID() &&

why getDeclName ?


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:42
@@ +41,3 @@
+
+class FieldUseVisitor : public RecursiveASTVisitor {
+public:

Please add a comment to describe the purpose of this class.
The code is the doc, and it will help readers.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:56
@@ +55,3 @@
+  bool VisitExpr(Expr *GenericExpr) {
+MemberExpr *Expression = dyn_cast(GenericExpr);
+if (!Expression || Expression->getMemberDecl() != SoughtField)

MemberExpr *Expression  -> const auto*


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:60
@@ +59,3 @@
+
+// Check if expr is a member of const thing.
+bool IsConstObj = false;

thing -> object


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:62
@@ +61,3 @@
+bool IsConstObj = false;
+for (const auto *ChildStmt : Expression->children()) {
+  const Expr *ChildExpr = dyn_cast(ChildStmt);

I think the child-expressions of MemberExpr can only be "member->getBase()" ?
In this case, no loop is needed.

```
child_range children() { return child_range(&Base, &Base+1); }
```

```
 Expr *getBase() const { return cast(Base); }
```


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:134
@@ +133,3 @@
+// All decls need their definitions in main file.
+if (!Declaration->hasBody() ||
+!SM.isInMainFile(Declaration->getBody()->getLocStart())) {

Watch out, Declaration->hasBody() is tricky with code when compile on windows 
(clang-cl).
hasBody() may return true, but the getBody() may be NULL.

This is why these tests exist:
```
cppcoreguidelines-pro-type-member-init-delayed.cpp
modernize-redundant-void-arg-delayed.cpp
modernize-use-default-delayed.cpp
performance-unnecessary-value-param-delayed.cpp
```
So this code may crash with delayed-template-parsing.



Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:213
@@ +212,3 @@
+  diag(FD->getLocation(), "'mutable' modifier is unnecessary for field %0")
+  << FD->getDeclName();
+

no need for ->getDeclName()
There is an overloaded operator for namedDecl.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:217
@@ +216,3 @@
+
+  if (CheckRemoval(SM, FD->getLocStart(), FD->getLocEnd(), Context,
+   RemovalRange)) {

You can change CheckRemoval to return the SourceRange.
If it's failing, you can call 'fixithint <<' and it won't be an issue.

This way, you do not need to declare Diag, and you can directly add the 
sourceRange to the expression to line 213.

```
 diag(FD->getLocation(), "'mutable' modifier is unnecessary for field %0")
  << FD
  << getSourceRangeOfMutableToken(FD);
```

WDYT?


http://reviews.llvm.org/D20053



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >