Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-05 Thread Alexander Kornienko
alexfh added a comment.

Some initial comments, mostly style-related. It takes some time to get used to 
the coding style used in LLVM/Clang. One notable thing: though we use `auto` 
sometimes, we don't use the almost-always-auto style. Please see the inline 
comments for specific cases.



Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:63
@@ +62,3 @@
+
+enum StyleConst {
+#define ENUMERATE(v) v,

I'd name this `StyleKind` as most other enums in the LLVM code.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:69
@@ +68,3 @@
+
+static StyleConst const StyleKeys[] = {
+#define ENUMERATE(v) v,

The only use of this array seems to be a simplification of a single loop (the 
other one can iterate over `StyleNames` as per the comment below). I'd remove 
it and instead added a "StyleKindCount" element in the enum and use a normal 
for loop.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:87
@@ +86,3 @@
+  auto const fromString = [](StringRef Str) {
+if (Str.equals("any") || Str.equals("aNy_CasE"))
+  return AnyCase;

This could be written nicer using llvm::StringSwitch.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:87
@@ +86,3 @@
+  auto const fromString = [](StringRef Str) {
+if (Str.equals("any") || Str.equals("aNy_CasE"))
+  return AnyCase;

alexfh wrote:
> This could be written nicer using llvm::StringSwitch.
Not sure why we would need alternative spellings of these options. That seems 
to just add complexity with no benefit.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:105
@@ +104,3 @@
+
+  for (const auto &Key : StyleKeys) {
+NamingStyles.push_back(NamingStyle(

Why not iterate over `StyleNames` here?


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:151
@@ +150,3 @@
+  if (const auto *DeclRef = Result.Nodes.getNodeAs("declref")) {
+auto It = NamingCheckFailures.find(cast(DeclRef->getDecl()));
+if (It == NamingCheckFailures.end())

No need to cast `ValueDecl` returned by `DeclRefExpr::getDecl()` to its base 
class.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:173
@@ +172,3 @@
+
+  auto KindName = "identifier";
+  auto Style = NamingStyle();

Please move the detection of the `KindName` and `Style` to a separate function. 
This method is too large.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:176
@@ +175,3 @@
+
+  if (Result.Nodes.getNodeAs("decl")) {
+if (NamingStyles[Typedef].isSet()) {

Please resolve the node only once (as it's done on line 168) and then just 
check it using `isa<...>(...)`.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:178
@@ +177,3 @@
+if (NamingStyles[Typedef].isSet()) {
+  KindName = "typedef";
+  Style = NamingStyles[Typedef];

Would it be better to have these in a single array next to `StyleNames`? Also, 
this code could return a `StyleKind` (now `StyleConst`), and you would need to 
get the corresponding `NamingStyle` and `KindName` once.

This code would suddenly become much leaner.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:190
@@ +189,3 @@
+  Style = NamingStyles[InlineNamespace];
+
+} else if (NamingStyles[Namespace].isSet()) {

Please remove empty lines before `}`.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:475
@@ +474,3 @@
+
+  auto matchesStyle = [](StringRef Name, NamingStyle Style) {
+static llvm::Regex Matchers[] = {

Please make this a function. This method is too large to define every utility 
function inside it.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:477
@@ +476,3 @@
+static llvm::Regex Matchers[] = {
+llvm::Regex(StringRef("^.*$")),
+llvm::Regex(StringRef("^[a-z][a-z0-9_]*$")),

No need to explicitly convert to `StringRef` here as well.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:505
@@ +504,3 @@
+
+auto fixupWithStyle = [](std::string Name, NamingStyle Style) {
+  static auto Splitter = llvm::Regex(StringRef(

Please make this a function. This method is too large to define every utility 
function inside it.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:505
@@ +504,3 @@
+
+auto fixupWithStyle = [](std::string Name, NamingStyle Style) {
+  static auto Splitter = llvm::Regex(StringRef(

alexfh wrote:
> Please make this a function. This method is too large to define every utility 
> function inside it.
Please make `Name` a StringRef.


Comment at: clang-tidy/readability/IdentifierNamingCh

Re: [PATCH] D10933: Add new IdentifierNaming check

2015-08-05 Thread Alexander Kornienko
alexfh added inline comments.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:87
@@ +86,3 @@
+  auto const fromString = [](StringRef Str) {
+if (Str.equals("any") || Str.equals("aNy_CasE"))
+  return AnyCase;

berenm wrote:
> alexfh wrote:
> > alexfh wrote:
> > > This could be written nicer using llvm::StringSwitch.
> > Not sure why we would need alternative spellings of these options. That 
> > seems to just add complexity with no benefit.
> The idea was to provide a way easier to type than the full names. This may 
> not be very useful, and maybe a single simple name for each case scheme would 
> be enough.
Clang-tidy options are usually read from a file, so minimizing typing is not 
really important.


Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:178
@@ +177,3 @@
+if (NamingStyles[Typedef].isSet()) {
+  KindName = "typedef";
+  Style = NamingStyles[Typedef];

berenm wrote:
> alexfh wrote:
> > Would it be better to have these in a single array next to `StyleNames`? 
> > Also, this code could return a `StyleKind` (now `StyleConst`), and you 
> > would need to get the corresponding `NamingStyle` and `KindName` once.
> > 
> > This code would suddenly become much leaner.
> The problem is that sometimes, the current code falls back to a more generic 
> naming style, but the "kind name" is still trying to describe the original 
> declaration.
> 
> For example, if no style is defined for methods, then it will try to use a 
> more generic "function" style, but the warning will still be "invalid case 
> style for method xxx".
> 
> Maybe this is superfluous and I can drop it. It don't see many cases anyway 
> (my original code was covering more cases - too many - and it seemed sensible 
> at that time).
> The problem is that sometimes, the current code falls back to a more 
> generic naming style, but the "kind name" is still trying to describe the 
> original declaration.

I see. It might be possible to split the mapping of types to style kinds and 
handling missing styles. E.g. a function can return "Method" (which should be 
SK_Method according to [1], btw) and then a caller would check whether the 
corresponding `NamingStyle` is configured, and if needed fall back to a more 
generic category. WDYT?


[1] 
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly


http://reviews.llvm.org/D10933



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


[clang-tools-extra] r339433 - [clang-tidy: modernize] modernize-redundant-void-arg crashes when a function body is in a macro

2018-08-10 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Aug 10 06:59:33 2018
New Revision: 339433

URL: http://llvm.org/viewvc/llvm-project?rev=339433&view=rev
Log:
[clang-tidy: modernize] modernize-redundant-void-arg crashes when a function 
body is in a macro

Fixes https://bugs.llvm.org/show_bug.cgi?id=28406

Patch by IdrissRio.

Differential revision: https://reviews.llvm.org/D49800

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=339433&r1=339432&r2=339433&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Fri 
Aug 10 06:59:33 2018
@@ -149,6 +149,8 @@ void RedundantVoidArgCheck::removeVoidAr
   ProtoToken.getRawIdentifier() == "void") {
 State = SawVoid;
 VoidToken = ProtoToken;
+  } else if (ProtoToken.is(tok::TokenKind::l_paren)) {
+State = SawLeftParen;
   } else {
 State = NothingYet;
   }
@@ -235,10 +237,11 @@ void RedundantVoidArgCheck::processLambd
 const MatchFinder::MatchResult &Result, const LambdaExpr *Lambda) {
   if (Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0 &&
   Lambda->hasExplicitParameters()) {
-SourceLocation Begin =
-Lambda->getIntroducerRange().getEnd().getLocWithOffset(1);
-SourceLocation End = Lambda->getBody()->getBeginLoc().getLocWithOffset(-1);
-removeVoidArgumentTokens(Result, SourceRange(Begin, End),
+SourceManager *SM = Result.SourceManager;
+TypeLoc TL = Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
+removeVoidArgumentTokens(Result,
+ {SM->getSpellingLoc(TL.getBeginLoc()),
+  SM->getSpellingLoc(TL.getEndLoc())},
  "lambda expression");
   }
 }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=339433&r1=339432&r2=339433&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
Fri Aug 10 06:59:33 2018
@@ -445,3 +445,46 @@ struct DefinitionWithNoBody {
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
   // CHECK-FIXES: DefinitionWithNoBody() = delete;
 };
+
+
+
+#define BODY {}
+#define LAMBDA1 [](void){}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+// CHECK-FIXES: LAMBDA1 [](){}
+
+#define LAMBDA2 [](void)BODY
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+// CHECK-FIXES: LAMBDA2 []()BODY
+
+#define LAMBDA3(captures, args, body) captures args body
+#define WRAP(...) __VA_ARGS__
+
+#define LAMBDA4 (void)LAMBDA3([],(void),BODY)
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+// CHECK-FIXES: LAMBDA4 (void)LAMBDA3([],(),BODY)
+
+#define LAMBDA5 []() -> void (*)(void) {return BODY;}
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+// CHECK-FIXES: LAMBDA5 []() -> void (*)() {return BODY;}
+void lambda_expression_with_macro_test(){
+  (void)LAMBDA1;
+  (void)LAMBDA2;
+  (void)LAMBDA3([], (void), BODY);
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+  // CHECK-FIXES: (void)LAMBDA3([], (), BODY);
+
+  LAMBDA4;
+  LAMBDA5;
+  WRAP((void)WRAP(WRAP(LAMBDA3(WRAP([]), WRAP((void)), WRAP(BODY);
+  // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+  // CHECK-FIXES: WRAP((void)WRAP(WRAP(LAMBDA3(WRAP([]), WRAP(()), 
WRAP(BODY);
+
+  (void)WRAP([](void) {});
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+  // CHECK-FIXES: (void)WRAP([]() {});
+
+  [](void) BODY;
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant void argument list in 
lambda expression [modernize-redundant-void-arg]
+  // CHECK-FIXES: []() BODY;
+}


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

r331870 - Fixes issue introduced by r331556.

2018-05-09 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed May  9 05:27:21 2018
New Revision: 331870

URL: http://llvm.org/viewvc/llvm-project?rev=331870&view=rev
Log:
Fixes issue introduced by r331556.

Closes bug: https://bugs.llvm.org/show_bug.cgi?id=37357

Patch by Rafael Stahl!

Differential revision: https://reviews.llvm.org/D46633

Added:
cfe/trunk/test/Analysis/initialization.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=331870&r1=331869&r2=331870&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed May  9 05:27:21 2018
@@ -1711,13 +1711,15 @@ SVal RegionStoreManager::getBindingForFi
   if (const auto *VR = dyn_cast(superR)) {
 const VarDecl *VD = VR->getDecl();
 QualType RecordVarTy = VD->getType();
+unsigned Index = FD->getFieldIndex();
 // Either the record variable or the field has to be const qualified.
 if (RecordVarTy.isConstQualified() || Ty.isConstQualified())
   if (const Expr *Init = VD->getInit())
 if (const auto *InitList = dyn_cast(Init))
-  if (const Expr *FieldInit = InitList->getInit(FD->getFieldIndex()))
-if (Optional V = svalBuilder.getConstantVal(FieldInit))
-  return *V;
+  if (Index < InitList->getNumInits())
+if (const Expr *FieldInit = InitList->getInit(Index))
+  if (Optional V = svalBuilder.getConstantVal(FieldInit))
+return *V;
   }
 
   return getBindingForFieldOrElementCommon(B, R, Ty);

Added: cfe/trunk/test/Analysis/initialization.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/initialization.c?rev=331870&view=auto
==
--- cfe/trunk/test/Analysis/initialization.c (added)
+++ cfe/trunk/test/Analysis/initialization.c Wed May  9 05:27:21 2018
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// expected-no-diagnostics
+
+void initbug() {
+  const union { float a; } u = {};
+  (void)u.a; // no-crash
+}


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


[clang-tools-extra] r332609 - [clang-tidy] Add a flag to enable alpha checkers

2018-05-17 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu May 17 07:04:27 2018
New Revision: 332609

URL: http://llvm.org/viewvc/llvm-project?rev=332609&view=rev
Log:
[clang-tidy] Add a flag to enable alpha checkers

Summary: The alpha checkers can already be enabled using the clang driver, this 
allows them to be enabled using the clang-tidy as well. This can make it easier 
to test the alpha checkers with projects which already support the 
compile_commands.json. It will also allow more people to give feedback and 
patches about the alpha checkers since they can run it as part of clang tidy 
checks.

Reviewers: aaron.ballman, hokein, ilya-biryukov, alexfh, lebedev.ri, xbolva00

Reviewed By: aaron.ballman, alexfh, lebedev.ri, xbolva00

Subscribers: xbolva00, NoQ, dcoughlin, lebedev.ri, xazax.hun, cfe-commits

Patch by Paul Fultz II!

Differential Revision: https://reviews.llvm.org/D46159

Added:
clang-tools-extra/trunk/test/clang-tidy/enable-alpha-checks.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=332609&r1=332608&r2=332609&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu May 17 07:04:27 2018
@@ -309,11 +309,12 @@ static void setStaticAnalyzerCheckerOpts
 
 typedef std::vector> CheckersList;
 
-static CheckersList getCheckersControlList(ClangTidyContext &Context) {
+static CheckersList getCheckersControlList(ClangTidyContext &Context,
+   bool IncludeExperimental) {
   CheckersList List;
 
   const auto &RegisteredCheckers =
-  AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/false);
+  AnalyzerOptions::getRegisteredCheckers(IncludeExperimental);
   bool AnalyzerChecksEnabled = false;
   for (StringRef CheckName : RegisteredCheckers) {
 std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + 
CheckName).str());
@@ -379,7 +380,8 @@ ClangTidyASTConsumerFactory::CreateASTCo
 Consumers.push_back(Finder->newASTConsumer());
 
   AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
-  AnalyzerOptions->CheckersControlList = getCheckersControlList(Context);
+  AnalyzerOptions->CheckersControlList =
+  getCheckersControlList(Context, 
Context.canEnableAnalyzerAlphaCheckers());
   if (!AnalyzerOptions->CheckersControlList.empty()) {
 setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
 AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
@@ -404,7 +406,8 @@ std::vector ClangTidyASTCon
   CheckNames.push_back(CheckFactory.first);
   }
 
-  for (const auto &AnalyzerCheck : getCheckersControlList(Context))
+  for (const auto &AnalyzerCheck : getCheckersControlList(
+   Context, Context.canEnableAnalyzerAlphaCheckers()))
 CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
 
   std::sort(CheckNames.begin(), CheckNames.end());
@@ -463,18 +466,24 @@ void OptionsView::store(ClangTidyOptions
   store(Options, LocalName, llvm::itostr(Value));
 }
 
-std::vector getCheckNames(const ClangTidyOptions &Options) {
+std::vector
+getCheckNames(const ClangTidyOptions &Options,
+  bool AllowEnablingAnalyzerAlphaCheckers) {
   clang::tidy::ClangTidyContext Context(
   llvm::make_unique(ClangTidyGlobalOptions(),
-Options));
+Options),
+  AllowEnablingAnalyzerAlphaCheckers);
   ClangTidyASTConsumerFactory Factory(Context);
   return Factory.getCheckNames();
 }
 
-ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options) {
+ClangTidyOptions::OptionMap
+getCheckOptions(const ClangTidyOptions &Options,
+bool AllowEnablingAnalyzerAlphaCheckers) {
   clang::tidy::ClangTidyContext Context(
   llvm::make_unique(ClangTidyGlobalOptions(),
-Options));
+Options),
+  AllowEnablingAnalyzerAlphaCheckers);
   ClangTidyASTConsumerFactory Factory(Context);
   return Factory.getCheckOptions();
 }

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=332609&r1=332608&r2=332609&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Thu May 17 07:04:27 2018
@@ -210,7 +210,

r314895 - Fix assertion failure in thread safety analysis (PR34800).

2017-10-04 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Oct  4 03:24:36 2017
New Revision: 314895

URL: http://llvm.org/viewvc/llvm-project?rev=314895&view=rev
Log:
Fix assertion failure in thread safety analysis (PR34800).

Summary:
Fix an assertion failure (http://llvm.org/PR34800) and clean up unused code 
relevant to the fixed logic.

A bit of context: when `SExprBuilder::translateMemberExpr` is called on a 
member expression that involves a conversion operator, for example, 
`til::Project` constructor can't just call `getName()` on it, since the name is 
not a simple identifier. In order to handle this case I've introduced an 
optional string to print the member name to. I discovered that the other two 
`til::Project` constructors are not used, so it was better to delete them 
instead of ensuring they work correctly with the new logic.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D38458

Modified:
cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h?rev=314895&r1=314894&r2=314895&view=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyTIL.h Wed Oct  4 
03:24:36 2017
@@ -909,15 +909,10 @@ class Project : public SExpr {
 public:
   static bool classof(const SExpr *E) { return E->opcode() == COP_Project; }
 
-  Project(SExpr *R, StringRef SName)
-  : SExpr(COP_Project), Rec(R), SlotName(SName), Cvdecl(nullptr)
-  { }
   Project(SExpr *R, const clang::ValueDecl *Cvd)
-  : SExpr(COP_Project), Rec(R), SlotName(Cvd->getName()), Cvdecl(Cvd)
-  { }
-  Project(const Project &P, SExpr *R)
-  : SExpr(P), Rec(R), SlotName(P.SlotName), Cvdecl(P.Cvdecl)
-  { }
+  : SExpr(COP_Project), Rec(R), Cvdecl(Cvd) {
+assert(Cvd && "ValueDecl must not be null");
+  }
 
   SExpr *record() { return Rec; }
   const SExpr *record() const { return Rec; }
@@ -931,10 +926,14 @@ public:
   }
 
   StringRef slotName() const {
-if (Cvdecl)
+if (Cvdecl->getDeclName().isIdentifier())
   return Cvdecl->getName();
-else
-  return SlotName;
+if (!SlotName) {
+  SlotName = "";
+  llvm::raw_string_ostream OS(*SlotName);
+  Cvdecl->printName(OS);
+}
+return *SlotName;
   }
 
   template 
@@ -953,7 +952,7 @@ public:
 
 private:
   SExpr* Rec;
-  StringRef SlotName;
+  mutable llvm::Optional SlotName;
   const clang::ValueDecl *Cvdecl;
 };
 

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=314895&r1=314894&r2=314895&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Wed Oct  4 03:24:36 
2017
@@ -5233,3 +5233,18 @@ class acquired_before_empty_str {
   } // expected-warning {{mutex 'lock_' is still held at the end of function}}
   Mutex lock_ ACQUIRED_BEFORE("");
 };
+
+namespace PR34800 {
+struct A {
+  operator int() const;
+};
+struct B {
+  bool g() __attribute__((locks_excluded(h))); // expected-warning 
{{'locks_excluded' attribute requires arguments whose type is annotated with 
'capability' attribute; type here is 'int'}}
+  int h;
+};
+struct C {
+  B *operator[](int);
+};
+C c;
+void f() { c[A()]->g(); }
+} // namespace PR34800


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


Re: [clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-06 Thread Alexander Kornienko via cfe-commits
On 6 Oct 2017 14:59, "Aaron Ballman via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: aaronballman
Date: Fri Oct  6 05:57:28 2017
New Revision: 315057

URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
Log:
Fix nested namespaces in google-readability-nested-namespace-comments.

Fixes PR34701.

Patch by Alexandru Octavian Buțiu.

Added:
clang-tools-extra/trunk/test/clang-tidy/google-readability-
nested-namespace-comments.cpp


Can we rename the test so it starts with the check name? E.g.
"google-readability-namespace-comments-cxx17" or something else that makes
sense?

Modified:
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/readability/
NamespaceCommentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=
315057&r1=315056&r2=315057&view=diff

==
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
Fri Oct  6 05:57:28 2017
@@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)?
*"
-  "namespace( +([a-zA-Z0-9_]+))?\\.?
*(\\*/)?$",
+  "namespace( +([a-zA-Z0-9_:]+))?\\.?
*(\\*/)?$",
   llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
@@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
   return Fix;
 }

+static std::string getNamespaceComment(const std::string &NameSpaceName,
+   bool InsertLineBreak) {
+  std::string Fix = "// namespace ";
+  Fix.append(NameSpaceName);
+  if (InsertLineBreak)
+Fix.append("\n");
+  return Fix;
+}
+
 void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ND = Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
@@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
   SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
   SourceLocation Loc = AfterRBrace;
   Token Tok;
+  SourceLocation LBracketLocation = ND->getLocation();
+  SourceLocation NestedNamespaceBegin = LBracketLocation;
+
+  // Currently for nested namepsace (n1::n2::...) the AST matcher will
match foo
+  // then bar instead of a single match. So if we got a nested namespace
we have
+  // to skip the next ones.
+  for (const auto &EndOfNameLocation : Ends) {
+if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
+  EndOfNameLocation))
+  return;
+  }
+  while (Lexer::getRawToken(LBracketLocation, Tok, Sources, getLangOpts())
||
+ !Tok.is(tok::l_brace)) {
+LBracketLocation = LBracketLocation.getLocWithOffset(1);
+  }
+
+  auto TextRange =
+  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin,
LBracketLocation),
+Sources, getLangOpts());
+  auto NestedNamespaceName =
+  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
+  bool IsNested = NestedNamespaceName.contains(':');
+
+  if (IsNested)
+Ends.push_back(LBracketLocation);
+
   // Skip whitespace until we find the next token.
   while (Lexer::getRawToken(Loc, Tok, Sources, getLangOpts()) ||
  Tok.is(tok::semi)) {
 Loc = Loc.getLocWithOffset(1);
   }
+
   if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
 return;

@@ -98,10 +134,14 @@ void NamespaceCommentCheck::check(const
   StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] :
"";
   StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";

-  // Check if the namespace in the comment is the same.
-  if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) ||
-  (ND->getNameAsString() == NamespaceNameInComment &&
-   Anonymous.empty())) {
+  if (IsNested && NestedNamespaceName == NamespaceNameInComment) {
+// C++17 nested namespace.
+return;
+  } else if ((ND->isAnonymousNamespace() &&
+  NamespaceNameInComment.empty()) ||
+ (ND->getNameAsString() == NamespaceNameInComment &&
+  Anonymous.empty())) {
+// Check if the namespace in the comment is the same.
 // FIXME: Maybe we need a strict mode, where we always fix
namespace
 // comments with different format.
 return;
@@ -131,13 +171,16 @@ void NamespaceCommentCheck::check(const
   std::string Names

Re: r314571 - [Analyzer] Synthesize function body for std::call_once

2017-10-07 Thread Alexander Kornienko via cfe-commits
This revision might be the cause of
https://bugs.llvm.org/show_bug.cgi?id=34869. I'm still working on a reduced
test case.

On Sat, Sep 30, 2017 at 2:03 AM, George Karpenkov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: george.karpenkov
> Date: Fri Sep 29 17:03:22 2017
> New Revision: 314571
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314571&view=rev
> Log:
> [Analyzer] Synthesize function body for std::call_once
>
> Differential Revision: https://reviews.llvm.org/D37840
>
> Added:
> cfe/trunk/test/Analysis/call_once.cpp
> Modified:
> cfe/trunk/lib/Analysis/BodyFarm.cpp
>
> Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Analysis/BodyFarm.cpp?rev=314571&r1=314570&r2=314571&view=diff
> 
> ==
> --- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
> +++ cfe/trunk/lib/Analysis/BodyFarm.cpp Fri Sep 29 17:03:22 2017
> @@ -14,11 +14,18 @@
>
>  #include "BodyFarm.h"
>  #include "clang/AST/ASTContext.h"
> +#include "clang/AST/CXXInheritance.h"
>  #include "clang/AST/Decl.h"
>  #include "clang/AST/Expr.h"
> +#include "clang/AST/ExprCXX.h"
>  #include "clang/AST/ExprObjC.h"
> +#include "clang/AST/NestedNameSpecifier.h"
>  #include "clang/Analysis/CodeInjector.h"
> +#include "clang/Basic/OperatorKinds.h"
>  #include "llvm/ADT/StringSwitch.h"
> +#include "llvm/Support/Debug.h"
> +
> +#define DEBUG_TYPE "body-farm"
>
>  using namespace clang;
>
> @@ -55,7 +62,9 @@ public:
>CompoundStmt *makeCompound(ArrayRef);
>
>/// Create a new DeclRefExpr for the referenced variable.
> -  DeclRefExpr *makeDeclRefExpr(const VarDecl *D);
> +  DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
> +   bool RefersToEnclosingVariableOrCapture =
> false,
> +   bool GetNonReferenceType = false);
>
>/// Create a new UnaryOperator representing a dereference.
>UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
> @@ -66,9 +75,24 @@ public:
>/// Create an implicit cast to a builtin boolean type.
>ImplicitCastExpr *makeIntegralCastToBoolean(const Expr *Arg);
>
> -  // Create an implicit cast for lvalue-to-rvaluate conversions.
> +  /// Create an implicit cast for lvalue-to-rvaluate conversions.
>ImplicitCastExpr *makeLvalueToRvalue(const Expr *Arg, QualType Ty);
>
> +  /// Create an implicit cast for lvalue-to-rvaluate conversions.
> +  ImplicitCastExpr *makeLvalueToRvalue(const Expr *Arg,
> +   bool GetNonReferenceType = false);
> +
> +  /// Make RValue out of variable declaration, creating a temporary
> +  /// DeclRefExpr in the process.
> +  ImplicitCastExpr *
> +  makeLvalueToRvalue(const VarDecl *Decl,
> + bool RefersToEnclosingVariableOrCapture = false,
> + bool GetNonReferenceType = false);
> +
> +  /// Create an implicit cast of the given type.
> +  ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
> + CastKind CK = CK_LValueToRValue);
> +
>/// Create an Objective-C bool literal.
>ObjCBoolLiteralExpr *makeObjCBool(bool Val);
>
> @@ -78,6 +102,18 @@ public:
>/// Create a Return statement.
>ReturnStmt *makeReturn(const Expr *RetVal);
>
> +  /// Create an integer literal.
> +  IntegerLiteral *makeIntegerLiteral(uint64_t value);
> +
> +  /// Create a member expression.
> +  MemberExpr *makeMemberExpression(Expr *base, ValueDecl *MemberDecl,
> +   bool IsArrow = false,
> +   ExprValueKind ValueKind = VK_LValue);
> +
> +  /// Returns a *first* member field of a record declaration with a given
> name.
> +  /// \return an nullptr if no member with such a name exists.
> +  NamedDecl *findMemberField(const CXXRecordDecl *RD, StringRef Name);
> +
>  private:
>ASTContext &C;
>  };
> @@ -106,16 +142,16 @@ CompoundStmt *ASTMaker::makeCompound(Arr
>return new (C) CompoundStmt(C, Stmts, SourceLocation(),
> SourceLocation());
>  }
>
> -DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) {
> -  DeclRefExpr *DR =
> -DeclRefExpr::Create(/* Ctx = */ C,
> -/* QualifierLoc = */ NestedNameSpecifierLoc(),
> -/* TemplateKWLoc = */ SourceLocation(),
> -/* D = */ const_cast(D),
> -/* RefersToEnclosingVariableOrCapture = */ false,
> -/* NameLoc = */ SourceLocation(),
> -/* T = */ D->getType(),
> -/* VK = */ VK_LValue);
> +DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D,
> +   bool RefersToEnclosingVariableOrCap
> ture,
> +   bool GetNonReferenceType) {
> +  auto Type = D->getType();
> +  if (GetNonReferenceType)
> +Type = Type.getNonReferenceType();
> +

Re: r314571 - [Analyzer] Synthesize function body for std::call_once

2017-10-09 Thread Alexander Kornienko via cfe-commits
Bugzilla is not accessible, so here's a reduced test case:
$ cat test-clang__BodyFarm__getBody.cc
namespace std {
template 
void call_once(d, e);
}
void g();
void f() {
  std::call_once(g, false);
}
$ clang-tidy -checks=-*,clang-analyzer* test-clang__BodyFarm__getBody.cc --
-std=c++11 -w
*** SIGSEGV; stack trace: ***
PC: @  0x2f96e3a  (unknown)  clang::DeclContext::lookup()
@  0x532bb51   1152  FailureSignalHandler()
@ 0x7f42b341f9a0  (unknown)  (unknown)
@  0x2ae74c5576  (anonymous
namespace)::ASTMaker::findMemberField()
@  0x2ae59fc704  create_call_once()
@  0x2ae5040784  clang::BodyFarm::getBody()
@  0x2ac67af144  clang::AnalysisDeclContext::getBody()
@  0x1c499fa128
 clang::ento::AnyFunctionCall::getRuntimeDefinition()
@  0x1cc6146320
 clang::ento::ExprEngine::defaultEvalCall()
@  0x1c61033464
 clang::ento::CheckerManager::runCheckersForEvalCall()
@  0x1cc4fc9352  clang::ento::ExprEngine::evalCall()
@  0x1cc4e8c432
 clang::ento::ExprEngine::VisitCallExpr()
@  0x1c7da94   4000  clang::ento::ExprEngine::Visit()
@  0x1c7a821496  clang::ento::ExprEngine::ProcessStmt()
@  0x1c7a4da240
 clang::ento::ExprEngine::processCFGElement()
@  0x1ca8ed6128
 clang::ento::CoreEngine::HandlePostStmt()
@  0x1ca87d6496
 clang::ento::CoreEngine::dispatchWorkItem()
@  0x1ca8338544
 clang::ento::CoreEngine::ExecuteWorkList()
@   0xf954d5 80
 clang::ento::ExprEngine::ExecuteWorkList()
@   0xf3c612   1056  (anonymous
namespace)::AnalysisConsumer::ActionExprEngine()
@   0xf3c3d1 80  (anonymous
namespace)::AnalysisConsumer::RunPathSensitiveChecks()
@   0xf3c095288  (anonymous
namespace)::AnalysisConsumer::HandleCode()
@   0xf2f6e3416  (anonymous
namespace)::AnalysisConsumer::HandleDeclsCallGraph()
@   0xf2d967336  (anonymous
namespace)::AnalysisConsumer::HandleTranslationUnit()
@  0x1366eae 80
 clang::MultiplexConsumer::HandleTranslationUnit()
@  0x1dc6ae6288  clang::ParseAST()
@  0x135475a 80
 clang::ASTFrontendAction::ExecuteAction()
@  0x13541f0112  clang::FrontendAction::Execute()
@  0x1169822496
 clang::CompilerInstance::ExecuteAction()
@  0x1032ba2464
 clang::tooling::FrontendActionFactory::runInvocation()
@  0x1032a43160
 clang::tooling::ToolInvocation::runInvocation()
@  0x1031306   1840  clang::tooling::ToolInvocation::run()
@  0x1033c30   1664  clang::tooling::ClangTool::run()

On Sat, Oct 7, 2017 at 12:56 PM, Alexander Kornienko 
wrote:

> This revision might be the cause of https://bugs.llvm.org/show_
> bug.cgi?id=34869. I'm still working on a reduced test case.
>
> On Sat, Sep 30, 2017 at 2:03 AM, George Karpenkov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: george.karpenkov
>> Date: Fri Sep 29 17:03:22 2017
>> New Revision: 314571
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=314571&view=rev
>> Log:
>> [Analyzer] Synthesize function body for std::call_once
>>
>> Differential Revision: https://reviews.llvm.org/D37840
>>
>> Added:
>> cfe/trunk/test/Analysis/call_once.cpp
>> Modified:
>> cfe/trunk/lib/Analysis/BodyFarm.cpp
>>
>> Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/
>> BodyFarm.cpp?rev=314571&r1=314570&r2=314571&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
>> +++ cfe/trunk/lib/Analysis/BodyFarm.cpp Fri Sep 29 17:03:22 2017
>> @@ -14,11 +14,18 @@
>>
>>  #include "BodyFarm.h"
>>  #include "clang/AST/ASTContext.h"
>> +#include "clang/AST/CXXInheritance.h"
>>  #include "clang/AST/Decl.h"
>>  #include "clang/AST/Expr.h"
>> +#include "clang/AST/ExprCXX.h"
>>  #include "clang/AST/ExprObjC.h"
>> +#include "clang/AST/NestedNameSpecifier.h"
>>  #include "clang/Analysis/CodeInjector.h"
>> +#include "clang/Basic/OperatorKinds.h"
>>  #include "llvm/ADT/StringSwitch.h"
>> +#include "llvm/Support/Debug.h"
>> +
>> +#define DEBUG_TYPE "body-farm"
>>
>>  using namespace clang;
>>
>> @@ -55,7

Re: [clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-11 Thread Alexander Kornienko via cfe-commits
On Fri, Oct 6, 2017 at 3:27 PM, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: aaronballman
> Date: Fri Oct  6 06:27:59 2017
> New Revision: 315060
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315060&view=rev
> Log:
> Renaming a test to start with the name of the check based on post-commit
> review feedback; NFC.
>
> Added:
> clang-tools-extra/trunk/test/clang-tidy/google-readability-
> namespace-comments-cxx17
>

Sorry for not being clear. I didn't mean the `.cpp` extension should be
removed. This effectively disables the test, since lit only runs tests in
files with certain extensions (under clang-tools-extra/test these are '.c',
'.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.modularize',
'.module-map-checker', '.test').

I've just renamed the file to *.cpp and the test fails for me:

[0/1] Running the Clang extra tools' regression tests
FAIL: Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp (102 of 674)

 TEST 'Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp' FAILED


Script:
--
/usr/bin/python2.7
/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py
/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
google-readability-namespace-comments
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp
-- -- -std=c++17
--
Exit Code: 1

Command Output (stdout):
--
Running ['clang-tidy',
'/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
'-fix', '--checks=-*,google-readability-namespace-comments', '--',
'-std=c++17', '-nostdinc++']...
 clang-tidy output ---


--

-- Fixes -


--

FileCheck failed:
/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp:13:17:
error: expected string not found in input

// CHECK-FIXES: }  // namespace n3
^
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:1:1:
note: scanning from here

// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- --
-std=c++17
^
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:5:7:
note: possible intended match here

  // So that namespace is not empty.
  ^


--
Command Output (stderr):
--
Traceback (most recent call last):
  File
"/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
line 140, in 
main()
  File
"/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
line 121, in main
stderr=subprocess.STDOUT)
  File "/usr/lib/python2.7/subprocess.py", line 573, in check_output

raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['FileCheck',
'-input-file=/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
'/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp',
'-check-prefix=CHECK-FIXES', '-strict-whitespace']' returned non-zero exit
status 1


--


Testing Time: 13.07s

Failing Tests (1):
Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp


  Expected Passes: 673
  Unexpected Failures: 1
FAILED: tools/clang/tools/extra/test/CMakeFiles/check-clang-tools



Did you experience anything similar? Any ideas?

  - copied unchanged from r315059, clang-tools-extra/trunk/test/
> clang-tidy/google-readability-nested-namespace-comments.cpp
> Removed:
> clang-tools-extra/trunk/test/clang-tidy/google-readability-
> nested-namespace-comments.cpp
>
> Removed: clang-tools-extra/trunk/test/clang-tidy/google-readability-
> nested-namespace-comments.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/test/clang-tidy/google-readability-nested-namespace-
> comments.cpp?rev=315059&view=auto
> 
> ==
> --- 
> clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
> (original)
> +++ 
> clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
> (removed)
> @@ -1,15 +0,0 @@
> -// RUN: %check_clang_tidy %s google-readability-namespace-comments %t --
> -- -std=c++17
> -
> -namespace n1::n2 {
> -namespace n3 {
> -  // So that namespace is not empty.
> -  void f();
> -
> -// CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n3' not terminated
> with
> -// CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n3' starts here
> -// CHEC

[clang-tools-extra] r315574 - Fix the google-readability-namespace-comments-cxx17 test after r315060.

2017-10-12 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Oct 12 03:41:22 2017
New Revision: 315574

URL: http://llvm.org/viewvc/llvm-project?rev=315574&view=rev
Log:
Fix the google-readability-namespace-comments-cxx17 test after r315060.

Restore the file extension. Make the namespace longer than the
ShortNamespaceLines so that the check triggers.

Added:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
Removed:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17

Removed: 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17?rev=315573&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17
 (removed)
@@ -1,15 +0,0 @@
-// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- -- 
-std=c++17
-
-namespace n1::n2 {
-namespace n3 {
-  // So that namespace is not empty.
-  void f();
-
-// CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n3' not terminated with
-// CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n3' starts here
-// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]
-// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
-}}
-// CHECK-FIXES: }  // namespace n3
-// CHECK-FIXES: }  // namespace n1::n2
-

Added: 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp?rev=315574&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
 Thu Oct 12 03:41:22 2017
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- -- 
-std=c++17
+
+namespace n1::n2 {
+namespace n3 {
+  // So that namespace is not empty and has at least 10 lines.
+  // 1
+  // 2
+  // 3
+  // 3
+  // 4
+  // 5
+  // 6
+  // 7
+  // 8
+  void f();
+}}
+// CHECK-MESSAGES: :[[@LINE-1]]:2: warning: namespace 'n3' not terminated with
+// CHECK-MESSAGES: :[[@LINE-14]]:11: note: namespace 'n3' starts here
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]
+// CHECK-MESSAGES: :[[@LINE-17]]:11: note: namespace 'n1::n2' starts here
+// CHECK-FIXES: }  // namespace n3
+// CHECK-FIXES: }  // namespace n1::n2
+


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


Re: [clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-12 Thread Alexander Kornienko via cfe-commits
On Thu, Oct 12, 2017 at 11:12 AM, Jonas Toth  wrote:

> Hi,
>
> I am not sure if could follow correctly, but the test for nested
> namespaces comments does not work correctly and is therefore currently
> disabled by fileextension?
>

No, the removal of the file extension was unintentional (likely
misunderstanding of my post-commit review comment).


>
> When running the check from trunk i get the following issues:
>
> $ clang-check google-readability-namespace-comments-cxx17.cpp --
> -std=c++17
> > error: invalid value 'c++17' in '-std=c++17'
>

I suppose, your clang-check is just old. Clang supports -std=c++17 these
days.


>
> In the clang-tidy check '-std=c++17' is used. I don't know if the c++17 -
> flag is introduced in clang yet, but maybe this would be one issue.
>
> Running clang-tidy from command line does not produce output (added
> fileextension for now):
>
> $ clang-tidy -checks=-*,google-readability-namespace-comments
> google-readability-namespace-comments-cxx17.cpp -- -std=c++1z
> $ clang-tidy -checks=-*,google-readability-namespace-comments
> google-readability-namespace-comments-cxx17.cpp -- -- -std=c++1z
> > Error while processing /home/jonas/opt/llvm/tools/cla
> ng/tools/extra/test/clang-tidy/google-readability-namespace-
> comments-cxx17.cpp.
>
> Adding a 'std::cout << "Test if run" << std::endl' at the beginning of the
> `check` - Method works and generates output:
>
> $ clang-tidy -checks=-*,google-readability-namespace-comments
> google-readability-namespace-comments-cxx17.cpp -- -std=c++1z
> Test if run
> Test if run
> Test if run
>
> So I think there is a regression in the Testingcode not catching the
> nested namespaces. Did it work before and what could have changed?
> If it did work and the clang-tidy code is the same this could be a
> regression somewhere else.
>

The problem was that the namespace was shorter than the default
ShortNamespaceLines option value, so the check didn't trigger. Fixed
in r315574 (but would be nice, if this kind of stuff was detected before
commit).

However, this is not the end of problems with this check. It started
causing assertion failures on some of our code after the recent changes
(r315057). I'll post an update on that revision once I have more details.


>
> All the Best, Jonas
>
>
> Am 11.10.2017 um 21:36 schrieb Aaron Ballman:
>
>> On Wed, Oct 11, 2017 at 3:29 PM, Alexander Kornienko 
>> wrote:
>>
>>> On Fri, Oct 6, 2017 at 3:27 PM, Aaron Ballman via cfe-commits
>>>  wrote:
>>>
>>>> Author: aaronballman
>>>> Date: Fri Oct  6 06:27:59 2017
>>>> New Revision: 315060
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=315060&view=rev
>>>> Log:
>>>> Renaming a test to start with the name of the check based on post-commit
>>>> review feedback; NFC.
>>>>
>>>> Added:
>>>>
>>>> clang-tools-extra/trunk/test/clang-tidy/google-readability-n
>>>> amespace-comments-cxx17
>>>>
>>>
>>> Sorry for not being clear. I didn't mean the `.cpp` extension should be
>>> removed. This effectively disables the test, since lit only runs tests in
>>> files with certain extensions (under clang-tools-extra/test these are
>>> '.c',
>>> '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.modularize',
>>> '.module-map-checker', '.test').
>>>
>> That's entirely my fault -- I should have recognized that. Sorry for
>> the trouble!
>>
>> I've just renamed the file to *.cpp and the test fails for me:
>>>
>>> [0/1] Running the Clang extra tools' regression tests
>>> FAIL: Clang Tools ::
>>> clang-tidy/google-readability-namespace-comments-cxx17.cpp (102 of 674)
>>>  TEST 'Clang Tools ::
>>> clang-tidy/google-readability-namespace-comments-cxx17.cpp' FAILED
>>> 
>>> Script:
>>> --
>>> /usr/bin/python2.7
>>> /src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py
>>> /src/tools/clang/tools/extra/test/clang-tidy/google-readabil
>>> ity-namespace-comments-cxx17.cpp
>>> google-readability-namespace-comments
>>> /build/tools/clang/tools/extra/test/clang-tidy/Output/google
>>> -readability-namespace-comments-cxx17.cpp.tmp
>>> -- -- -std=c++17
>>> --
>>> Exit Code: 1
>>>

Re: [clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-12 Thread Alexander Kornienko via cfe-commits
On Fri, Oct 6, 2017 at 2:57 PM, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: aaronballman
> Date: Fri Oct  6 05:57:28 2017
> New Revision: 315057
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
> Log:
> Fix nested namespaces in google-readability-nested-namespace-comments.
>
> Fixes PR34701.
>
> Patch by Alexandru Octavian Buțiu.
>
> Added:
> clang-tools-extra/trunk/test/clang-tidy/google-readability-
> nested-namespace-comments.cpp
> Modified:
> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h
>
> Modified: clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=
> 315057&r1=315056&r2=315057&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> Fri Oct  6 05:57:28 2017
> @@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
>   ClangTidyContext *Context)
>  : ClangTidyCheck(Name, Context),
>NamespaceCommentPattern("^/[/*] *(end (of )?)?
> *(anonymous|unnamed)? *"
> -  "namespace( +([a-zA-Z0-9_]+))?\\.?
> *(\\*/)?$",
> +  "namespace( +([a-zA-Z0-9_:]+))?\\.?
> *(\\*/)?$",
>llvm::Regex::IgnoreCase),
>ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
>SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
> @@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
>return Fix;
>  }
>
> +static std::string getNamespaceComment(const std::string &NameSpaceName,
> +   bool InsertLineBreak) {
> +  std::string Fix = "// namespace ";
> +  Fix.append(NameSpaceName);
> +  if (InsertLineBreak)
> +Fix.append("\n");
> +  return Fix;
> +}
> +
>  void NamespaceCommentCheck::check(const MatchFinder::MatchResult
> &Result) {
>const auto *ND = Result.Nodes.getNodeAs("namespace");
>const SourceManager &Sources = *Result.SourceManager;
> @@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
>SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
>SourceLocation Loc = AfterRBrace;
>Token Tok;
> +  SourceLocation LBracketLocation = ND->getLocation();
> +  SourceLocation NestedNamespaceBegin = LBracketLocation;
> +
> +  // Currently for nested namepsace (n1::n2::...) the AST matcher will
> match foo
> +  // then bar instead of a single match. So if we got a nested namespace
> we have
> +  // to skip the next ones.
> +  for (const auto &EndOfNameLocation : Ends) {
> +if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
> +  EndOfNameLocation))
> +  return;
> +  }
> +  while (Lexer::getRawToken(LBracketLocation, Tok, Sources,
> getLangOpts()) ||
> + !Tok.is(tok::l_brace)) {
>

Now another issue with this revision: the check started triggering an
assertion failure and incredible slowness (infinite loops?) on some real
files. I've not yet come up with an isolated test case, but all this seems
to be happening around this loop.

I'm going to revert this revision.


> +LBracketLocation = LBracketLocation.getLocWithOffset(1);
> +  }
> +
> +  auto TextRange =
> +  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin,
> LBracketLocation),
> +Sources, getLangOpts());
> +  auto NestedNamespaceName =
> +  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
> +  bool IsNested = NestedNamespaceName.contains(':');
> +
> +  if (IsNested)
> +Ends.push_back(LBracketLocation);
> +
>// Skip whitespace until we find the next token.
>while (Lexer::getRawToken(Loc, Tok, Sources, getLangOpts()) ||
>   Tok.is(tok::semi)) {
>  Loc = Loc.getLocWithOffset(1);
>}
> +
>if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
>  return;
>
> @@ -98,10 +134,14 @@ void NamespaceCommentCheck::check(const
>StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] :
> "";
>StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
>
> -  // Check if the namespace in the comment is the same.
> -  if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty())
> ||
> -  (ND->getNameAsString() == NamespaceNameInComment &&
> -   Anonymous.empty())) {
> +  if (IsNested && NestedNamespaceName == NamespaceNameInComment) {
> +// C++17 nested namespace.
> +return;
> +  } else if ((ND->isAnonymousNamespace() &&
> +  NamespaceNameInComment.empty()) ||
> +

[clang-tools-extra] r315580 - Revert "Fix nested namespaces in google-readability-nested-namespace-comments."

2017-10-12 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Oct 12 07:25:16 2017
New Revision: 315580

URL: http://llvm.org/viewvc/llvm-project?rev=315580&view=rev
Log:
Revert "Fix nested namespaces in google-readability-nested-namespace-comments."

This reverts r315057. The revision introduces assertion failures:
assertion failed at llvm/tools/clang/include/clang/Basic/SourceManager.h:428 in
const clang::SrcMgr::ExpansionInfo &clang::SrcMgr::SLocEntry::getExpansion()
const: isExpansion() && "Not a macro expansion SLocEntry!"
Stack trace:
__assert_fail
clang::SrcMgr::SLocEntry::getExpansion()
clang::SourceManager::getExpansionLocSlowCase()
clang::SourceManager::getExpansionLoc()
clang::Lexer::getRawToken()
clang::tidy::readability::NamespaceCommentCheck::check()
clang::ast_matchers::internal::(anonymous 
namespace)::MatchASTVisitor::MatchVisitor::visitMatch()
clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches()
clang::ast_matchers::internal::(anonymous 
namespace)::MatchASTVisitor::matchWithFilter()
clang::ast_matchers::internal::(anonymous 
namespace)::MatchASTVisitor::matchDispatch()
clang::ast_matchers::internal::(anonymous 
namespace)::MatchASTVisitor::TraverseDecl()
clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
clang::RecursiveASTVisitor<>::TraverseDecl()
clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
clang::RecursiveASTVisitor<>::TraverseDecl()
clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
clang::RecursiveASTVisitor<>::TraverseDecl()
clang::ast_matchers::MatchFinder::matchAST()
clang::MultiplexConsumer::HandleTranslationUnit()
clang::ParseAST()
clang::FrontendAction::Execute()
clang::CompilerInstance::ExecuteAction()
clang::tooling::FrontendActionFactory::runInvocation()
clang::tooling::ToolInvocation::runInvocation()
clang::tooling::ToolInvocation::run()

Still working on an isolated test case.

Removed:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=315580&r1=315579&r2=315580&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
Thu Oct 12 07:25:16 2017
@@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
+  "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$",
   llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
@@ -56,15 +56,6 @@ static std::string getNamespaceComment(c
   return Fix;
 }
 
-static std::string getNamespaceComment(const std::string &NameSpaceName,
-   bool InsertLineBreak) {
-  std::string Fix = "// namespace ";
-  Fix.append(NameSpaceName);
-  if (InsertLineBreak)
-Fix.append("\n");
-  return Fix;
-}
-
 void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ND = Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
@@ -83,38 +74,11 @@ void NamespaceCommentCheck::check(const
   SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
   SourceLocation Loc = AfterRBrace;
   Token Tok;
-  SourceLocation LBracketLocation = ND->getLocation();
-  SourceLocation NestedNamespaceBegin = LBracketLocation;
-
-  // Currently for nested namepsace (n1::n2::...) the AST matcher will match 
foo
-  // then bar instead of a single match. So if we got a nested namespace we 
have
-  // to skip the next ones.
-  for (const auto &EndOfNameLocation : Ends) {
-if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
-  EndOfNameLocation))
-  return;
-  }
-  while (Lexer::getRawToken(LBracketLocation, Tok, Sources, getLangOpts()) ||
- !Tok.is(tok::l_brace)) {
-LBracketLocation = LBracketLocation.getLocWithOffset(1);
-  }
-
-  auto TextRange =
-  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin, 
LBracketLocation),
-Sources, getLangOpts());
-  auto NestedNamespaceName =
-  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rt

Re: [clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-12 Thread Alexander Kornienko via cfe-commits
Reverted in r315580.

On Thu, Oct 12, 2017 at 4:03 PM, Aaron Ballman 
wrote:

> On Thu, Oct 12, 2017 at 10:01 AM, Alexander Kornienko 
> wrote:
> >
> > On Fri, Oct 6, 2017 at 2:57 PM, Aaron Ballman via cfe-commits
> >  wrote:
> >>
> >> Author: aaronballman
> >> Date: Fri Oct  6 05:57:28 2017
> >> New Revision: 315057
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
> >> Log:
> >> Fix nested namespaces in google-readability-nested-namespace-comments.
> >>
> >> Fixes PR34701.
> >>
> >> Patch by Alexandru Octavian Buțiu.
> >>
> >> Added:
> >>
> >> clang-tools-extra/trunk/test/clang-tidy/google-readability-
> nested-namespace-comments.cpp
> >> Modified:
> >>
> >> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> >> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.h
> >>
> >> Modified:
> >> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=
> 315057&r1=315056&r2=315057&view=diff
> >>
> >> 
> ==
> >> ---
> >> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> >> (original)
> >> +++
> >> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> Fri
> >> Oct  6 05:57:28 2017
> >> @@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
> >>   ClangTidyContext *Context)
> >>  : ClangTidyCheck(Name, Context),
> >>NamespaceCommentPattern("^/[/*] *(end (of )?)?
> >> *(anonymous|unnamed)? *"
> >> -  "namespace( +([a-zA-Z0-9_]+))?\\.?
> >> *(\\*/)?$",
> >> +  "namespace( +([a-zA-Z0-9_:]+))?\\.?
> >> *(\\*/)?$",
> >>llvm::Regex::IgnoreCase),
> >>ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
> >>SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
> >> @@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
> >>return Fix;
> >>  }
> >>
> >> +static std::string getNamespaceComment(const std::string
> &NameSpaceName,
> >> +   bool InsertLineBreak) {
> >> +  std::string Fix = "// namespace ";
> >> +  Fix.append(NameSpaceName);
> >> +  if (InsertLineBreak)
> >> +Fix.append("\n");
> >> +  return Fix;
> >> +}
> >> +
> >>  void NamespaceCommentCheck::check(const MatchFinder::MatchResult
> &Result)
> >> {
> >>const auto *ND = Result.Nodes.getNodeAs("namespace");
> >>const SourceManager &Sources = *Result.SourceManager;
> >> @@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
> >>SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
> >>SourceLocation Loc = AfterRBrace;
> >>Token Tok;
> >> +  SourceLocation LBracketLocation = ND->getLocation();
> >> +  SourceLocation NestedNamespaceBegin = LBracketLocation;
> >> +
> >> +  // Currently for nested namepsace (n1::n2::...) the AST matcher will
> >> match foo
> >> +  // then bar instead of a single match. So if we got a nested
> namespace
> >> we have
> >> +  // to skip the next ones.
> >> +  for (const auto &EndOfNameLocation : Ends) {
> >> +if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
> >> +  EndOfNameLocation))
> >> +  return;
> >> +  }
> >> +  while (Lexer::getRawToken(LBracketLocation, Tok, Sources,
> >> getLangOpts()) ||
> >> + !Tok.is(tok::l_brace)) {
> >
> >
> > Now another issue with this revision: the check started triggering an
> > assertion failure and incredible slowness (infinite loops?) on some real
> > files. I've not yet come up with an isolated test case, but all this
> seems
> > to be happening around this loop.
> >
> > I'm going to revert this revision.
>
> I think that's the right call. The original r

[clang-tools-extra] r315682 - [clang-tidy] Add a regression test for google-readability-namespace-comments

2017-10-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Oct 13 07:11:14 2017
New Revision: 315682

URL: http://llvm.org/viewvc/llvm-project?rev=315682&view=rev
Log:
[clang-tidy] Add a regression test for google-readability-namespace-comments

Add a regression test for the google-readability-namespace-comments bug
introduced in r315057 (reverted in r315580).

Modified:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp?rev=315682&r1=315681&r2=315682&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
 Fri Oct 13 07:11:14 2017
@@ -15,6 +15,20 @@ void f(); // So that the namespace isn't
 // CHECK-FIXES: }  // namespace n2
 // CHECK-FIXES: }  // namespace n1
 
+#define MACRO macro_expansion
+namespace MACRO {
+void f(); // So that the namespace isn't empty.
+// 1
+// 2
+// 3
+// 4
+// 5
+// 6
+// 7
+// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'macro_expansion' not 
terminated with
+// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'macro_expansion' starts 
here
+}
+// CHECK-FIXES: }  // namespace macro_expansion
 
 namespace short1 {
 namespace short2 {


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


Re: r315811 - Re-land r315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."

2017-10-19 Thread Alexander Kornienko via cfe-commits
On Sat, Oct 14, 2017 at 5:59 PM, Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: d0k
> Date: Sat Oct 14 08:59:34 2017
> New Revision: 315811
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315811&view=rev
> Log:
> Re-land r315787, "[Sema] Warn about unused variables if we can constant
> evaluate the initializer."
>
> The warnings in libc++ tests were fixed in the meantime.
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDecl.cpp?rev=315811&r1=315810&r2=315811&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Oct 14 08:59:34 2017
> @@ -1723,7 +1723,8 @@ static bool ShouldDiagnoseUnusedDecl(con
>  dyn_cast(Init);
>if (Construct && !Construct->isElidable()) {
>  CXXConstructorDecl *CD = Construct->getConstructor();
> -if (!CD->isTrivial() && !RD->hasAttr())
> +if (!CD->isTrivial() && !RD->hasAttr() &&
> +!VD->evaluateValue())
>

The evaluateValue call above causes an assertion failure on
instantiation-dependent values:
llvm/tools/clang/lib/AST/Decl.cpp:2196 in clang::APValue
*clang::VarDecl::evaluateValue(SmallVectorImpl
&) const: !Init->isValueDependent()

I'm not sure why evaluateValue uses an assertion instead of outputting a
note and returning nullptr, but the assertion can be avoided on the caller
site as well.

Working on a reduced test case...


>return false;
>}
>  }
>
> Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/warn-unused-variables.cpp?rev=315811&r1=315810&r2=315811&view=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Sat Oct 14 08:59:34
> 2017
> @@ -1,4 +1,5 @@
>  // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label
> -Wno-c++1y-extensions -verify %s
> +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label
> -Wno-c++1y-extensions -verify -std=c++11 %s
>  template void f() {
>T t;
>t = 17;
> @@ -194,3 +195,35 @@ void test() {
>  }
>
>  }
> +
> +#if __cplusplus >= 201103L
> +namespace with_constexpr {
> +template 
> +struct Literal {
> +  T i;
> +  Literal() = default;
> +  constexpr Literal(T i) : i(i) {}
> +};
> +
> +struct NoLiteral {
> +  int i;
> +  NoLiteral() = default;
> +  constexpr NoLiteral(int i) : i(i) {}
> +  ~NoLiteral() {}
> +};
> +
> +static Literal gl1;  // expected-warning {{unused variable
> 'gl1'}}
> +static Literal gl2(1);   // expected-warning {{unused variable
> 'gl2'}}
> +static const Literal gl3(0); // expected-warning {{unused variable
> 'gl3'}}
> +
> +template 
> +void test(int i) {
> +  Literal l1; // expected-warning {{unused variable 'l1'}}
> +  Literal l2(42); // expected-warning {{unused variable 'l2'}}
> +  Literal l3(i);  // no-warning
> +  Literal l4(0);// no-warning
> +  NoLiteral nl1;   // no-warning
> +  NoLiteral nl2(42);   // no-warning
> +}
> +}
> +#endif
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r315811 - Re-land r315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."

2017-10-19 Thread Alexander Kornienko via cfe-commits
A reduced test case:

struct a {
  a(const char *);
};
template 
void c() {
  a d(b::e ? "" : "");
}

On Thu, Oct 19, 2017 at 5:57 PM, Benjamin Kramer 
wrote:

> We should check VD->getInit()->isValueDependent() before we call
> evaluateValue. I wasn't able to come up with a test case that triggers
> the assert though :(
>
> On Thu, Oct 19, 2017 at 5:45 PM, Alexander Kornienko 
> wrote:
> >
> >
> > On Sat, Oct 14, 2017 at 5:59 PM, Benjamin Kramer via cfe-commits
> >  wrote:
> >>
> >> Author: d0k
> >> Date: Sat Oct 14 08:59:34 2017
> >> New Revision: 315811
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=315811&view=rev
> >> Log:
> >> Re-land r315787, "[Sema] Warn about unused variables if we can constant
> >> evaluate the initializer."
> >>
> >> The warnings in libc++ tests were fixed in the meantime.
> >>
> >> Modified:
> >> cfe/trunk/lib/Sema/SemaDecl.cpp
> >> cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDecl.cpp?rev=315811&r1=315810&r2=315811&view=diff
> >>
> >> 
> ==
> >> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Oct 14 08:59:34 2017
> >> @@ -1723,7 +1723,8 @@ static bool ShouldDiagnoseUnusedDecl(con
> >>  dyn_cast(Init);
> >>if (Construct && !Construct->isElidable()) {
> >>  CXXConstructorDecl *CD = Construct->getConstructor();
> >> -if (!CD->isTrivial() && !RD->hasAttr())
> >> +if (!CD->isTrivial() && !RD->hasAttr() &&
> >> +!VD->evaluateValue())
> >
> >
> > The evaluateValue call above causes an assertion failure on
> > instantiation-dependent values:
> > llvm/tools/clang/lib/AST/Decl.cpp:2196 in clang::APValue
> > *clang::VarDecl::evaluateValue(SmallVectorImpl<
> clang::PartialDiagnosticAt>
> > &) const: !Init->isValueDependent()
> >
> > I'm not sure why evaluateValue uses an assertion instead of outputting a
> > note and returning nullptr, but the assertion can be avoided on the
> caller
> > site as well.
> >
> > Working on a reduced test case...
> >
> >>
> >>return false;
> >>}
> >>  }
> >>
> >> Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/warn-unused-variables.cpp?rev=315811&r1=315810&r2=315811&view=diff
> >>
> >> 
> ==
> >> --- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)
> >> +++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Sat Oct 14
> 08:59:34
> >> 2017
> >> @@ -1,4 +1,5 @@
> >>  // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label
> >> -Wno-c++1y-extensions -verify %s
> >> +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label
> >> -Wno-c++1y-extensions -verify -std=c++11 %s
> >>  template void f() {
> >>T t;
> >>t = 17;
> >> @@ -194,3 +195,35 @@ void test() {
> >>  }
> >>
> >>  }
> >> +
> >> +#if __cplusplus >= 201103L
> >> +namespace with_constexpr {
> >> +template 
> >> +struct Literal {
> >> +  T i;
> >> +  Literal() = default;
> >> +  constexpr Literal(T i) : i(i) {}
> >> +};
> >> +
> >> +struct NoLiteral {
> >> +  int i;
> >> +  NoLiteral() = default;
> >> +  constexpr NoLiteral(int i) : i(i) {}
> >> +  ~NoLiteral() {}
> >> +};
> >> +
> >> +static Literal gl1;  // expected-warning {{unused variable
> >> 'gl1'}}
> >> +static Literal gl2(1);   // expected-warning {{unused variable
> >> 'gl2'}}
> >> +static const Literal gl3(0); // expected-warning {{unused variable
> >> 'gl3'}}
> >> +
> >> +template 
> >> +void test(int i) {
> >> +  Literal l1; // expected-warning {{unused variable 'l1'}}
> >> +  Literal l2(42); // expected-warning {{unused variable 'l2'}}
> >> +  Literal l3(i);  // no-warning
> >> +  Literal l4(0);// no-warning
> >> +  NoLiteral nl1;   // no-warning
> >> +  NoLiteral nl2(42);   // no-warning
> >> +}
> >> +}
> >> +#endif
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Patch bug 27628 (clang-tidy should exit with a failure code when there are errors)

2017-10-19 Thread Alexander Kornienko via cfe-commits
The patch was lost. Could you re-attach it or even better upload to
reviews.llvm.org as described in http://llvm.org/docs/Phabricator.html?
Please make sure the patch applies cleanly to the current HEAD.

Thanks!

On Tue, Oct 17, 2017 at 9:10 PM, Friedman, Eli 
wrote:

> Sometimes people just lose track; "pinging" is normal (see
> http://llvm.org/docs/DeveloperPolicy.html#code-reviews).  And sometimes
> it's helpful to CC reviewers in the area; adding Alexander Kornienko.
>
> -Eli
>
>
> On 10/17/2017 12:03 PM, Antoni Boucher wrote:
>
>> Since the patch was redirected to the right mailing list and the subject
>> was edited, I believe everything is okay, now?
>> Is there any news?
>> Thanks.
>>
>> On Thu, Sep 28, 2017 at 06:56:57PM +, Friedman, Eli wrote:
>>
>> When you're submitting a patch, please make sure you're sending it to the
>>> right list, and the "subject" line actually describes what the patch
>>> changes; otherwise, reviewers won't notice the patch.  Optionally, you can
>>> submit a patch using Phabricator, a tool which which makes patch reviews a
>>> little easier.  See http://llvm.org/docs/Developer
>>> Policy.html#code-reviews
>>>
>>> -Eli
>>>
>>> On 9/28/2017 10:22 AM, Antoni Boucher via cfe-commits wrote:
>>>
>>> Any news on this?
>>>>
>>>> Aaand the patch itself...
>>>>>
>>>>> -K
>>>>>
>>>>> On 9/8/2017 10:32 AM, Krzysztof Parzyszek via cfe-commits wrote:
>>>>>
>>>>> This should to to cfe-commits. Redirecting.
>>>>>>
>>>>>> -Krzysztof
>>>>>>
>>>>>> On 9/8/2017 10:25 AM, Antoni Boucher via llvm-commits wrote:
>>>>>>
>>>>>> Hello. I've fixed the bug 27628: https://bugs.llvm.org/show_bug
>>>>>>> .cgi?id=27628
>>>>>>>
>>>>>>> I attached the patch.
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>>
>>>>>>> ___ llvm-commits
>>>>>>> mailing list llvm-commits at lists.llvm.org
>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>>>>> hosted by The Linux Foundation -- next part -- An
>>>>> embedded and charset-unspecified text was scrubbed... Name:
>>>>> clang-tidy-error-code.diff URL: <http://lists.llvm.org/piperma
>>>>> il/cfe-commits/attachments/20170908/8a2 98102/attachment.ksh>
>>>>>
>>>>
>>>> ___ cfe-commits mailing
>>>> list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/
>>>> mailman/listinfo/cfe-commits
>>>>
>>>
>>>
>>> -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation
>>> Center, Inc. is a member of Code Aurora Forum, a Linux Foundation
>>> Collaborative Project
>>>
>>>
> --
> Employee of Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux
> Foundation Collaborative Project
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r316539 - [Analyzer] Remove spaces inside comments mentioning the parameter name,

2017-10-25 Thread Alexander Kornienko via cfe-commits
Thanks! This should be enough for the tools, however I would also remove
all other spaces inside the argument comments for consistency with the rest
of LLVM code. Currently different ways of putting spaces inside the
argument comments are used in LLVM as follows:
  1. /*Name=*/ - in 78 files (this is also
misunderstood by clang-format)
  2. /*Name=*/ - in 2 files
  3. /*Name=*/ - in 3 files
  4. /*Name=*/ - in 693 files.

So #4 is clearly the prevalent style.

-- Alex

On Tue, Oct 24, 2017 at 5:03 PM, George Karpenkov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: george.karpenkov
> Date: Tue Oct 24 17:03:45 2017
> New Revision: 316539
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316539&view=rev
> Log:
> [Analyzer] Remove spaces inside comments mentioning the parameter name,
>
> to aid clang-tidy comprehension.
> Requested by @alexfh in https://reviews.llvm.org/D39015
>
> Modified:
> cfe/trunk/lib/Analysis/BodyFarm.cpp
>
> Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Analysis/BodyFarm.cpp?rev=316539&r1=316538&r2=316539&view=diff
> 
> ==
> --- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
> +++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue Oct 24 17:03:45 2017
> @@ -168,10 +168,10 @@ ASTMaker::makeLvalueToRvalue(const VarDe
>  ImplicitCastExpr *ASTMaker::makeImplicitCast(const Expr *Arg, QualType
> Ty,
>   CastKind CK) {
>return ImplicitCastExpr::Create(C, Ty,
> -  /* CastKind= */ CK,
> -  /* Expr= */ const_cast(Arg),
> -  /* CXXCastPath= */ nullptr,
> -  /* ExprValueKind= */ VK_RValue);
> +  /* CastKind=*/ CK,
> +  /* Expr=*/ const_cast(Arg),
> +  /* CXXCastPath=*/ nullptr,
> +  /* ExprValueKind=*/ VK_RValue);
>  }
>
>  Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
> @@ -222,7 +222,7 @@ MemberExpr *ASTMaker::makeMemberExpressi
>C, base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
>SourceLocation(), MemberDecl, FoundDecl,
>DeclarationNameInfo(MemberDecl->getDeclName(), SourceLocation()),
> -  /* TemplateArgumentListInfo= */ nullptr, MemberDecl->getType(),
> ValueKind,
> +  /* TemplateArgumentListInfo=*/ nullptr, MemberDecl->getType(),
> ValueKind,
>OK_Ordinary);
>  }
>
> @@ -231,7 +231,7 @@ ValueDecl *ASTMaker::findMemberField(con
>CXXBasePaths Paths(
>/* FindAmbiguities=*/false,
>/* RecordPaths=*/false,
> -  /* DetectVirtual= */ false);
> +  /* DetectVirtual=*/ false);
>const IdentifierInfo &II = C.Idents.get(Name);
>DeclarationName DeclName = C.DeclarationNames.getIdentifier(&II);
>
> @@ -282,14 +282,14 @@ static CallExpr *create_call_once_lambda
>assert(callOperatorDecl != nullptr);
>
>DeclRefExpr *callOperatorDeclRef =
> -  DeclRefExpr::Create(/* Ctx = */ C,
> -  /* QualifierLoc = */ NestedNameSpecifierLoc(),
> -  /* TemplateKWLoc = */ SourceLocation(),
> +  DeclRefExpr::Create(/* Ctx =*/ C,
> +  /* QualifierLoc =*/ NestedNameSpecifierLoc(),
> +  /* TemplateKWLoc =*/ SourceLocation(),
>const_cast(callOperatorDecl),
> -  /* RefersToEnclosingVariableOrCapture= */
> false,
> -  /* NameLoc = */ SourceLocation(),
> -  /* T = */ callOperatorDecl->getType(),
> -  /* VK = */ VK_LValue);
> +  /* RefersToEnclosingVariableOrCapture=*/ false,
> +  /* NameLoc =*/ SourceLocation(),
> +  /* T =*/ callOperatorDecl->getType(),
> +  /* VK =*/ VK_LValue);
>
>return new (C)
>CXXOperatorCallExpr(/*AstContext=*/C, OO_Call, callOperatorDeclRef,
> @@ -372,7 +372,7 @@ static Stmt *create_call_once(ASTContext
>  // Lambda requires callback itself inserted as a first parameter.
>  CallArgs.push_back(
>  M.makeDeclRefExpr(Callback,
> -  /* RefersToEnclosingVariableOrCapture= */
> true));
> +  /* RefersToEnclosingVariableOrCapture=*/
> true));
>  CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
> ->getType()
> ->getAs();
> @@ -429,13 +429,13 @@ static Stmt *create_call_once(ASTContext
>
>// Negation predicate.
>UnaryOperator *FlagCheck = new (C) UnaryOperator(
> -  /* input= */
> +  /* input=*/
>M.makeImplicitCast(M.makeLvalueToRvalue(Deref, DerefType),
> DerefType,
>  

Re: r337703 - [ASTMatchers] add matcher for decltypeType and its underlyingType

2018-07-24 Thread Alexander Kornienko via cfe-commits
Let's not forget to regenerate LibASTMatchersReference.html (see
clang/docs/tools/dump_ast_matchers.py).

On Mon, Jul 23, 2018 at 5:59 PM Jonas Toth via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: jonastoth
> Date: Mon Jul 23 08:59:27 2018
> New Revision: 337703
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337703&view=rev
> Log:
> [ASTMatchers] add matcher for decltypeType and its underlyingType
>
> Summary:
> This patch introduces a new matcher for `DecltypeType` and its underlying
> type
> in order to fix a bug in clang-tidy, see https://reviews.llvm.org/D48717
> for more.
>
> Reviewers: aaron.ballman, alexfh, NoQ, dcoughlin
>
> Reviewed By: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D48759
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
> cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=337703&r1=337702&r2=337703&view=diff
>
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jul 23 08:59:27
> 2018
> @@ -5111,6 +5111,18 @@ AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasVal
>  ///   matches "auto n" and "auto i"
>  extern const AstTypeMatcher autoType;
>
> +/// Matches types nodes representing C++11 decltype() types.
> +///
> +/// Given:
> +/// \code
> +///   short i = 1;
> +///   int j = 42;
> +///   decltype(i + j) result = i + j;
> +/// \endcode
> +/// decltypeType()
> +///   matches "decltype(i + j)"
> +extern const AstTypeMatcher decltypeType;
> +
>  /// Matches \c AutoType nodes where the deduced type is a specific type.
>  ///
>  /// Note: There is no \c TypeLoc for the deduced type and thus no
> @@ -5128,6 +5140,20 @@ extern const AstTypeMatcher au
>  AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
>AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
>
> +/// Matches \c DecltypeType nodes to find out the underlying type.
> +///
> +/// Given
> +/// \code
> +///   decltype(1) a = 1;
> +///   decltype(2.0) b = 2.0;
> +/// \endcode
> +/// decltypeType(hasUnderlyingType(isInteger()))
> +///   matches "auto a"
> +///
> +/// Usable as: Matcher
> +AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
> +  AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType));
> +
>  /// Matches \c FunctionType nodes.
>  ///
>  /// Given
>
> Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==
> --- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
> +++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Mon Jul 23 08:59:27
> 2018
> @@ -800,6 +800,7 @@ const AstTypeMatcher  const AstTypeMatcher variableArrayType;
>  const AstTypeMatcher atomicType;
>  const AstTypeMatcher autoType;
> +const AstTypeMatcher decltypeType;
>  const AstTypeMatcher functionType;
>  const AstTypeMatcher functionProtoType;
>  const AstTypeMatcher parenType;
>
> Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==
> --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
> +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Jul 23 08:59:27 2018
> @@ -188,6 +188,7 @@ RegistryMaps::RegistryMaps() {
>REGISTER_MATCHER(decayedType);
>REGISTER_MATCHER(decl);
>REGISTER_MATCHER(declaratorDecl);
> +  REGISTER_MATCHER(decltypeType);
>REGISTER_MATCHER(declCountIs);
>REGISTER_MATCHER(declRefExpr);
>REGISTER_MATCHER(declStmt);
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=337703&r1=337702&r2=337703&view=diff
>
> ==
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Jul 23
> 08:59:27 2018
> @@ -1206,6 +1206,12 @@ TEST(TypeMatching, MatchesAutoTypes) {
>//   autoType(hasDeducedType(isInteger();
>  }
>
> +TEST(TypeMatching, MatchesDeclTypes) {
> +  EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", decltypeType()));
> +  EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;",
> +  de

[clang-tools-extra] r338025 - [clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)

2018-07-26 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jul 26 06:13:54 2018
New Revision: 338025

URL: http://llvm.org/viewvc/llvm-project?rev=338025&view=rev
Log:
[clang-tidy] Fix llvm.org/PR38315 (support type aliases in 
modernize-shrink-to-fit)

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp?rev=338025&r1=338024&r2=338025&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ShrinkToFitCheck.cpp Thu Jul 
26 06:13:54 2018
@@ -43,8 +43,8 @@ void ShrinkToFitCheck::registerMatchers(
 
   Finder->addMatcher(
   cxxMemberCallExpr(
-  on(hasType(namedDecl(
-  hasAnyName("std::basic_string", "std::deque", "std::vector",
+  on(hasType(hasCanonicalType(hasDeclaration(namedDecl(
+  hasAnyName("std::basic_string", "std::deque", 
"std::vector")),
   callee(cxxMethodDecl(hasName("swap"))),
   has(ignoringParenImpCasts(memberExpr(hasDescendant(CopyCtorCall,
   hasArgument(0, SwapParam.bind("ContainerToShrink")),

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp?rev=338025&r1=338024&r2=338025&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp Thu Jul 
26 06:13:54 2018
@@ -72,3 +72,16 @@ void h() {
   // CHECK-FIXES: {{^  }}COPY_AND_SWAP_INT_VEC(v);{{$}}
 }
 
+void PR38315() {
+  typedef std::vector Vector;
+  Vector v;
+  Vector(v).swap(v);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should
+  // CHECK-FIXES: {{^  }}v.shrink_to_fit();{{$}}
+
+  using Vector2 = std::vector;
+  Vector2 v2;
+  Vector2(v2).swap(v2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should
+  // CHECK-FIXES: {{^  }}v2.shrink_to_fit();{{$}}
+}


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


Re: r338259 - [analyzer] Add support for more invalidating functions in InnerPointerChecker.

2018-08-02 Thread Alexander Kornienko via cfe-commits
On Mon, Jul 30, 2018 at 5:44 PM Reka Kovacs via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rkovacs
> Date: Mon Jul 30 08:43:45 2018
> New Revision: 338259
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338259&view=rev
> Log:
> [analyzer] Add support for more invalidating functions in
> InnerPointerChecker.
>
> According to the standard, pointers referring to the elements of a
> `basic_string` may be invalidated if they are used as an argument to
> any standard library function taking a reference to non-const
> `basic_string` as an argument. This patch makes InnerPointerChecker warn
> for these cases.
>
> Differential Revision: https://reviews.llvm.org/D49656
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
> cfe/trunk/test/Analysis/inner-pointer.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338259&r1=338258&r2=338259&view=diff
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Mon Jul
> 30 08:43:45 2018
> @@ -91,37 +91,53 @@ public:
>  ReserveFn("reserve"), ResizeFn("resize"),
>  ShrinkToFitFn("shrink_to_fit"), SwapFn("swap") {}
>
> -  /// Check whether the function called on the container object is a
> -  /// member function that potentially invalidates pointers referring
> -  /// to the objects's internal buffer.
> -  bool mayInvalidateBuffer(const CallEvent &Call) const;
> -
> -  /// Record the connection between the symbol returned by c_str() and the
> -  /// corresponding string object region in the ProgramState. Mark the
> symbol
> -  /// released if the string object is destroyed.
> +  /// Check if the object of this member function call is a
> `basic_string`.
> +  bool isCalledOnStringObject(const CXXInstanceCall *ICall) const;
> +
> +  /// Check whether the called member function potentially invalidates
> +  /// pointers referring to the container object's inner buffer.
> +  bool isInvalidatingMemberFunction(const CallEvent &Call) const;
> +
> +  /// Mark pointer symbols associated with the given memory region
> released
> +  /// in the program state.
> +  void markPtrSymbolsReleased(const CallEvent &Call, ProgramStateRef
> State,
> +  const MemRegion *ObjRegion,
> +  CheckerContext &C) const;
> +
> +  /// Standard library functions that take a non-const `basic_string`
> argument by
> +  /// reference may invalidate its inner pointers. Check for these cases
> and
> +  /// mark the pointers released.
> +  void checkFunctionArguments(const CallEvent &Call, ProgramStateRef
> State,
> +  CheckerContext &C) const;
> +
> +  /// Record the connection between raw pointers referring to a container
> +  /// object's inner buffer and the object's memory region in the program
> state.
> +  /// Mark potentially invalidated pointers released.
>void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
>
> -  /// Clean up the ProgramState map.
> +  /// Clean up the program state map.
>void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
>  };
>
>  } // end anonymous namespace
>
> -// [string.require]
> -//
> -// "References, pointers, and iterators referring to the elements of a
> -// basic_string sequence may be invalidated by the following uses of that
> -// basic_string object:
> -//
> -// -- TODO: As an argument to any standard library function taking a
> reference
> -// to non-const basic_string as an argument. For example, as an argument
> to
> -// non-member functions swap(), operator>>(), and getline(), or as an
> argument
> -// to basic_string::swap().
> -//
> -// -- Calling non-const member functions, except operator[], at, front,
> back,
> -// begin, rbegin, end, and rend."
> -//
> -bool InnerPointerChecker::mayInvalidateBuffer(const CallEvent &Call)
> const {
> +bool InnerPointerChecker::isCalledOnStringObject(
> +const CXXInstanceCall *ICall) const {
> +  const auto *ObjRegion =
> +
> dyn_cast_or_null(ICall->getCXXThisVal().getAsRegion());
> +  if (!ObjRegion)
> +return false;
> +
> +  QualType ObjTy = ObjRegion->getValueType();
> +  if (ObjTy.isNull() ||
> +  ObjTy->getAsCXXRecordDecl()->getName() != "basic_string")
>

We observe crashes on this line. I'm working on an isolated repro, but you
could probably try to construct one yourself (I
suppose, getAsCXXRecordDecl() can return null here).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r338775 - [analyzer] Add a safety check to InnerPointerChecker.

2018-08-03 Thread Alexander Kornienko via cfe-commits
On Fri, Aug 3, 2018 at 12:20 AM Reka Kovacs via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rkovacs
> Date: Thu Aug  2 15:19:57 2018
> New Revision: 338775
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338775&view=rev
> Log:
> [analyzer] Add a safety check to InnerPointerChecker.
>
> Do not crash if the CXXRecordDecl of an object is not available.
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338775&r1=338774&r2=338775&view=diff
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Thu Aug
> 2 15:19:57 2018
> @@ -129,8 +129,11 @@ bool InnerPointerChecker::isCalledOnStri
>  return false;
>
>QualType ObjTy = ObjRegion->getValueType();
> -  if (ObjTy.isNull() ||
> -  ObjTy->getAsCXXRecordDecl()->getName() != "basic_string")
> +  if (ObjTy.isNull())
> +return false;
> +
> +  CXXRecordDecl *Decl = ObjTy->getAsCXXRecordDecl();
> +  if (!Decl || Decl->getName() != "basic_string")
>  return false;
>
>return true;
>

Thanks for the fix! An improvement suggestion:
return Decl && Decl->getName() == "basic_string";


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


Re: r338259 - [analyzer] Add support for more invalidating functions in InnerPointerChecker.

2018-08-03 Thread Alexander Kornienko via cfe-commits
Thanks for the prompt fix, it solved the problem.

In case you want to add a regression test, this is what I came up with:
$ cat test-isCalledOnStringObject.cc
char *c();
class B {};
void d() {
  B g, *h;
  *(void **)&h = c() + 1;
  *h = g;
}
$ ./clang-tidy -checks=-*,clang-analyzer* test-isCalledOnStringObject.cc --
-std=c++11
@ 0x5640f3e56b85 32  clang::DeclarationName::isIdentifier()
@ 0x5640f3ebaca3 80  clang::NamedDecl::getName()
@ 0x5640f9f7e56b336  (anonymous
namespace)::InnerPointerChecker::isCalledOnStringObject()
@ 0x5640f9f7e0ef288  (anonymous
namespace)::InnerPointerChecker::checkPostCall()
@ 0x5640f9f7e080 48
clang::ento::check::PostCall::_checkCall<>()
@ 0x5640fa2d5c12 64  clang::ento::CheckerFn<>::operator()()
@ 0x5640fa2c82d8208  (anonymous
namespace)::CheckCallContext::runChecker()
@ 0x5640fa2c4d6c384  expandGraphWithCheckers<>()
@ 0x5640fa2c4acb208
clang::ento::CheckerManager::runCheckersForCallEvent()
@ 0x5640fa32fdc8 80
clang::ento::CheckerManager::runCheckersForPostCall()
@ 0x5640fa332ff3336  clang::ento::ExprEngine::evalCall()
@ 0x5640fa332e89400
clang::ento::ExprEngine::VisitCallExpr()
@ 0x5640fa2ef8cb   4304  clang::ento::ExprEngine::Visit()
@ 0x5640fa2ec38c464  clang::ento::ExprEngine::ProcessStmt()
@ 0x5640fa2ec079208
clang::ento::ExprEngine::processCFGElement()
@ 0x5640fa31d8ff128
clang::ento::CoreEngine::HandlePostStmt()
@ 0x5640fa31d208496
clang::ento::CoreEngine::dispatchWorkItem()
@ 0x5640fa31cdbb544
clang::ento::CoreEngine::ExecuteWorkList()
@ 0x5640f9c466b4 80
clang::ento::ExprEngine::ExecuteWorkList()


On Fri, Aug 3, 2018 at 12:28 AM Réka Nikolett Kovács 
wrote:

> Thanks for the notice. Have you managed to get the repro? I haven't
> succeeded in constructing one yet, but I've committed a check for the
> CXXRecordDecl. I hope that fixes the crashes.
>
> Alexander Kornienko  ezt írta (időpont: 2018. aug. 2.,
> Cs, 11:07):
>
>>
>>
>> On Mon, Jul 30, 2018 at 5:44 PM Reka Kovacs via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rkovacs
>>> Date: Mon Jul 30 08:43:45 2018
>>> New Revision: 338259
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=338259&view=rev
>>> Log:
>>> [analyzer] Add support for more invalidating functions in
>>> InnerPointerChecker.
>>>
>>> According to the standard, pointers referring to the elements of a
>>> `basic_string` may be invalidated if they are used as an argument to
>>> any standard library function taking a reference to non-const
>>> `basic_string` as an argument. This patch makes InnerPointerChecker warn
>>> for these cases.
>>>
>>> Differential Revision: https://reviews.llvm.org/D49656
>>>
>>> Modified:
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
>>> cfe/trunk/test/Analysis/inner-pointer.cpp
>>>
>>> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338259&r1=338258&r2=338259&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
>>> (original)
>>> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Mon
>>> Jul 30 08:43:45 2018
>>> @@ -91,37 +91,53 @@ public:
>>>  ReserveFn("reserve"), ResizeFn("resize"),
>>>  ShrinkToFitFn("shrink_to_fit"), SwapFn("swap") {}
>>>
>>> -  /// Check whether the function called on the container object is a
>>> -  /// member function that potentially invalidates pointers referring
>>> -  /// to the objects's internal buffer.
>>> -  bool mayInvalidateBuffer(const CallEvent &Call) const;
>>> -
>>> -  /// Record the connection between the symbol returned by c_str() and
>>> the
>>> -  /// corresponding string object region in the ProgramState. Mark the
>>> symbol
>>> -  /// released if the string object is destroyed.
>>> +  /// Check if the object of this member function call is a
>>> `basic_string`.
>>> +  bool isCalledOnStringObject(const

Re: r338667 - [analyzer] Extend NoStoreFuncVisitor to follow fields.

2018-08-03 Thread Alexander Kornienko via cfe-commits
On Thu, Aug 2, 2018 at 4:03 AM George Karpenkov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: george.karpenkov
> Date: Wed Aug  1 19:02:40 2018
> New Revision: 338667
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338667&view=rev
> Log:
> [analyzer] Extend NoStoreFuncVisitor to follow fields.
>
> rdar://39701823
>
> Differential Revision: https://reviews.llvm.org/D49901
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.c
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=338667&r1=338666&r2=338667&view=diff
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug  1
> 19:02:40 2018
> @@ -269,10 +269,14 @@ namespace {
>  /// pointer dereference outside.
>  class NoStoreFuncVisitor final : public BugReporterVisitor {
>const SubRegion *RegionOfInterest;
> +  MemRegionManager &MmrMgr;
>const SourceManager &SM;
>const PrintingPolicy &PP;
> -  static constexpr const char *DiagnosticsMsg =
> -  "Returning without writing to '";
> +
> +  /// Recursion limit for dereferencing fields when looking for the
> +  /// region of interest.
> +  /// The limit of two indicates that we will dereference fields only
> once.
> +  static const unsigned DEREFERENCE_LIMIT = 2;
>
>/// Frames writing into \c RegionOfInterest.
>/// This visitor generates a note only if a function does not write into
> @@ -285,15 +289,17 @@ class NoStoreFuncVisitor final : public
>llvm::SmallPtrSet FramesModifyingRegion;
>llvm::SmallPtrSet
> FramesModifyingCalculated;
>
> +  using RegionVector = SmallVector;
>  public:
>NoStoreFuncVisitor(const SubRegion *R)
> -  : RegionOfInterest(R),
> -SM(R->getMemRegionManager()->getContext().getSourceManager()),
> -PP(R->getMemRegionManager()->getContext().getPrintingPolicy()) {}
> +  : RegionOfInterest(R), MmrMgr(*R->getMemRegionManager()),
> +SM(MmrMgr.getContext().getSourceManager()),
> +PP(MmrMgr.getContext().getPrintingPolicy()) {}
>
>void Profile(llvm::FoldingSetNodeID &ID) const override {
>  static int Tag = 0;
>  ID.AddPointer(&Tag);
> +ID.AddPointer(RegionOfInterest);
>}
>
>std::shared_ptr VisitNode(const ExplodedNode *N,
> @@ -307,48 +313,69 @@ public:
>  auto CallExitLoc = N->getLocationAs();
>
>  // No diagnostic if region was modified inside the frame.
> -if (!CallExitLoc)
> +if (!CallExitLoc || isRegionOfInterestModifiedInFrame(N))
>return nullptr;
>
>  CallEventRef<> Call =
>  BRC.getStateManager().getCallEventManager().getCaller(SCtx,
> State);
>
> +if (SM.isInSystemHeader(Call->getDecl()->getSourceRange().getBegin()))
> +  return nullptr;
> +
>  // Region of interest corresponds to an IVar, exiting a method
>  // which could have written into that IVar, but did not.
> -if (const auto *MC = dyn_cast(Call))
> -  if (const auto *IvarR = dyn_cast(RegionOfInterest))
> -if
> (potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
> -  IvarR->getDecl()) &&
> -!isRegionOfInterestModifiedInFrame(N))
> -  return notModifiedMemberDiagnostics(
> -  Ctx, *CallExitLoc, Call,
> MC->getReceiverSVal().getAsRegion());
> +if (const auto *MC = dyn_cast(Call)) {
> +  if (const auto *IvarR = dyn_cast(RegionOfInterest))
> {
> +const MemRegion *SelfRegion = MC->getReceiverSVal().getAsRegion();
> +if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
> +
> potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
> +  IvarR->getDecl()))
> +  return notModifiedDiagnostics(Ctx, *CallExitLoc, Call, {},
> SelfRegion,
> +"self",
> /*FirstIsReferenceType=*/false,
> +1);
> +  }
> +}
>
>  if (const auto *CCall = dyn_cast(Call)) {
>const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
>if (RegionOfInterest->isSubRegionOf(ThisR)
> -  && !CCall->getDecl()->isImplicit()
> -  && !isRegionOfInterestModifiedInFrame(N))
> -return notModifiedMemberDiagnostics(Ctx, *CallExitLoc, Call,
> ThisR);
> +  && !CCall->getDecl()->isImplicit())
> +return notModifiedDiagnostics(Ctx, *CallExitLoc, Call, {}, ThisR,
> +  "this",
> +  /*FirstIsReferenceType=*/false, 1);

Re: [clang-tools-extra] r303884 - [Documentation] Mention hicpp check group in Clang-tidy main document.

2017-05-25 Thread Alexander Kornienko via cfe-commits
On 25 May 2017 19:22, "Eugene Zelenko via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: eugenezelenko
Date: Thu May 25 12:22:29 2017
New Revision: 303884

URL: http://llvm.org/viewvc/llvm-project?rev=303884&view=rev
Log:
[Documentation] Mention hicpp check group in Clang-tidy main document.

Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
docs/clang-tidy/index.rst?rev=303884&r1=303883&r2=303884&view=diff

==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Thu May 25 12:22:29
2017
@@ -59,7 +59,8 @@ Name prefixDescription
 ``cert-``  Checks related to CERT Secure Coding Guidelines.
 ``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
 ``clang-analyzer-``Clang Static Analyzer checks.
-``google-``Checks related to the Google coding conventions.
+``google-``Checks related to Google coding conventions.


Could you explain why you think that the article should be omitted here?
(Maybe a native speaker could chime in? ;)

+``hicpp-`` Checks related to High Integrity C++ Coding
Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently
"modern"
@@ -652,7 +653,7 @@ The script provides multiple configurati
 * To restrict the files examined you can provide one or more regex
arguments
   that the file names are matched against.
   ``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze
clang-tidy
-  checkers. It may also be necessary to restrict the header files warnings
are
+  checks. It may also be necessary to restrict the header files warnings
are
   displayed from using the ``-header-filter`` flag. It has the same
behavior
   as the corresponding :program:`clang-tidy` flag.



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


[clang-tools-extra] r304154 - [clang-tidy] Use getLocalOrGlobal for the StrictMode option

2017-05-29 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon May 29 08:59:27 2017
New Revision: 304154

URL: http://llvm.org/viewvc/llvm-project?rev=304154&view=rev
Log:
[clang-tidy] Use getLocalOrGlobal for the StrictMode option

Modified:
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp?rev=304154&r1=304153&r2=304154&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp Mon 
May 29 08:59:27 2017
@@ -108,7 +108,8 @@ static bool isPossiblyBitMask(const Enum
 
 SuspiciousEnumUsageCheck::SuspiciousEnumUsageCheck(StringRef Name,
ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), StrictMode(Options.get("StrictMode", 0)) 
{}
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", 0)) {}
 
 void SuspiciousEnumUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
   Options.store(Opts, "StrictMode", StrictMode);

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp?rev=304154&r1=304153&r2=304154&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
 Mon May 29 08:59:27 2017
@@ -24,7 +24,8 @@ void InefficientStringConcatenationCheck
 
 InefficientStringConcatenationCheck::InefficientStringConcatenationCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), StrictMode(Options.get("StrictMode", 0)) 
{}
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", 0)) {}
 
 void InefficientStringConcatenationCheck::registerMatchers(
 MatchFinder *Finder) {


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


r304302 - Enable the ARM Neon intrinsics test by default.

2017-05-31 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed May 31 09:35:50 2017
New Revision: 304302

URL: http://llvm.org/viewvc/llvm-project?rev=304302&view=rev
Log:
Enable the ARM Neon intrinsics test by default.

The test being marked 'REQUIRES: long-tests' doesn't make sense. It's not the
first time the test is broken without being noticed by the committer. If the
test is too long, it should be shortened, split in multiple ones or removed
altogether. Keeping it as is is actively harmful.
(BTW, on my machine `ninja check-clang` takes 90-92 seconds with and without
this test. The difference in times is below the spread caused by random
factors.)

Modified:
cfe/trunk/test/CodeGen/arm_neon_intrinsics.c

Modified: cfe/trunk/test/CodeGen/arm_neon_intrinsics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_neon_intrinsics.c?rev=304302&r1=304301&r2=304302&view=diff
==
--- cfe/trunk/test/CodeGen/arm_neon_intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/arm_neon_intrinsics.c Wed May 31 09:35:50 2017
@@ -3,8 +3,6 @@
 // RUN:  -disable-O0-optnone -emit-llvm -o - %s \
 // RUN:  | opt -S -mem2reg | FileCheck %s
 
-// REQUIRES: long-tests
-
 #include 
 
 // CHECK-LABEL: @test_vaba_s8(


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


r304408 - Make the clang-cl test less restrictive.

2017-06-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jun  1 06:41:21 2017
New Revision: 304408

URL: http://llvm.org/viewvc/llvm-project?rev=304408&view=rev
Log:
Make the clang-cl test less restrictive.

Make the test less restrictive to allow directory layout used in our test setup.

Modified:
cfe/trunk/test/Driver/cl-include.c

Modified: cfe/trunk/test/Driver/cl-include.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-include.c?rev=304408&r1=304407&r2=304408&view=diff
==
--- cfe/trunk/test/Driver/cl-include.c (original)
+++ cfe/trunk/test/Driver/cl-include.c Thu Jun  1 06:41:21 2017
@@ -2,10 +2,10 @@
 // command-line option, e.g. on Mac where %s is commonly under /Users.
 
 // RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=BUILTIN
-// BUILTIN: "-internal-isystem" "{{.*lib.*clang.*[0-9]\.[0-9].*include}}"
+// BUILTIN: "-internal-isystem" "{{.*lib.*clang.*include}}"
 
 // RUN: %clang_cl -nobuiltininc -### -- %s 2>&1 | FileCheck %s 
--check-prefix=NOBUILTIN
-// NOBUILTIN-NOT: "-internal-isystem" "{{.*lib.*clang.*[0-9]\.[0-9].*include}}"
+// NOBUILTIN-NOT: "-internal-isystem" "{{.*lib.*clang.*include}}"
 
 // RUN: env INCLUDE=/my/system/inc %clang_cl -### -- %s 2>&1 | FileCheck %s 
--check-prefix=STDINC
 // STDINC: "-internal-isystem" "/my/system/inc"


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


[clang-tools-extra] r304570 - [clang-tidy] check for __func__/__FUNCTION__ in lambdas

2017-06-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jun  2 12:36:32 2017
New Revision: 304570

URL: http://llvm.org/viewvc/llvm-project?rev=304570&view=rev
Log:
[clang-tidy] check for __func__/__FUNCTION__ in lambdas

Add a clang-tidy check for using func__/FUNCTION__ inside lambdas. This
evaluates to the string operator(), which is almost never useful and almost
certainly not what the author intended.

Patch by Bryce Liu!

Differential Revision: https://reviews.llvm.org/D33497

Added:
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-lambda-function-name.rst
clang-tools-extra/trunk/test/clang-tidy/misc-lambda-function-name.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

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=304570&r1=304569&r2=304570&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Fri Jun  2 12:36:32 
2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyMiscModule
   ArgumentCommentCheck.cpp
   AssertSideEffectCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
+  LambdaFunctionNameCheck.cpp
   MisplacedConstCheck.cpp
   UnconventionalAssignOperatorCheck.cpp
   BoolPointerImplicitConversionCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp?rev=304570&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp Fri Jun 
 2 12:36:32 2017
@@ -0,0 +1,99 @@
+//===--- LambdaFunctionNameCheck.cpp - 
clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "LambdaFunctionNameCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+namespace {
+
+// Keep track of macro expansions that contain both __FILE__ and __LINE__. If
+// such a macro also uses __func__ or __FUNCTION__, we don't want to issue a
+// warning because __FILE__ and __LINE__ may be useful even if __func__ or
+// __FUNCTION__ is not, especially if the macro could be used in the context of
+// either a function body or a lambda body.
+class MacroExpansionsWithFileAndLine : public PPCallbacks {
+public:
+  explicit MacroExpansionsWithFileAndLine(
+  LambdaFunctionNameCheck::SourceRangeSet *SME)
+  : SuppressMacroExpansions(SME) {}
+
+  void MacroExpands(const Token &MacroNameTok,
+const MacroDefinition &MD, SourceRange Range,
+const MacroArgs *Args) override {
+bool has_file = false;
+bool has_line = false;
+for (const auto& T : MD.getMacroInfo()->tokens()) {
+  if (T.is(tok::identifier)) {
+StringRef IdentName = T.getIdentifierInfo()->getName();
+if (IdentName == "__FILE__") {
+  has_file = true;
+} else if (IdentName == "__LINE__") {
+  has_line = true;
+}
+  }
+}
+if (has_file && has_line) {
+  SuppressMacroExpansions->insert(Range);
+}
+  }
+
+private:
+  LambdaFunctionNameCheck::SourceRangeSet* SuppressMacroExpansions;
+};
+
+} // namespace
+
+void LambdaFunctionNameCheck::registerMatchers(MatchFinder *Finder) {
+  // Match on PredefinedExprs inside a lambda.
+  Finder->addMatcher(predefinedExpr(hasAncestor(lambdaExpr())).bind("E"),
+ this);
+}
+
+void LambdaFunctionNameCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+  Compiler.getPreprocessor().addPPCallbacks(
+  llvm::make_unique(
+  &SuppressMacroExpansions));
+}
+
+void LambdaFunctionNameCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *E = Result.Nodes.getNodeAs("E");
+  if (E->getIdentType() != PredefinedExpr::Func &&
+  E->getIdentType() != PredefinedExpr::Function) {
+// We don't care about other PredefinedExprs.
+return;
+  }
+  if (E->getLocation().isMacroID

[clang-tools-extra] r304581 - Fix formatting in docs.

2017-06-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jun  2 13:44:32 2017
New Revision: 304581

URL: http://llvm.org/viewvc/llvm-project?rev=304581&view=rev
Log:
Fix formatting in docs.

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=304581&r1=304580&r2=304581&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Jun  2 13:44:32 2017
@@ -71,16 +71,15 @@ Improvements to clang-tidy
   
`_
 check
 
   Allow custom memory management functions to be considered as well.
-  
+
 - New `misc-forwarding-reference-overload
   
`_
 check
 
   Finds perfect forwarding constructors that can unintentionally hide copy or 
move constructors.
 
-- New `misc-lambda-function-name
-   
`_
 check
+- New `misc-lambda-function-name 
`_
 check
 
-   Finds uses of ``__func__`` or ``__FUNCTION__`` inside lambdas.
+  Finds uses of ``__func__`` or ``__FUNCTION__`` inside lambdas.
 
 - New `modernize-replace-random-shuffle
   
`_
 check
@@ -92,7 +91,7 @@ Improvements to clang-tidy
 
   Finds and replaces explicit calls to the constructor in a return statement by
   a braced initializer list so that the return type is not needlessly repeated.
-  
+
 - Improved `modernize-use-emplace
   `_ 
check
 
@@ -106,7 +105,7 @@ Improvements to clang-tidy
 
   Finds possible inefficient vector operations in for loops that may cause
   unnecessary memory reallocations.
-  
+
 - Added `ParameterThreshold` to `readability-function-size
   
`_
 check
 
@@ -116,10 +115,10 @@ Improvements to clang-tidy
   
`_
 check
 
   Finds misleading indentation where braces should be introduced or the code 
should be reformatted.
-  
+
 - Support clang-formatting of the code around applied fixes (``-format-style``
   command-line option).
-  
+
 - New `hicpp` module
 
   Adds checks that implement the `High Integrity C++ Coding Standard 
`_ and other safety


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


[clang-tools-extra] r304583 - [clang-tidy] Add `const` to operator() to fix a warning.

2017-06-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jun  2 13:47:50 2017
New Revision: 304583

URL: http://llvm.org/viewvc/llvm-project?rev=304583&view=rev
Log:
[clang-tidy] Add `const` to operator() to fix a warning.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h?rev=304583&r1=304582&r2=304583&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h Fri Jun  
2 13:47:50 2017
@@ -25,7 +25,7 @@ namespace misc {
 class LambdaFunctionNameCheck : public ClangTidyCheck {
 public:
   struct SourceRangeLessThan {
-bool operator()(const SourceRange &L, const SourceRange &R) {
+bool operator()(const SourceRange &L, const SourceRange &R) const {
   if (L.getBegin() == R.getBegin()) {
 return L.getEnd() < R.getEnd();
   }


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


Re: [clang-tools-extra] r304583 - [clang-tidy] Add `const` to operator() to fix a warning.

2017-06-06 Thread Alexander Kornienko via cfe-commits
On Mon, Jun 5, 2017 at 7:11 PM, David Blaikie  wrote:

> what was the warning?
>

I don't remember the exact warning text, but the idea was that a non-const
operator() could not be called. The change is reasonable in any case: the
operator() here has no reason to be non-const.


>
> On Fri, Jun 2, 2017 at 11:48 AM Alexander Kornienko via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: alexfh
>> Date: Fri Jun  2 13:47:50 2017
>> New Revision: 304583
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=304583&view=rev
>> Log:
>> [clang-tidy] Add `const` to operator() to fix a warning.
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/misc/
>> LambdaFunctionNameCheck.h
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
>> trunk/clang-tidy/misc/LambdaFunctionNameCheck.h?rev=
>> 304583&r1=304582&r2=304583&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
>> Fri Jun  2 13:47:50 2017
>> @@ -25,7 +25,7 @@ namespace misc {
>>  class LambdaFunctionNameCheck : public ClangTidyCheck {
>>  public:
>>struct SourceRangeLessThan {
>> -bool operator()(const SourceRange &L, const SourceRange &R) {
>> +bool operator()(const SourceRange &L, const SourceRange &R) const {
>>if (L.getBegin() == R.getBegin()) {
>>  return L.getEnd() < R.getEnd();
>>}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r304811 - [clang-tidy] misc-inaccurate-erase: support call by pointer

2017-06-06 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jun  6 12:49:45 2017
New Revision: 304811

URL: http://llvm.org/viewvc/llvm-project?rev=304811&view=rev
Log:
[clang-tidy] misc-inaccurate-erase: support call by pointer

+ replace matchesName calls with more efficient alternatives.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp?rev=304811&r1=304810&r2=304811&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp Tue Jun  6 
12:49:45 2017
@@ -18,6 +18,10 @@ namespace clang {
 namespace tidy {
 namespace misc {
 
+namespace {
+AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
+}
+
 void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++; the functionality currently does not
   // provide any benefit to other languages, despite being benign.
@@ -30,13 +34,14 @@ void InaccurateEraseCheck::registerMatch
.bind("InaccEndCall",
anything()));
 
+  const auto DeclInStd = decl(isInStdNamespace());
   Finder->addMatcher(
   cxxMemberCallExpr(
-  on(hasType(namedDecl(matchesName("^::std::",
+  on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd,
   callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1),
   hasArgument(0, has(ignoringParenImpCasts(
- callExpr(callee(functionDecl(matchesName(
-  "^::std::(remove(_if)?|unique)$"))),
+ callExpr(callee(functionDecl(hasAnyName(
+  "remove", "remove_if", "unique"))),
   CheckForEndCall)
  .bind("InaccAlgCall",
   unless(isInTemplateInstantiation()))

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp?rev=304811&r1=304810&r2=304811&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp Tue Jun  
6 12:49:45 2017
@@ -56,6 +56,12 @@ int main() {
   // CHECK-FIXES: {{^  }}v.erase(remove(v.begin(), v.end(), 10), v.end());{{$}}
   v.erase(remove(v.begin(), v.end(), 20), v.end());
 
+  auto *p = &v;
+  p->erase(remove(p->begin(), p->end(), 11));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
+  // CHECK-FIXES: {{^  }}p->erase(remove(p->begin(), p->end(), 11), 
p->end());{{$}}
+
+
   // Fix is not trivial.
   auto it = v.end();
   v.erase(remove(v.begin(), it, 10));


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


[clang-tools-extra] r304879 - [clang-tidy] Make misc-inaccurate-erase work with real C++11 containers.

2017-06-07 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Jun  7 03:25:51 2017
New Revision: 304879

URL: http://llvm.org/viewvc/llvm-project?rev=304879&view=rev
Log:
[clang-tidy] Make misc-inaccurate-erase work with real C++11 containers.

The check failed to match iterator->const_iterator conversion that is happening
at least when using the libstdc++'s vector. We might want to make it match even
more flexible patterns, if we see more false negatives.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp?rev=304879&r1=304878&r2=304879&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp Wed Jun  7 
03:25:51 2017
@@ -28,38 +28,40 @@ void InaccurateEraseCheck::registerMatch
   if (!getLangOpts().CPlusPlus)
 return;
 
-  const auto CheckForEndCall = hasArgument(
-  1, anyOf(cxxConstructExpr(has(ignoringParenImpCasts(
-   cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"
-   .bind("InaccEndCall",
-   anything()));
+  const auto EndCall =
+  callExpr(
+  callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),
+  hasArgument(
+  1,
+  anyOf(cxxConstructExpr(has(ignoringImplicit(
+
cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"
+.bind("end",
+anything(
+  .bind("alg");
 
   const auto DeclInStd = decl(isInStdNamespace());
   Finder->addMatcher(
   cxxMemberCallExpr(
   on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd,
   callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1),
-  hasArgument(0, has(ignoringParenImpCasts(
- callExpr(callee(functionDecl(hasAnyName(
-  "remove", "remove_if", "unique"))),
-  CheckForEndCall)
- .bind("InaccAlgCall",
+  hasArgument(0, has(ignoringImplicit(
+ anyOf(EndCall, has(ignoringImplicit(EndCall)),
   unless(isInTemplateInstantiation()))
-  .bind("InaccErase"),
+  .bind("erase"),
   this);
 }
 
 void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *MemberCall =
-  Result.Nodes.getNodeAs("InaccErase");
+  Result.Nodes.getNodeAs("erase");
   const auto *EndExpr =
-  Result.Nodes.getNodeAs("InaccEndCall");
+  Result.Nodes.getNodeAs("end");
   const SourceLocation Loc = MemberCall->getLocStart();
 
   FixItHint Hint;
 
   if (!Loc.isMacroID() && EndExpr) {
-const auto *AlgCall = Result.Nodes.getNodeAs("InaccAlgCall");
+const auto *AlgCall = Result.Nodes.getNodeAs("alg");
 std::string ReplacementText = Lexer::getSourceText(
 CharSourceRange::getTokenRange(EndExpr->getSourceRange()),
 *Result.SourceManager, getLangOpts());

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp?rev=304879&r1=304878&r2=304879&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp Wed Jun  
7 03:25:51 2017
@@ -2,12 +2,15 @@
 
 namespace std {
 template  struct vec_iterator {
-  T *ptr;
+  T ptr;
   vec_iterator operator++(int);
+
+  template 
+  vec_iterator(const vec_iterator &); // Omit enable_if<...>.
 };
 
 template  struct vector {
-  typedef vec_iterator iterator;
+  typedef vec_iterator iterator;
 
   iterator begin();
   iterator end();
@@ -16,6 +19,17 @@ template  struct vector {
   void erase(iterator, iterator);
 };
 
+template  struct vector_with_const_iterator {
+  typedef vec_iterator iterator;
+  typedef vec_iterator const_iterator;
+
+  iterator begin();
+  iterator end();
+
+  void erase(const_iterator);
+  void erase(const_iterator, const_iterator);
+};
+
 template 
 FwIt remove(FwIt begin, FwIt end, const T &val);
 
@@ -61,6 +75,10 @@ int main() {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
   // CHECK-FIXES: {{^  }}p->erase(remove(p->begin(), p->end(), 11), 
p->end());{{$}}
 
+  std::vector_with_const_iterator v2;
+  v2.erase(remove(v2.begin(), v2.end(), 12));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
+  // CHECK-FIXES: {{^  }}v2.erase(re

[clang-tools-extra] r304977 - [clang-tidy] New checker to replace dynamic exception specifications

2017-06-08 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jun  8 09:04:16 2017
New Revision: 304977

URL: http://llvm.org/viewvc/llvm-project?rev=304977&view=rev
Log:
[clang-tidy] New checker to replace dynamic exception specifications

Summary:
New checker to replace dynamic exception
specifications

This is an alternative to D18575 which relied on reparsing the decl to
find the location of dynamic exception specifications, but couldn't
deal with preprocessor conditionals correctly without reparsing the
entire file.

This approach uses D20428 to find dynamic exception specification
locations and handles all cases correctly.

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman, alexfh

Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere, 
cfe-commits, Eugene.Zelenko, etienneb

Patch by Don Hinton!

Differential Revision: https://reviews.llvm.org/D20693

Added:
clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-noexcept.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=304977&r1=304976&r2=304977&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Thu Jun  8 
09:04:16 2017
@@ -22,6 +22,7 @@ add_clang_library(clangTidyModernizeModu
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
+  UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseTransparentFunctorsCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp?rev=304977&r1=304976&r2=304977&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp Thu 
Jun  8 09:04:16 2017
@@ -28,6 +28,7 @@
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
+#include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseTransparentFunctorsCheck.h"
@@ -69,6 +70,7 @@ public:
 
CheckFactories.registerCheck("modernize-use-equals-default");
 CheckFactories.registerCheck(
 "modernize-use-equals-delete");
+CheckFactories.registerCheck("modernize-use-noexcept");
 CheckFactories.registerCheck("modernize-use-nullptr");
 CheckFactories.registerCheck("modernize-use-override");
 CheckFactories.registerCheck(

Added: clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp?rev=304977&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp Thu Jun  
8 09:04:16 2017
@@ -0,0 +1,114 @@
+//===--- UseNoexceptCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UseNoexceptCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+UseNoexceptCheck::UseNoexceptCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  NoexceptMacro(Options.get("ReplacementString", "")),
+  UseNoexceptFalse(Options.get("UseNoexceptFalse", true)) {}
+
+void UseNoexceptCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "ReplacementString", NoexceptMacro);
+  Options.store(Opts, "UseNoexceptFalse", UseNoexceptFalse);
+}
+
+void UseNoexceptCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  Finder->a

Re: [clang-tools-extra] r304977 - [clang-tidy] New checker to replace dynamic exception specifications

2017-06-08 Thread Alexander Kornienko via cfe-commits
It looks like the buildbots have exceptions turned off by default, so the
tests need to use `-fexceptions` explicitly. Testing a fix...

On Thu, Jun 8, 2017 at 11:26 PM, Galina Kistanova 
wrote:

> Hello Alexander,
>
> Couple of our builders do not like this commit:
>
> Failing Tests:
>
> Clang Tools :: clang-tidy/modernize-use-noexcept-opt.cpp
> Clang Tools :: clang-tidy/modernize-use-noexcept.cpp
>
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_
> 64-scei-ps4-ubuntu-fast/builds/12431
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_
> 64-scei-ps4-windows10pro-fast
>
> Please have a look at this?
>
> Thanks
>
> Galina
>
> On Thu, Jun 8, 2017 at 7:04 AM, Alexander Kornienko via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: alexfh
>> Date: Thu Jun  8 09:04:16 2017
>> New Revision: 304977
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=304977&view=rev
>> Log:
>> [clang-tidy] New checker to replace dynamic exception specifications
>>
>> Summary:
>> New checker to replace dynamic exception
>> specifications
>>
>> This is an alternative to D18575 which relied on reparsing the decl to
>> find the location of dynamic exception specifications, but couldn't
>> deal with preprocessor conditionals correctly without reparsing the
>> entire file.
>>
>> This approach uses D20428 to find dynamic exception specification
>> locations and handles all cases correctly.
>>
>> Reviewers: aaron.ballman, alexfh
>>
>> Reviewed By: aaron.ballman, alexfh
>>
>> Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere,
>> cfe-commits, Eugene.Zelenko, etienneb
>>
>> Patch by Don Hinton!
>>
>> Differential Revision: https://reviews.llvm.org/D20693
>>
>> Added:
>> clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.h
>> clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use
>> -noexcept.rst
>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexce
>> pt-macro.cpp
>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexce
>> pt-opt.cpp
>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>> clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>> clang-tools-extra/trunk/docs/ReleaseNotes.rst
>> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clang-tidy/modernize/CMakeLists.txt?rev=304977&r1=304976&r2=
>> 304977&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Thu Jun
>> 8 09:04:16 2017
>> @@ -22,6 +22,7 @@ add_clang_library(clangTidyModernizeModu
>>UseEmplaceCheck.cpp
>>UseEqualsDefaultCheck.cpp
>>UseEqualsDeleteCheck.cpp
>> +  UseNoexceptCheck.cpp
>>UseNullptrCheck.cpp
>>UseOverrideCheck.cpp
>>UseTransparentFunctorsCheck.cpp
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyMo
>> dule.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clang-tidy/modernize/ModernizeTidyModule.cpp?rev=304977&r1=
>> 304976&r2=304977&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>> Thu Jun  8 09:04:16 2017
>> @@ -28,6 +28,7 @@
>>  #include "UseEmplaceCheck.h"
>>  #include "UseEqualsDefaultCheck.h"
>>  #include "UseEqualsDeleteCheck.h"
>> +#include "UseNoexceptCheck.h"
>>  #include "UseNullptrCheck.h"
>>  #include "UseOverrideCheck.h"
>>  #include "UseTransparentFunctorsCheck.h"
>> @@ -69,6 +70,7 @@ public:
>>  CheckFactories.registerCheck("modern
>> ize-use-equals-default");
>>  CheckFactories.registerCheck(
>>  "modernize-use-equals-delete");
>> +CheckFactories.registerCheck("m

[clang-tools-extra] r305024 - [clang-tidy] Use -fexceptions explicitly in the tests that need exceptions.

2017-06-08 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jun  8 17:25:23 2017
New Revision: 305024

URL: http://llvm.org/viewvc/llvm-project?rev=305024&view=rev
Log:
[clang-tidy] Use -fexceptions explicitly in the tests that need exceptions.

This should fix relevant buildbot breakages.

Modified:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp?rev=305024&r1=305023&r2=305024&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-macro.cpp 
Thu Jun  8 17:25:23 2017
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
 // RUN:   -config="{CheckOptions: [{key: 
modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
-// RUN:   -- -std=c++11
+// RUN:   -- -std=c++11 -fexceptions
 
 // Example definition of NOEXCEPT -- simplified test to see if noexcept is 
supported.
 #if (__has_feature(cxx_noexcept))

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp?rev=305024&r1=305023&r2=305024&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept-opt.cpp Thu 
Jun  8 17:25:23 2017
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
 // RUN:   -config="{CheckOptions: [{key: 
modernize-use-noexcept.UseNoexceptFalse, value: 0}]}" \
-// RUN:   -- -std=c++11
+// RUN:   -- -std=c++11 -fexceptions
 
 class A {};
 class B {};

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp?rev=305024&r1=305023&r2=305024&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp Thu Jun  
8 17:25:23 2017
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
-// RUN:   -- -std=c++11
+// RUN:   -- -std=c++11 -fexceptions
 
 class A {};
 class B {};


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


[clang-tools-extra] r305057 - Revert "[clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed."

2017-06-09 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jun  9 02:34:58 2017
New Revision: 305057

URL: http://llvm.org/viewvc/llvm-project?rev=305057&view=rev
Log:
Revert "[clang-tidy] When" -fno-exceptions is used", this warning is better to 
be suppressed."

This reverts commit r304949.

https://reviews.llvm.org/D34002#775830

Modified:
clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp?rev=305057&r1=305056&r2=305057&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp 
Fri Jun  9 02:34:58 2017
@@ -20,7 +20,7 @@ namespace misc {
 void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++11; the functionality currently does not
   // provide any benefit to other languages, despite being benign.
-  if (!getLangOpts().CPlusPlus11 || !getLangOpts().CXXExceptions)
+  if (!getLangOpts().CPlusPlus11)
 return;
 
   Finder->addMatcher(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp?rev=305057&r1=305056&r2=305057&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp 
Fri Jun  9 02:34:58 2017
@@ -1,25 +1,16 @@
-// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-std=c++11 \
-// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
-// RUN:   -implicit-check-not="{{warning|error}}:"
-// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-fno-exceptions -std=c++11 \
-// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
-// RUN:   -implicit-check-not="{{warning|error}}:"
-
+// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t
 
 class A {
   A(A &&);
-  // CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
-  // CHECK-NONEXCEPTIONS-NOT: warning:
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
   A &operator=(A &&);
-  // CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: move assignment operators 
should
-  // CHECK-NONEXCEPTIONS-NOT: warning:
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
 };
 
 struct B {
   static constexpr bool kFalse = false;
   B(B &&) noexcept(kFalse);
-  // CHECK-EXCEPTIONS: :[[@LINE-1]]:20: warning: noexcept specifier on the 
move constructor evaluates to 'false' [misc-noexcept-move-constructor]
-  // CHECK-NONEXCEPTIONS-NOT: warning:
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move 
constructor evaluates to 'false' [misc-noexcept-move-constructor]
 };
 
 class OK {};


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


Re: [clang-tools-extra] r304977 - [clang-tidy] New checker to replace dynamic exception specifications

2017-06-09 Thread Alexander Kornienko via cfe-commits
Fixes committed in r305024 and r305057.

On Fri, Jun 9, 2017 at 12:07 AM, Alexander Kornienko 
wrote:

> It looks like the buildbots have exceptions turned off by default, so the
> tests need to use `-fexceptions` explicitly. Testing a fix...
>
> On Thu, Jun 8, 2017 at 11:26 PM, Galina Kistanova 
> wrote:
>
>> Hello Alexander,
>>
>> Couple of our builders do not like this commit:
>>
>> Failing Tests:
>>
>> Clang Tools :: clang-tidy/modernize-use-noexcept-opt.cpp
>> Clang Tools :: clang-tidy/modernize-use-noexcept.cpp
>>
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-
>> scei-ps4-ubuntu-fast/builds/12431
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-
>> scei-ps4-windows10pro-fast
>>
>> Please have a look at this?
>>
>> Thanks
>>
>> Galina
>>
>> On Thu, Jun 8, 2017 at 7:04 AM, Alexander Kornienko via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: alexfh
>>> Date: Thu Jun  8 09:04:16 2017
>>> New Revision: 304977
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=304977&view=rev
>>> Log:
>>> [clang-tidy] New checker to replace dynamic exception specifications
>>>
>>> Summary:
>>> New checker to replace dynamic exception
>>> specifications
>>>
>>> This is an alternative to D18575 which relied on reparsing the decl to
>>> find the location of dynamic exception specifications, but couldn't
>>> deal with preprocessor conditionals correctly without reparsing the
>>> entire file.
>>>
>>> This approach uses D20428 to find dynamic exception specification
>>> locations and handles all cases correctly.
>>>
>>> Reviewers: aaron.ballman, alexfh
>>>
>>> Reviewed By: aaron.ballman, alexfh
>>>
>>> Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere,
>>> cfe-commits, Eugene.Zelenko, etienneb
>>>
>>> Patch by Don Hinton!
>>>
>>> Differential Revision: https://reviews.llvm.org/D20693
>>>
>>> Added:
>>> clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.cpp
>>> clang-tools-extra/trunk/clang-tidy/modernize/UseNoexceptCheck.h
>>> clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use
>>> -noexcept.rst
>>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexce
>>> pt-macro.cpp
>>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexce
>>> pt-opt.cpp
>>> clang-tools-extra/trunk/test/clang-tidy/modernize-use-noexcept.cpp
>>> Modified:
>>> clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>>> clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>>> clang-tools-extra/trunk/docs/ReleaseNotes.rst
>>> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>>>
>>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>>> clang-tidy/modernize/CMakeLists.txt?rev=304977&r1=304976&r2=
>>> 304977&view=diff
>>> 
>>> ==
>>> --- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>>> (original)
>>> +++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Thu
>>> Jun  8 09:04:16 2017
>>> @@ -22,6 +22,7 @@ add_clang_library(clangTidyModernizeModu
>>>UseEmplaceCheck.cpp
>>>UseEqualsDefaultCheck.cpp
>>>UseEqualsDeleteCheck.cpp
>>> +  UseNoexceptCheck.cpp
>>>UseNullptrCheck.cpp
>>>UseOverrideCheck.cpp
>>>UseTransparentFunctorsCheck.cpp
>>>
>>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyMo
>>> dule.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>>> clang-tidy/modernize/ModernizeTidyModule.cpp?rev=304977&r1=3
>>> 04976&r2=304977&view=diff
>>> 
>>> ==
>>> --- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>>> (original)
>>> +++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>>> Thu Jun  8 09:04:16 2017
>>> @@ -28,6 +28,7 @@
>>>  #includ

Re: [clang-tools-extra] r321363 - [clang-tidy] Adding Fuchsia checker for overloaded operators

2018-01-03 Thread Alexander Kornienko via cfe-commits
There was a recent bug report related to this check. Could you take a look?
http://llvm.org/PR35803

On Fri, Dec 22, 2017 at 5:52 PM, Julie Hockett via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: juliehockett
> Date: Fri Dec 22 08:52:25 2017
> New Revision: 321363
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321363&view=rev
> Log:
> [clang-tidy] Adding Fuchsia checker for overloaded operators
>
> Adds a check to the Fuchsia module to warn if an operator is overloaded,
> except move and copy operators.
>
> See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
> reference.
>
> Differential Revision: https://reviews.llvm.org/D41363
>
> Added:
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
> clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-
> overloaded-operator.rst
> clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-
> operator.cpp
> Modified:
> clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> clang-tools-extra/trunk/docs/ReleaseNotes.rst
> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=321363&r1=
> 321362&r2=321363&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Fri Dec 22
> 08:52:25 2017
> @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
>  add_clang_library(clangTidyFuchsiaModule
>DefaultArgumentsCheck.cpp
>FuchsiaTidyModule.cpp
> +  OverloadedOperatorCheck.cpp
>VirtualInheritanceCheck.cpp
>
>LINK_LIBS
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=
> 321363&r1=321362&r2=321363&view=diff
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Fri
> Dec 22 08:52:25 2017
> @@ -11,6 +11,7 @@
>  #include "../ClangTidyModule.h"
>  #include "../ClangTidyModuleRegistry.h"
>  #include "DefaultArgumentsCheck.h"
> +#include "OverloadedOperatorCheck.h"
>  #include "VirtualInheritanceCheck.h"
>
>  using namespace clang::ast_matchers;
> @@ -25,6 +26,8 @@ public:
>void addCheckFactories(ClangTidyCheckFactories &CheckFactories)
> override {
>  CheckFactories.registerCheck(
>  "fuchsia-default-arguments");
> +CheckFactories.registerCheck(
> +"fuchsia-overloaded-operator");
>  CheckFactories.registerCheck(
>  "fuchsia-virtual-inheritance");
>}
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/
> OverloadedOperatorCheck.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321363&view=auto
> 
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> (added)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> Fri Dec 22 08:52:25 2017
> @@ -0,0 +1,39 @@
> +//===--- OverloadedOperatorCheck.cpp - clang-tidy
> --===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===--
> ===//
> +
> +#include "OverloadedOperatorCheck.h"
> +
> +using namespace clang::ast_matchers;
> +
> +namespace clang {
> +namespace tidy {
> +namespace fuchsia {
> +
> +AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
> +  if (const auto *CXXMethodNode = dyn_cast(&Node)) {
> +if (CXXMethodNode->isCopyAssignmentOperator() ||
> +CXXMethodNode->isMoveAssignmentOperator())
> +  return false;
> +  }
> +  return Node.isOverloadedOperator();
> +}
> +
> +void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
> +  Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator())
> .bind("decl"),
> + this);
> +}
> +
> +void OverloadedOperatorCheck::check(const MatchFinder::MatchResult
> &Result) {
> +  if (const auto *D = Result.Nodes.getNodeAs("decl"))
> +diag(D->getLocStart(), "cannot overload %0") << D;
> +}
> +
> +} // namespace fuchsia
> +} // namespace tidy
> +} // namespace clang
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/
> OverloadedOperatorCheck.h

Re: [clang-tools-extra] r321762 - [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

2018-01-04 Thread Alexander Kornienko via cfe-commits
Yes, would be nice to include this into 6.0.

On Wed, Jan 3, 2018 at 11:16 PM, Aaron Ballman 
wrote:

> Hans, I'd like to nominate this patch for the 6.0 branch. It fixes a
> failing assertion with new functionality; without this fix, anyone
> enabling this check and including a STL header that transitively
> includes  (which is most of them) will hit the assertion.
>
> Thanks!
>
> ~Aaron
>
> On Wed, Jan 3, 2018 at 5:10 PM, Julie Hockett via cfe-commits
>  wrote:
> > Author: juliehockett
> > Date: Wed Jan  3 14:10:11 2018
> > New Revision: 321762
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=321762&view=rev
> > Log:
> > [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc
> >
> > Updating fuchsia-overloaded-operator check to not issue warnings for
> > invalid locations.
> >
> > Fixes PR35803.
> >
> > Differential Revision: https://reviews.llvm.org/D41708
> >
> > Modified:
> > clang-tools-extra/trunk/clang-tidy/fuchsia/
> OverloadedOperatorCheck.cpp
> > clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-
> operator.cpp
> >
> > Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/
> OverloadedOperatorCheck.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?
> rev=321762&r1=321761&r2=321762&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> (original)
> > +++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> Wed Jan  3 14:10:11 2018
> > @@ -30,8 +30,12 @@ void OverloadedOperatorCheck::registerMa
> >  }
> >
> >  void OverloadedOperatorCheck::check(const MatchFinder::MatchResult
> &Result) {
> > -  if (const auto *D = Result.Nodes.getNodeAs("decl"))
> > -diag(D->getLocStart(), "cannot overload %0") << D;
> > +  const auto *D = Result.Nodes.getNodeAs("decl");
> > +  assert(D && "No FunctionDecl captured!");
> > +
> > +  SourceLocation Loc = D->getLocStart();
> > +  if (Loc.isValid())
> > +diag(Loc, "cannot overload %0") << D;
> >  }
> >
> >  } // namespace fuchsia
> >
> > Modified: clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-
> operator.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp?rev=
> 321762&r1=321761&r2=321762&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
> (original)
> > +++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
> Wed Jan  3 14:10:11 2018
> > @@ -16,3 +16,6 @@ public:
> >
> >  A operator-(const A &A1, const A &A2);
> >  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator-'
> [fuchsia-overloaded-operator]
> > +
> > +void operator delete(void*, void*) throw();
> > +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator
> delete' [fuchsia-overloaded-operator]
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322082 - Explicitly specify output file.

2018-01-09 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan  9 07:05:13 2018
New Revision: 322082

URL: http://llvm.org/viewvc/llvm-project?rev=322082&view=rev
Log:
Explicitly specify output file.

Otherwise the test fails when LLVM sources are on a read-only partition.

Modified:
cfe/trunk/test/CodeGen/x86-cf-protection.c

Modified: cfe/trunk/test/CodeGen/x86-cf-protection.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86-cf-protection.c?rev=322082&r1=322081&r2=322082&view=diff
==
--- cfe/trunk/test/CodeGen/x86-cf-protection.c (original)
+++ cfe/trunk/test/CodeGen/x86-cf-protection.c Tue Jan  9 07:05:13 2018
@@ -1,5 +1,5 @@
-// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -triple 
i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s 
--check-prefix=RETURN
-// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -triple 
i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s 
--check-prefix=BRANCH
+// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple 
i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s 
--check-prefix=RETURN
+// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple 
i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s 
--check-prefix=BRANCH
 
 // RETURN: error: option 'cf-protection=return' cannot be specified without 
'-mshstk'
 // BRANCH: error: option 'cf-protection=branch' cannot be specified without 
'-mibt'


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


[clang-tools-extra] r322274 - [clang-tidy] Fix google-readability-namespace-comments handling of C++17 nested namespaces

2018-01-11 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jan 11 05:00:28 2018
New Revision: 322274

URL: http://llvm.org/viewvc/llvm-project?rev=322274&view=rev
Log:
[clang-tidy] Fix google-readability-namespace-comments handling of C++17 nested 
namespaces

Summary:
Fixes bug 34701

When we encounter a namespace find the location of the left bracket.
Then if the text between the name and the left bracket contains a ':'
then it's a C++17 nested namespace.

Reviewers: #clang-tools-extra, alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: curdeius, cfe-commits, krasimir, JonasToth, JDevlieghere, xazax.hun

Tags: #clang-tools-extra

Patch by Alexandru Octavian Buțiu!

Differential Revision: https://reviews.llvm.org/D38284

Added:

clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=322274&r1=322273&r2=322274&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
Thu Jan 11 05:00:28 2018
@@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$",
+  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
   llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
@@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
   return Fix;
 }
 
+static std::string getNamespaceComment(const std::string &NameSpaceName,
+   bool InsertLineBreak) {
+  std::string Fix = "// namespace ";
+  Fix.append(NameSpaceName);
+  if (InsertLineBreak)
+Fix.append("\n");
+  return Fix;
+}
+
 void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ND = Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
@@ -74,11 +83,44 @@ void NamespaceCommentCheck::check(const
   SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
   SourceLocation Loc = AfterRBrace;
   Token Tok;
+  SourceLocation LBracketLocation = ND->getLocation();
+  SourceLocation NestedNamespaceBegin = LBracketLocation;
+
+  // Currently for nested namepsace (n1::n2::...) the AST matcher will match 
foo
+  // then bar instead of a single match. So if we got a nested namespace we 
have
+  // to skip the next ones.
+  for (const auto &EndOfNameLocation : Ends) {
+if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
+  EndOfNameLocation))
+  return;
+  }
+
+  // Ignore macros
+  if (!ND->getLocation().isMacroID()) {
+while (Lexer::getRawToken(LBracketLocation, Tok, Sources, getLangOpts()) ||
+   !Tok.is(tok::l_brace)) {
+  LBracketLocation = LBracketLocation.getLocWithOffset(1);
+}
+  }
+
+  auto TextRange =
+  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin, 
LBracketLocation),
+Sources, getLangOpts());
+  StringRef NestedNamespaceName =
+  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
+  bool IsNested = NestedNamespaceName.contains(':');
+
+  if (IsNested)
+Ends.push_back(LBracketLocation);
+  else
+NestedNamespaceName = ND->getName();
+
   // Skip whitespace until we find the next token.
   while (Lexer::getRawToken(Loc, Tok, Sources, getLangOpts()) ||
  Tok.is(tok::semi)) {
 Loc = Loc.getLocWithOffset(1);
   }
+
   if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
 return;
 
@@ -98,10 +140,14 @@ void NamespaceCommentCheck::check(const
   StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : "";
   StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
 
-  // Check if the namespace in the comment is the same.
-  if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) ||
-  (ND->getNameAsString() == NamespaceNameInComment &&
-   Anonymous.empty())) {
+  if (IsNested && NestedNamespaceName == NamespaceNameInComment) {
+// C++17 nested namespace.
+return;
+  } else if ((ND->isAnonymousNamespace() &&
+  NamespaceNameInComment.empty()) ||
+ (ND->getNameAsString() == Names

[clang-tools-extra] r326314 - [clang-tidy] Add a test for readability-implicit-bool-conversion with bitfields.

2018-02-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb 28 02:30:25 2018
New Revision: 326314

URL: http://llvm.org/viewvc/llvm-project?rev=326314&view=rev
Log:
[clang-tidy] Add a test for readability-implicit-bool-conversion with bitfields.

Modified:

clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion-allow-in-conditions.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion-allow-in-conditions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion-allow-in-conditions.cpp?rev=326314&r1=326313&r2=326314&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion-allow-in-conditions.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-conversion-allow-in-conditions.cpp
 Wed Feb 28 02:30:25 2018
@@ -12,6 +12,7 @@ int* functionReturningPointer();
 
 struct Struct {
   int member;
+  unsigned bitfield : 1;
 };
 
 
@@ -23,6 +24,11 @@ void regularImplicitConversionIntegerToB
 }
 
 void implicitConversionIntegerToBoolInConditionalsIsAllowed() {
+  Struct s = {};
+  if (s.member) {}
+  if (!s.member) {}
+  if (s.bitfield) {}
+  if (!s.bitfield) {}
   if (functionReturningInt()) {}
   if (!functionReturningInt()) {}
   if (functionReturningInt() && functionReturningPointer()) {}


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


[clang-tools-extra] r326321 - [clang-tidy] Fix 'add_new_check.py --udpate-docs'

2018-02-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb 28 04:21:38 2018
New Revision: 326321

URL: http://llvm.org/viewvc/llvm-project?rev=326321&view=rev
Log:
[clang-tidy] Fix 'add_new_check.py --udpate-docs'

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=326321&r1=326320&r2=326321&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Wed Feb 28 04:21:38 2018
@@ -320,9 +320,11 @@ def main():
   metavar='LANG')
   parser.add_argument(
   'module',
+  nargs='?',
   help='module directory under which to place the new tidy check (e.g., 
misc)')
   parser.add_argument(
   'check',
+  nargs='?',
   help='name of new tidy check to add (e.g. foo-do-the-stuff)')
   args = parser.parse_args()
 
@@ -330,6 +332,11 @@ def main():
 update_checks_list(os.path.dirname(sys.argv[0]))
 return
 
+  if not args.module or not args.check:
+print 'Module and check must be specified.'
+parser.print_usage()
+return
+
   module = args.module
   check_name = args.check
 


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


[clang-tools-extra] r326327 - Rename a few checks from misc- to bugprone-.

2018-02-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb 28 06:47:20 2018
New Revision: 326327

URL: http://llvm.org/viewvc/llvm-project?rev=326327&view=rev
Log:
Rename a few checks from misc- to bugprone-.

Summary:
rename_check.py {misc,bugprone}-forwarding-reference-overload
rename_check.py {misc,bugprone}-macro-repeated-side-effects
rename_check.py {misc,bugprone}-lambda-function-name
rename_check.py {misc,bugprone}-misplaced-widening-cast

Reviewers: hokein, sammccall, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D43867

Added:

clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.h
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/LambdaFunctionNameCheck.h
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h

clang-tools-extra/trunk/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.h
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/MacroRepeatedSideEffectsCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.h
  - copied, changed from r326321, 
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
  - copied, changed from r326321, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-forwarding-reference-overload.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-lambda-function-name.rst
  - copied, changed from r326321, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-lambda-function-name.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-macro-repeated-side-effects.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-misplaced-widening-cast.rst
  - copied, changed from r326321, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-lambda-function-name.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/test/clang-tidy/misc-lambda-function-name.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c
  - copied, changed from r326321, 
clang-tools-extra/trunk/test/clang-tidy/misc-macro-repeated-side-effects.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-implicit-enabled.cpp
  - copied, changed from r326321, 
clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-widening-cast-implicit-enabled.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.h
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/LambdaFunctionNameCheck.h
clang-tools-extra/trunk/clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MacroRepeatedSideEffectsCheck.h
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-forwarding-reference-overload.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-lambda-function-name.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-macro-repeated-side-effects.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst

clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-lambda-function-name.

[clang-tools-extra] r326384 - Rename more checks from misc- to bugprone-.

2018-02-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb 28 15:30:29 2018
New Revision: 326384

URL: http://llvm.org/viewvc/llvm-project?rev=326384&view=rev
Log:
Rename more checks from misc- to bugprone-.

Summary:
clang-tidy/rename_check.py {misc,bugprone}-string-integer-assignment
clang-tidy/rename_check.py {misc,bugprone}-string-literal-with-embedded-nul
clang-tidy/rename_check.py {misc,bugprone}-suspicious-enum-usage
clang-tidy/rename_check.py {misc,bugprone}-suspicious-missing-comma

Reviewers: hokein, sammccall, aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D43868

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.h
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.h

clang-tools-extra/trunk/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.h
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMissingCommaCheck.h
  - copied, changed from r326365, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-integer-assignment.rst
  - copied, changed from r326365, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-integer-assignment.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-string-literal-with-embedded-nul.rst
  - copied, changed from r326365, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-enum-usage.rst
  - copied, changed from r326365, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-enum-usage.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-missing-comma.rst
  - copied, changed from r326365, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/test/clang-tidy/misc-string-integer-assignment.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-string-literal-with-embedded-nul.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-missing-comma.cpp
  - copied, changed from r326365, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-missing-comma.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringIntegerAssignmentCheck.h

clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousMissingCommaCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-integer-assignment.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-enum-usage.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst
clang-tools-extra/trunk/test/

[clang-tools-extra] r326386 - [clang-tidy] Another batch of checks to rename from misc- to bugprone-.

2018-02-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb 28 15:47:15 2018
New Revision: 326386

URL: http://llvm.org/viewvc/llvm-project?rev=326386&view=rev
Log:
[clang-tidy] Another batch of checks to rename from misc- to bugprone-.

Summary:
clang-tidy/rename_check.py {misc,bugprone}-suspicious-semicolon
clang-tidy/rename_check.py {misc,bugprone}-suspicious-string-compare
clang-tidy/rename_check.py {misc,bugprone}-swapped-arguments
clang-tidy/rename_check.py {misc,bugprone}-undelegated-constructor 
--check_class_name UndelegatedConstructor

Reviewers: hokein, sammccall, aaron.ballman

Subscribers: klimek, mgorny, xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D43870

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.h
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousStringCompareCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousStringCompareCheck.h
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousStringCompareCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SwappedArgumentsCheck.h
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/UndelegatedConstructorCheck.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/UndelegatedConstructorCheck.h
  - copied, changed from r326384, 
clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst
  - copied, changed from r326384, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-string-compare.rst
  - copied, changed from r326384, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-string-compare.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-swapped-arguments.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undelegated-constructor.rst
  - copied, changed from r326384, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-undelegated-constructor.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-semicolon-fail.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-semicolon.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-string-compare.c
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-string-compare.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-string-compare.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-string-compare.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-swapped-arguments.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-swapped-arguments.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-undelegated-constructor-cxx98.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-undelegated-constructor-cxx98.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-undelegated-constructor.cpp
  - copied, changed from r326384, 
clang-tools-extra/trunk/test/clang-tidy/misc-undelegated-constructor.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousStringCompareCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousStringCompareCheck.h
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.h
clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-string-compare.rst
clang-tools-extra/trunk/docs/cl

Re: r326746 - [analyzer] AST-matching checker to detect global central dispatch performance anti-pattern

2018-03-06 Thread Alexander Kornienko via cfe-commits
On Mon, Mar 5, 2018 at 11:05 PM George Karpenkov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: george.karpenkov
> Date: Mon Mar  5 14:03:32 2018
> New Revision: 326746
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326746&view=rev
> Log:
> [analyzer] AST-matching checker to detect global central dispatch
> performance anti-pattern
>
> rdar://37312818
>
> NB: The checker does not care about the ordering of callbacks, see the
> relevant FIXME in tests.
>
> Differential Revision: https://reviews.llvm.org/D44059
>
> Added:
> cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
> cfe/trunk/test/gcdasyncsemaphorechecker_test.m
>

The test doesn't belong here. The right place seems to be test/Analysis/.


> Modified:
> cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
> cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=326746&r1=326745&r2=326746&view=diff
>
> ==
> --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Mar  5
> 14:03:32 2018
> @@ -610,6 +610,13 @@ def ObjCSuperDeallocChecker : Checker<"S
>
>  } // end "osx.cocoa"
>
> +let ParentPackage = OSXAlpha in {
> +
> +def GCDAsyncSemaphoreChecker : Checker<"GCDAsyncSemaphore">,
> +  HelpText<"Checker for performance anti-pattern when using semaphors
> from async API">,
> +  DescFile<"GCDAsyncSemaphoreChecker.cpp">;
> +} // end "alpha.osx"
> +
>  let ParentPackage = CocoaAlpha in {
>
>  def InstanceVariableInvalidation :
> Checker<"InstanceVariableInvalidation">,
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=326746&r1=326745&r2=326746&view=diff
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Mon Mar  5
> 14:03:32 2018
> @@ -37,6 +37,7 @@ add_clang_library(clangStaticAnalyzerChe
>DynamicTypeChecker.cpp
>ExprInspectionChecker.cpp
>FixedAddressChecker.cpp
> +  GCDAsyncSemaphoreChecker.cpp
>GenericTaintChecker.cpp
>GTestChecker.cpp
>IdenticalExprChecker.cpp
>
> Added: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp?rev=326746&view=auto
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
> (added)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp Mon
> Mar  5 14:03:32 2018
> @@ -0,0 +1,154 @@
> +//===- GCDAsyncSemaphoreChecker.cpp -*- C++
> -*-==//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===--===//
> +//
> +// This file defines GCDAsyncSemaphoreChecker which checks against a
> common
> +// antipattern when synchronous API is emulated from asynchronous
> callbacks
> +// using a semaphor:
> +//
> +//   dispatch_semapshore_t sema = dispatch_semaphore_create(0);
> +
> +//   AnyCFunctionCall(^{
> +// // code…
> +// dispatch_semapshore_signal(sema);
> +//   })
> +//   dispatch_semapshore_wait(sema, *)
> +//
> +// Such code is a common performance problem, due to inability of GCD to
> +// properly handle QoS when a combination of queues and semaphors is used.
> +// Good code would either use asynchronous API (when available), or
> perform
> +// the necessary action in asynchronous callback.
> +//
> +// Currently, the check is performed using a simple heuristical AST
> pattern
> +// matching.
> +//
>
> +//===--===//
> +
> +#include "ClangSACheckers.h"
> +#include "clang/ASTMatchers/ASTMatchFinder.h"
> +#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
> +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
> +#include "clang/StaticAnalyzer/Core/Checker.h"
> +#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
> +#include "llvm/Support/Debug.h"
> +
> +#define DEBUG_TYPE "gcdasyncsemaphorechecker"
> +
> +using namespace clang;
> +using namespace ento;
> +using namespace ast_matchers;
> +
> +namespace {
> +
> +const char *WarningBinding = "semaphore_wait";
> +
> +class GCDAsyncSemaphoreChecker : public Checker {
> +public:
> +  void checkASTCode

r326772 - Move test/gcdasyncsemaphorechecker_test.m to a subdirectory

2018-03-06 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Mar  6 02:40:11 2018
New Revision: 326772

URL: http://llvm.org/viewvc/llvm-project?rev=326772&view=rev
Log:
Move test/gcdasyncsemaphorechecker_test.m to a subdirectory

Added:
cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m
  - copied, changed from r326767, 
cfe/trunk/test/gcdasyncsemaphorechecker_test.m
Removed:
cfe/trunk/test/gcdasyncsemaphorechecker_test.m

Copied: cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m (from r326767, 
cfe/trunk/test/gcdasyncsemaphorechecker_test.m)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m?p2=cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m&p1=cfe/trunk/test/gcdasyncsemaphorechecker_test.m&r1=326767&r2=326772&rev=326772&view=diff
==
(empty)

Removed: cfe/trunk/test/gcdasyncsemaphorechecker_test.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/gcdasyncsemaphorechecker_test.m?rev=326771&view=auto
==
--- cfe/trunk/test/gcdasyncsemaphorechecker_test.m (original)
+++ cfe/trunk/test/gcdasyncsemaphorechecker_test.m (removed)
@@ -1,203 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.osx.GCDAsyncSemaphore 
%s -fblocks -verify
-typedef signed char BOOL;
-@protocol NSObject  - (BOOL)isEqual:(id)object; @end
-@interface NSObject  {}
-+(id)alloc;
--(id)init;
--(id)autorelease;
--(id)copy;
--(id)retain;
-@end
-
-typedef int dispatch_semaphore_t;
-typedef void (^block_t)();
-
-dispatch_semaphore_t dispatch_semaphore_create(int);
-void dispatch_semaphore_wait(dispatch_semaphore_t, int);
-void dispatch_semaphore_signal(dispatch_semaphore_t);
-
-void func(void (^)(void));
-void func_w_typedef(block_t);
-
-int coin();
-
-void use_semaphor_antipattern() {
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema);
-  });
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-// It's OK to use pattern in tests.
-// We simply match the containing function name against ^test.
-void test_no_warning() {
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema);
-  });
-  dispatch_semaphore_wait(sema, 100);
-}
-
-void use_semaphor_antipattern_multiple_times() {
-  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema1);
-  });
-  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-
-  dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema2);
-  });
-  dispatch_semaphore_wait(sema2, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-void use_semaphor_antipattern_multiple_wait() {
-  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema1);
-  });
-  // FIXME: multiple waits on same semaphor should not raise a warning.
-  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-void warn_incorrect_order() {
-  // FIXME: ASTMatchers do not allow ordered matching, so would match even
-  // if out of order.
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-  func(^{
-  dispatch_semaphore_signal(sema);
-  });
-}
-
-void warn_w_typedef() {
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-
-  func_w_typedef(^{
-  dispatch_semaphore_signal(sema);
-  });
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-void warn_nested_ast() {
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-
-  if (coin()) {
-func(^{
- dispatch_semaphore_signal(sema);
- });
-  } else {
-func(^{
- dispatch_semaphore_signal(sema);
- });
-  }
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-void use_semaphore_assignment() {
-  dispatch_semaphore_t sema;
-  sema = dispatch_semaphore_create(0);
-
-  func(^{
-  dispatch_semaphore_signal(sema);
-  });
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-void use_semaphore_assignment_init() {
-  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
-  sema = dispatch_semaphore_create(1);
-
-  func(^{
-  dispatch_semaphore_signal(sema);
-  });
-  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
-}
-
-

Re: r326746 - [analyzer] AST-matching checker to detect global central dispatch performance anti-pattern

2018-03-06 Thread Alexander Kornienko via cfe-commits
On Tue, Mar 6, 2018 at 11:03 AM Alexander Kornienko 
wrote:

> On Mon, Mar 5, 2018 at 11:05 PM George Karpenkov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: george.karpenkov
>> Date: Mon Mar  5 14:03:32 2018
>> New Revision: 326746
>>
>> cfe/trunk/test/gcdasyncsemaphorechecker_test.m
>>
>
> The test doesn't belong here. The right place seems to be test/Analysis/.
>

Moved the test in r326772.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r327606 - [clang-tidy] rename_check.py {misc, bugprone}-macro-parentheses

2018-03-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Mar 15 01:25:39 2018
New Revision: 327606

URL: http://llvm.org/viewvc/llvm-project?rev=327606&view=rev
Log:
[clang-tidy] rename_check.py {misc,bugprone}-macro-parentheses

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp
  - copied, changed from r327590, 
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.h
  - copied, changed from r327590, 
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-macro-parentheses.rst
  - copied, changed from r327590, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-macro-parentheses.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-parentheses-cmdline.cpp
  - copied, changed from r327590, 
clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses-cmdline.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-parentheses.cpp
  - copied, changed from r327590, 
clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-macro-parentheses.rst
clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses-cmdline.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-macro-parentheses.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327606&r1=327605&r2=327606&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Mar 
15 01:25:39 2018
@@ -22,6 +22,7 @@
 #include "IncorrectRoundingsCheck.h"
 #include "IntegerDivisionCheck.h"
 #include "LambdaFunctionNameCheck.h"
+#include "MacroParenthesesCheck.h"
 #include "MacroRepeatedSideEffectsCheck.h"
 #include "MisplacedOperatorInStrlenInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
@@ -73,6 +74,8 @@ public:
 "bugprone-integer-division");
 CheckFactories.registerCheck(
 "bugprone-lambda-function-name");
+CheckFactories.registerCheck(
+"bugprone-macro-parentheses");
 CheckFactories.registerCheck(
 "bugprone-macro-repeated-side-effects");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327606&r1=327605&r2=327606&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Mar 15 
01:25:39 2018
@@ -14,6 +14,7 @@ add_clang_library(clangTidyBugproneModul
   IncorrectRoundingsCheck.cpp
   IntegerDivisionCheck.cpp
   LambdaFunctionNameCheck.cpp
+  MacroParenthesesCheck.cpp
   MacroRepeatedSideEffectsCheck.cpp
   MisplacedOperatorInStrlenInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp 
(from r327590, 
clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp&r1=327590&r2=327606&rev=327606&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MacroParenthesesCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp Thu 
Mar 15 01:25:39 2018
@@ -14,7 +14,7 @@
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 namespace {
 class MacroParenthesesPPCallbacks : public PPCallbacks {
@@ -255,6 +255,6 @@ void MacroParenthesesCheck::registerPPCa
   &Compiler.getPreprocessor(), this));
 }
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.h 
(from r327590, clang-tools-extra/trunk/clang-tidy/misc/MacroParenthese

[clang-tools-extra] r327609 - Fixed filename in a comment. NFC

2018-03-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Mar 15 01:26:58 2018
New Revision: 327609

URL: http://llvm.org/viewvc/llvm-project?rev=327609&view=rev
Log:
Fixed filename in a comment. NFC

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h?rev=327609&r1=327608&r2=327609&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h Thu 
Mar 15 01:26:58 2018
@@ -1,4 +1,4 @@
-//===--- IncorrectRoundingsCheckCheck.h - clang-tidy -*- C++ 
-*-===//
+//===--- IncorrectRoundingsCheck.h - clang-tidy -*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //


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


[clang-tools-extra] r327608 - [clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-container

2018-03-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Mar 15 01:26:47 2018
New Revision: 327608

URL: http://llvm.org/viewvc/llvm-project?rev=327608&view=rev
Log:
[clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-container

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp
  - copied, changed from r327607, 
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h
  - copied, changed from r327607, 
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-container.rst
  - copied, changed from r327607, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-container.cpp
  - copied, changed from r327607, 
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-container.rst
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327608&r1=327607&r2=327608&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Mar 
15 01:26:47 2018
@@ -28,6 +28,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "StringConstructorCheck.h"
 #include "StringIntegerAssignmentCheck.h"
@@ -87,6 +88,8 @@ public:
 "bugprone-move-forwarding-reference");
 CheckFactories.registerCheck(
 "bugprone-multiple-statement-macro");
+CheckFactories.registerCheck(
+"bugprone-sizeof-container");
 CheckFactories.registerCheck(
 "bugprone-sizeof-expression");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327608&r1=327607&r2=327608&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Mar 15 
01:26:47 2018
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModul
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
+  SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   StringConstructorCheck.cpp
   StringIntegerAssignmentCheck.cpp

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp 
(from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp&r1=327607&r2=327608&rev=327608&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.cpp Thu 
Mar 15 01:26:47 2018
@@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
@@ -44,6 +44,6 @@ void SizeofContainerCheck::check(const M
   "container; did you mean .size()?");
 }
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h 
(from r327607, clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.h)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofContainerCheck.h&p1=clang-tools-extra/trunk/cla

[clang-tools-extra] r327607 - [clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expression

2018-03-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Mar 15 01:26:19 2018
New Revision: 327607

URL: http://llvm.org/viewvc/llvm-project?rev=327607&view=rev
Log:
[clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expression

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  - copied, changed from r327606, 
clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.h
  - copied, changed from r327606, 
clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-sizeof-expression.rst
  - copied, changed from r327606, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-expression.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-sizeof-expression.cpp
  - copied, changed from r327606, 
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-expression.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-expression.rst
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-expression.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327607&r1=327606&r2=327607&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Mar 
15 01:26:19 2018
@@ -28,6 +28,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "SizeofExpressionCheck.h"
 #include "StringConstructorCheck.h"
 #include "StringIntegerAssignmentCheck.h"
 #include "StringLiteralWithEmbeddedNulCheck.h"
@@ -86,6 +87,8 @@ public:
 "bugprone-move-forwarding-reference");
 CheckFactories.registerCheck(
 "bugprone-multiple-statement-macro");
+CheckFactories.registerCheck(
+"bugprone-sizeof-expression");
 CheckFactories.registerCheck(
 "bugprone-string-constructor");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327607&r1=327606&r2=327607&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Mar 15 
01:26:19 2018
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModul
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
+  SizeofExpressionCheck.cpp
   StringConstructorCheck.cpp
   StringIntegerAssignmentCheck.cpp
   StringLiteralWithEmbeddedNulCheck.cpp

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
(from r327606, 
clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.cpp&r1=327606&r2=327607&rev=327607&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.cpp Thu 
Mar 15 01:26:19 2018
@@ -16,7 +16,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 namespace {
 
@@ -260,6 +260,6 @@ void SizeofExpressionCheck::check(const
   }
 }
 
-} // namespace misc
+} // namespace bugprone
 } // namespace tidy
 } // namespace clang

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.h 
(from r327606, clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.h)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/SizeofExpressionCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/SizeofExpressionCheck.h&r1=327606&r2=327607&rev=327607&view=diff
=

[clang-tools-extra] r327610 - [clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii --check_class_name=UnusedRAIICheck

2018-03-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Mar 15 01:27:42 2018
New Revision: 327610

URL: http://llvm.org/viewvc/llvm-project?rev=327610&view=rev
Log:
[clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii 
--check_class_name=UnusedRAIICheck

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.cpp
  - copied, changed from r327609, 
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.h
  - copied, changed from r327609, 
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-raii.rst
  - copied, changed from r327609, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-unused-raii.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-raii.cpp
  - copied, changed from r327609, 
clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-unused-raii.rst
clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327610&r1=327609&r2=327610&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Mar 
15 01:27:42 2018
@@ -42,6 +42,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
+#include "UnusedRaiiCheck.h"
 #include "UseAfterMoveCheck.h"
 #include "VirtualNearMissCheck.h"
 
@@ -116,6 +117,8 @@ public:
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
+CheckFactories.registerCheck(
+"bugprone-unused-raii");
 CheckFactories.registerCheck(
 "bugprone-use-after-move");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327610&r1=327609&r2=327610&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Mar 15 
01:27:42 2018
@@ -34,6 +34,7 @@ add_clang_library(clangTidyBugproneModul
   ThrowKeywordMissingCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
+  UnusedRaiiCheck.cpp
   UseAfterMoveCheck.cpp
   VirtualNearMissCheck.cpp
 

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.cpp (from 
r327609, clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp&r1=327609&r2=327610&rev=327610&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UnusedRaiiCheck.cpp Thu Mar 15 
01:27:42 2018
@@ -1,4 +1,4 @@
-//===--- UnusedRAIICheck.cpp - clang-tidy 
-===//
+//===--- UnusedRaiiCheck.cpp - clang-tidy 
-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-#include "UnusedRAIICheck.h"
+#include "UnusedRaiiCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
 
@@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespace misc {
+namespace bugprone {
 
 namespace {
 AST_MATCHER(CXXRecordDecl, hasNonTrivialDestructor) {
@@ -24,7 +24,7 @@ AST_MATCHER(CXXRecordDecl, hasNonTrivial
 }
 } // namespace
 
-void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) {
+void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++; the functionality currently does not
   // provide 

[clang-tools-extra] r327833 - [clang-tidy] New check bugprone-unused-return-value

2018-03-19 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Mar 19 06:02:32 2018
New Revision: 327833

URL: http://llvm.org/viewvc/llvm-project?rev=327833&view=rev
Log:
[clang-tidy] New check bugprone-unused-return-value

Summary:
Detects function calls where the return value is unused.

Checked functions can be configured.

Reviewers: alexfh, aaron.ballman, ilya-biryukov, hokein

Reviewed By: alexfh, aaron.ballman

Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Kalle Huttunen!

Differential Revision: https://reviews.llvm.org/D41655

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327833&r1=327832&r2=327833&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Mon Mar 
19 06:02:32 2018
@@ -43,6 +43,7 @@
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnusedRaiiCheck.h"
+#include "UnusedReturnValueCheck.h"
 #include "UseAfterMoveCheck.h"
 #include "VirtualNearMissCheck.h"
 
@@ -119,6 +120,8 @@ public:
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
 "bugprone-unused-raii");
+CheckFactories.registerCheck(
+"bugprone-unused-return-value");
 CheckFactories.registerCheck(
 "bugprone-use-after-move");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327833&r1=327832&r2=327833&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Mon Mar 19 
06:02:32 2018
@@ -35,6 +35,7 @@ add_clang_library(clangTidyBugproneModul
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnusedRaiiCheck.cpp
+  UnusedReturnValueCheck.cpp
   UseAfterMoveCheck.cpp
   VirtualNearMissCheck.cpp
 

Added: clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp?rev=327833&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp Mon 
Mar 19 06:02:32 2018
@@ -0,0 +1,82 @@
+//===--- UnusedReturnValueCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UnusedReturnValueCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  CheckedFunctions(Options.get("CheckedFunctions", "::std::async;"
+   "::std::launder;"
+   "::std::remove;"
+   "::std::remove_if;"
+   "::std::unique")) {}
+
+void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "CheckedFunctions", CheckedFunctions);
+}
+
+void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
+  auto FunVec = utils::options::parseStringList(CheckedFunctions);
+  auto MatchedCallEx

[clang-tools-extra] r334400 - Add support for arrays in performance-implicit-conversion-in-loop

2018-06-11 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Jun 11 05:46:48 2018
New Revision: 334400

URL: http://llvm.org/viewvc/llvm-project?rev=334400&view=rev
Log:
Add support for arrays in performance-implicit-conversion-in-loop

Summary:
Add support for arrays (and structure that use naked pointers for their 
iterator, like std::array) in performance-implicit-conversion-in-loop

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Alex Pilkiewicz.

Differential Revision: https://reviews.llvm.org/D47945

Modified:

clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.h

clang-tools-extra/trunk/test/clang-tidy/performance-implicit-conversion-in-loop.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp?rev=334400&r1=334399&r2=334400&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
 Mon Jun 11 05:46:48 2018
@@ -28,7 +28,7 @@ namespace performance {
 static bool IsNonTrivialImplicitCast(const Stmt *ST) {
   if (const auto *ICE = dyn_cast(ST)) {
 return (ICE->getCastKind() != CK_NoOp) ||
-   IsNonTrivialImplicitCast(ICE->getSubExpr());
+IsNonTrivialImplicitCast(ICE->getSubExpr());
   }
   return false;
 }
@@ -39,7 +39,9 @@ void ImplicitConversionInLoopCheck::regi
   // conversion. The check on the implicit conversion is done in check() 
because
   // we can't access implicit conversion subnode via matchers: has() skips 
casts
   // and materialize! We also bind on the call to operator* to get the proper
-  // type in the diagnostic message.
+  // type in the diagnostic message. We use both cxxOperatorCallExpr for user
+  // defined operator and unaryOperator when the iterator is a pointer, like
+  // for arrays or std::array.
   //
   // Note that when the implicit conversion is done through a user defined
   // conversion operator, the node is a CXXMemberCallExpr, not a
@@ -47,10 +49,14 @@ void ImplicitConversionInLoopCheck::regi
   // cxxOperatorCallExpr() matcher.
   Finder->addMatcher(
   cxxForRangeStmt(hasLoopVariable(
-  varDecl(hasType(qualType(references(qualType(isConstQualified(),
-  hasInitializer(expr(hasDescendant(cxxOperatorCallExpr().bind(
-  "operator-call")))
- .bind("init")))
+  varDecl(
+  hasType(qualType(references(qualType(isConstQualified(),
+  hasInitializer(
+  expr(anyOf(hasDescendant(
+ cxxOperatorCallExpr().bind("operator-call")),
+ hasDescendant(unaryOperator(hasOperatorName("*"))
+   .bind("operator-call"
+  .bind("init")))
   .bind("faulty-var"))),
   this);
 }
@@ -60,7 +66,7 @@ void ImplicitConversionInLoopCheck::chec
   const auto *VD = Result.Nodes.getNodeAs("faulty-var");
   const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *OperatorCall =
-  Result.Nodes.getNodeAs("operator-call");
+  Result.Nodes.getNodeAs("operator-call");
 
   if (const auto *Cleanup = dyn_cast(Init))
 Init = Cleanup->getSubExpr();
@@ -79,7 +85,7 @@ void ImplicitConversionInLoopCheck::chec
 
 void ImplicitConversionInLoopCheck::ReportAndFix(
 const ASTContext *Context, const VarDecl *VD,
-const CXXOperatorCallExpr *OperatorCall) {
+const Expr *OperatorCall) {
   // We only match on const ref, so we should print a const ref version of the
   // type.
   QualType ConstType = OperatorCall->getType().withConst();

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.h?rev=334400&r1=334399&r2=334400&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.h 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/ImplicitConversionInLoopCheck.h 
Mon Jun 11 05:46:48 2018
@@ -28,7 +28,7 @@ public:
 
 private:
   void ReportAndFix(const ASTContext *Context, const VarDecl *VD,
-const CXXOperatorCallExpr *OperatorCall);
+const Expr *OperatorCall);
 };
 
 } // namespace performance

Modified: 
clang-tools-extra/trunk/test/clang-tidy/performance-implicit-conversion-in-loop.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-t

Re: r330382 - [CFG] [analyzer] Add construction contexts for loop condition variables.

2018-06-14 Thread Alexander Kornienko via cfe-commits
This commit seems to have introduced
https://bugs.llvm.org/show_bug.cgi?id=37769. Could you take a look?

On Fri, Apr 20, 2018 at 1:33 AM Artem Dergachev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: dergachev
> Date: Thu Apr 19 16:30:15 2018
> New Revision: 330382
>
> URL: http://llvm.org/viewvc/llvm-project?rev=330382&view=rev
> Log:
> [CFG] [analyzer] Add construction contexts for loop condition variables.
>
> Loop condition variables, eg.
>
>   while (shared_ptr P = getIntPtr()) { ... })
>
> weren't handled in r324794 because they don't go through the common
> CFGBuilder::VisitDeclStmt method. Which means that they regressed
> after r324800.
>
> Fix the regression by duplicating the necessary construction context scan
> in
> the loop visiting code.
>
> Differential Revision: https://reviews.llvm.org/D45706
>
> Modified:
> cfe/trunk/lib/Analysis/CFG.cpp
> cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp
> cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
> cfe/trunk/test/Analysis/scopes-cfg-output.cpp
>
> Modified: cfe/trunk/lib/Analysis/CFG.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=330382&r1=330381&r2=330382&view=diff
>
> ==
> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
> +++ cfe/trunk/lib/Analysis/CFG.cpp Thu Apr 19 16:30:15 2018
> @@ -3169,7 +3169,13 @@ CFGBlock *CFGBuilder::VisitForStmt(ForSt
>if (VarDecl *VD = F->getConditionVariable()) {
>  if (Expr *Init = VD->getInit()) {
>autoCreateBlock();
> -  appendStmt(Block, F->getConditionVariableDeclStmt());
> +  const DeclStmt *DS = F->getConditionVariableDeclStmt();
> +  assert(DS->isSingleDecl());
> +  findConstructionContexts(
> +
> ConstructionContextLayer::create(cfg->getBumpVectorContext(),
> +   const_cast *>(DS)),
> +  Init);
> +  appendStmt(Block, DS);
>EntryConditionBlock = addStmt(Init);
>assert(Block == EntryConditionBlock);
>maybeAddScopeBeginForVarDecl(EntryConditionBlock, VD, C);
> @@ -3494,7 +3500,13 @@ CFGBlock *CFGBuilder::VisitWhileStmt(Whi
>  if (VarDecl *VD = W->getConditionVariable()) {
>if (Expr *Init = VD->getInit()) {
>  autoCreateBlock();
> -appendStmt(Block, W->getConditionVariableDeclStmt());
> +const DeclStmt *DS = W->getConditionVariableDeclStmt();
> +assert(DS->isSingleDecl());
> +findConstructionContexts(
> +ConstructionContextLayer::create(cfg->getBumpVectorContext(),
> + const_cast(DS)),
> +Init);
> +appendStmt(Block, DS);
>  EntryConditionBlock = addStmt(Init);
>  assert(Block == EntryConditionBlock);
>  maybeAddScopeBeginForVarDecl(EntryConditionBlock, VD, C);
>
> Modified: cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp?rev=330382&r1=330381&r2=330382&view=diff
>
> ==
> --- cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp (original)
> +++ cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp Thu Apr 19
> 16:30:15 2018
> @@ -388,7 +388,8 @@ void test_if_jumps() {
>  // CHECK:  [B4]
>  // CHECK-NEXT:   1: a
>  // CHECK-NEXT:   2: [B4.1] (ImplicitCastExpr, NoOp, const class A)
> -// CHECK-NEXT:   3: [B4.2] (CXXConstructExpr, class A)
> +// WARNINGS-NEXT:   3: [B4.2] (CXXConstructExpr, class A)
> +// ANALYZER-NEXT:   3: [B4.2] (CXXConstructExpr, [B4.4], class A)
>  // CHECK-NEXT:   4: A b = a;
>  // CHECK-NEXT:   5: b
>  // CHECK-NEXT:   6: [B4.5] (ImplicitCastExpr, NoOp, const class A)
> @@ -478,7 +479,8 @@ void test_while_implicit_scope() {
>  // CHECK:  [B10]
>  // CHECK-NEXT:   1: a
>  // CHECK-NEXT:   2: [B10.1] (ImplicitCastExpr, NoOp, const class A)
> -// CHECK-NEXT:   3: [B10.2] (CXXConstructExpr, class A)
> +// WARNINGS-NEXT:   3: [B10.2] (CXXConstructExpr, class A)
> +// ANALYZER-NEXT:   3: [B10.2] (CXXConstructExpr, [B10.4], class A)
>  // CHECK-NEXT:   4: A b = a;
>  // CHECK-NEXT:   5: b
>  // CHECK-NEXT:   6: [B10.5] (ImplicitCastExpr, NoOp, const class A)
> @@ -761,7 +763,8 @@ void test_switch_jumps() {
>  // CHECK:  [B4]
>  // CHECK-NEXT:   1: a
>  // CHECK-NEXT:   2: [B4.1] (ImplicitCastExpr, NoOp, const class A)
> -// CHECK-NEXT:   3: [B4.2] (CXXConstructExpr, class A)
> +// WARNINGS-NEXT:   3: [B4.2] (CXXConstructExpr, class A)
> +// ANALYZER-NEXT:   3: [B4.2] (CXXConstructExpr, [B4.4], class A)
>  // CHECK-NEXT:   4: A b = a;
>  // CHECK-NEXT:   5: b
>  // CHECK-NEXT:   6: [B4.5] (ImplicitCastExpr, NoOp, const class A)
> @@ -851,7 +854,8 @@ void test_for_implicit_scope() {
>  // CHECK:  [B10]
>  // CHECK-NEXT:   1: b
>  // CHECK-NEXT:   2: [B

[clang-tools-extra] r335252 - [clang-tidy] Remove the google-readability-redundant-smartptr-get alias

2018-06-21 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jun 21 09:14:27 2018
New Revision: 335252

URL: http://llvm.org/viewvc/llvm-project?rev=335252&view=rev
Log:
[clang-tidy] Remove the google-readability-redundant-smartptr-get alias

I don't remember why I added it, but it's definitely not needed, since the check
doesn't have any options and the check doesn't have any special relation to the
Google C++ style.

Removed:

clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
Modified:
clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-smartptr-get.rst

Modified: clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp?rev=335252&r1=335251&r2=335252&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp Thu Jun 21 
09:14:27 2018
@@ -13,7 +13,6 @@
 #include "../readability/BracesAroundStatementsCheck.h"
 #include "../readability/FunctionSizeCheck.h"
 #include "../readability/NamespaceCommentCheck.h"
-#include "../readability/RedundantSmartptrGetCheck.h"
 #include "AvoidCStyleCastsCheck.h"
 #include "AvoidThrowingObjCExceptionCheck.h"
 #include "DefaultArgumentsCheck.h"
@@ -71,9 +70,6 @@ class GoogleModule : public ClangTidyMod
 CheckFactories
 .registerCheck(
 "google-readability-namespace-comments");
-CheckFactories
-.registerCheck(
-"google-readability-redundant-smartptr-get");
   }
 
   ClangTidyOptions getModuleOptions() override {

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=335252&r1=335251&r2=335252&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Jun 21 09:14:27 2018
@@ -193,6 +193,10 @@ Improvements to clang-tidy
   `
   added.
 
+- Removed the `google-readability-redundant-smartptr-get` alias of the
+  :doc:`readability-redundant-smartptr-get
+  ` check.
+
 - The 'misc-forwarding-reference-overload' check was renamed to 
:doc:`bugprone-forwarding-reference-overload
   `
 

Removed: 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst?rev=335251&view=auto
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
 (removed)
@@ -1,10 +0,0 @@
-.. title:: clang-tidy - google-readability-redundant-smartptr-get
-.. meta::
-   :http-equiv=refresh: 5;URL=readability-redundant-smartptr-get.html
-
-google-readability-redundant-smartptr-get
-=
-
-The google-readability-redundant-smartptr-get check is an alias, please see
-`readability-redundant-smartptr-get `_
-for more information.

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=335252&r1=335251&r2=335252&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Jun 21 09:14:27 
2018
@@ -93,8 +93,8 @@ Clang-Tidy Checks
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
-   fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 

fuchsia-default-arguments
+   fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 

fuchsia-multiple-inheritance
fuchsia-overloaded-operator
fuchsia-restrict-system-includes
@@ -113,7 +113,6 @@ Clang-Tidy Checks
google-readability-casting
google-readability-function-size (redirects to readability-function-size) 

google-readability-namespace-comments (redirects to llvm-namespace-comment) 

-   google-readability-redundant-smartptr-get (redirects to 
readability-redundant-smartptr-get) 
google-readability-todo
google-runtime-int
google-runtime-operator

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-smartptr-get.rst
URL: 
http://llvm.org/viewvc/llvm-projec

[clang-tools-extra] r344058 - [clang-tidy] Fix handling of parens around new expressions in make_ checks.

2018-10-09 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Oct  9 08:58:18 2018
New Revision: 344058

URL: http://llvm.org/viewvc/llvm-project?rev=344058&view=rev
Log:
[clang-tidy] Fix handling of parens around new expressions in make_ 
checks.

Summary:
Extra parentheses around a new expression result in incorrect code
after applying fixes.

Reviewers: hokein

Reviewed By: hokein

Subscribers: xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D52989

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=344058&r1=344057&r2=344058&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Oct  
9 08:58:18 2018
@@ -21,6 +21,9 @@ namespace modernize {
 namespace {
 
 constexpr char StdMemoryHeader[] = "memory";
+constexpr char ConstructorCall[] = "constructorCall";
+constexpr char ResetCall[] = "resetCall";
+constexpr char NewExpression[] = "newExpression";
 
 std::string GetNewExprName(const CXXNewExpr *NewExpr,
const SourceManager &SM,
@@ -30,7 +33,7 @@ std::string GetNewExprName(const CXXNewE
   
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
   if (NewExpr->isArray()) {
-return WrittenName.str() + "[]";
+return (WrittenName + "[]").str();
   }
   return WrittenName.str();
 }
@@ -38,9 +41,6 @@ std::string GetNewExprName(const CXXNewE
 } // namespace
 
 const char MakeSmartPtrCheck::PointerType[] = "pointerType";
-const char MakeSmartPtrCheck::ConstructorCall[] = "constructorCall";
-const char MakeSmartPtrCheck::ResetCall[] = "resetCall";
-const char MakeSmartPtrCheck::NewExpression[] = "newExpression";
 
 MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name,
  ClangTidyContext* Context,
@@ -68,8 +68,8 @@ bool MakeSmartPtrCheck::isLanguageVersio
 
 void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
   if (isLanguageVersionSupported(getLangOpts())) {
-Inserter.reset(new utils::IncludeInserter(
-Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
+Inserter = llvm::make_unique(
+Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
 Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 }
@@ -122,12 +122,12 @@ void MakeSmartPtrCheck::check(const Matc
 return;
 
   if (Construct)
-checkConstruct(SM, Construct, Type, New);
+checkConstruct(SM, Result.Context, Construct, Type, New);
   else if (Reset)
-checkReset(SM, Reset, New);
+checkReset(SM, Result.Context, Reset, New);
 }
 
-void MakeSmartPtrCheck::checkConstruct(SourceManager &SM,
+void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, ASTContext *Ctx,
const CXXConstructExpr *Construct,
const QualType *Type,
const CXXNewExpr *New) {
@@ -154,7 +154,7 @@ void MakeSmartPtrCheck::checkConstruct(S
 return;
   }
 
-  if (!replaceNew(Diag, New, SM)) {
+  if (!replaceNew(Diag, New, SM, Ctx)) {
 return;
   }
 
@@ -193,7 +193,7 @@ void MakeSmartPtrCheck::checkConstruct(S
   insertHeader(Diag, SM.getFileID(ConstructCallStart));
 }
 
-void MakeSmartPtrCheck::checkReset(SourceManager &SM,
+void MakeSmartPtrCheck::checkReset(SourceManager &SM, ASTContext *Ctx,
const CXXMemberCallExpr *Reset,
const CXXNewExpr *New) {
   const auto *Expr = cast(Reset->getCallee());
@@ -224,7 +224,7 @@ void MakeSmartPtrCheck::checkReset(Sourc
 return;
   }
 
-  if (!replaceNew(Diag, New, SM)) {
+  if (!replaceNew(Diag, New, SM, Ctx)) {
 return;
   }
 
@@ -241,10 +241,24 @@ void MakeSmartPtrCheck::checkReset(Sourc
 }
 
 bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New,
-   SourceManager& SM) {
-  SourceLocation NewStart = New->getSourceRange().getBegin();
-  SourceLocation NewEnd = New->getSourceRange().getEnd();
+   const CXXNewExpr *New, SourceManager &SM,
+   ASTContext *Ctx) {
+  auto SkipParensParents = [&](const Expr *E) {
+for (const Expr *OldE = nullptr; E != OldE;) {
+  OldE = E;
+  for (const auto &Node : Ctx->getParents(*E)) {
+if (const Expr *Parent = Node.

[clang-tools-extra] r345049 - [clang-tidy] Add a separate section for NOLINT(NEXTLINE)? doc.

2018-10-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Oct 23 09:48:16 2018
New Revision: 345049

URL: http://llvm.org/viewvc/llvm-project?rev=345049&view=rev
Log:
[clang-tidy] Add a separate section for NOLINT(NEXTLINE)? doc.

Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=345049&r1=345048&r2=345049&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Tue Oct 23 09:48:16 2018
@@ -255,16 +255,19 @@ An overview of all the command-line opti
   value:   'some value'
   ...
 
+Suppressing Undesired Diagnostics
+=
+
 :program:`clang-tidy` diagnostics are intended to call out code that does
 not adhere to a coding standard, or is otherwise problematic in some way.
 However, if it is known that the code is correct, the check-specific ways
-to silence the diagnostics could be used, if they are available (e.g. 
-bugprone-use-after-move can be silenced by re-initializing the variable after 
-it has been moved out, misc-string-integer-assignment can be suppressed by 
-explicitly casting the integer to char, readability-implicit-bool-conversion
-can also be suppressed by using explicit casts, etc.). If they are not 
-available or if changing the semantics of the code is not desired, 
-the ``NOLINT`` or ``NOLINTNEXTLINE`` comments can be used instead. For example:
+to silence the diagnostics could be used, if they are available (e.g.
+bugprone-use-after-move can be silenced by re-initializing the variable after 
it
+has been moved out, bugprone-string-integer-assignment can be suppressed by
+explicitly casting the integer to char, readability-implicit-bool-conversion 
can
+also be suppressed by using explicit casts, etc.). If they are not available or
+if changing the semantics of the code is not desired, the ``NOLINT`` or
+``NOLINTNEXTLINE`` comments can be used instead. For example:
 
 .. code-block:: c++
 


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


r351196 - Reduce ASTMatchers stack footprint. Addresses http://llvm.org/PR38851

2019-01-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan 15 07:34:26 2019
New Revision: 351196

URL: http://llvm.org/viewvc/llvm-project?rev=351196&view=rev
Log:
Reduce ASTMatchers stack footprint. Addresses http://llvm.org/PR38851

The BoundNodesTreeBuilder class is used both directly and indirectly as a local
variable in matchesAncestorOfRecursively, memoizedMatchesAncestorOfRecursively
and other functions that happen to be on long recursive call paths. By reducing
the inline storage size of the SmallVector we dramatically reduce the stack
requirements of ASTMatchers. Running clang-tidy with a large number of checks
enabled on a few arbitrarily chosen files show no performance regression.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=351196&r1=351195&r2=351196&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Tue Jan 15 
07:34:26 2019
@@ -261,7 +261,7 @@ public:
   }
 
 private:
-  SmallVector Bindings;
+  SmallVector Bindings;
 };
 
 class ASTMatchFinder;


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


[clang-tools-extra] r351751 - [clang-tidy] Work around http://llvm.org/PR40392

2019-01-21 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Jan 21 08:26:54 2019
New Revision: 351751

URL: http://llvm.org/viewvc/llvm-project?rev=351751&view=rev
Log:
[clang-tidy] Work around http://llvm.org/PR40392

The readability-else-after-return check should be smarter about cases where the
variable defined in the condition is used in the `else` branch. This patch makes
it just ignore such cases, but alternative solutions may be better (added a
FIXME).

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp

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=351751&r1=351750&r2=351751&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp Mon 
Jan 21 08:26:54 2019
@@ -18,16 +18,22 @@ namespace tidy {
 namespace readability {
 
 void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ControlFlowInterruptorMatcher =
+  const auto InterruptsControlFlow =
   stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"),
  breakStmt().bind("break"),
  expr(ignoringImplicit(cxxThrowExpr().bind("throw");
   Finder->addMatcher(
   compoundStmt(forEach(
   ifStmt(unless(isConstexpr()),
- hasThen(stmt(
- anyOf(ControlFlowInterruptorMatcher,
-   compoundStmt(has(ControlFlowInterruptorMatcher),
+ // FIXME: Explore alternatives for the
+ // `if (T x = ...) {... return; } else {  }`
+ // pattern:
+ //   * warn, but don't fix;
+ //   * fix by pulling out the variable declaration out of
+ // the condition.
+ unless(hasConditionVariableStatement(anything())),
+ hasThen(stmt(anyOf(InterruptsControlFlow,
+
compoundStmt(has(InterruptsControlFlow),
  hasElse(stmt().bind("else")))
   .bind("if"))),
   this);

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp?rev=351751&r1=351750&r2=351751&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp 
Mon Jan 21 08:26:54 2019
@@ -105,3 +105,15 @@ void foo() {
 }
   }
 }
+
+extern int *g();
+extern void h(int **x);
+
+int *decl_in_condition() {
+  if (int *x = g()) {
+return x;
+  } else {
+h(&x);
+return x;
+  }
+}


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


[clang-tools-extra] r351814 - [clang-tidy] Fix whitespace in docs. NFC

2019-01-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan 22 04:59:34 2019
New Revision: 351814

URL: http://llvm.org/viewvc/llvm-project?rev=351814&view=rev
Log:
[clang-tidy] Fix whitespace in docs. NFC

Actually, just testing commits via monorepo ;)

Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=351814&r1=351813&r2=351814&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Tue Jan 22 04:59:34 2019
@@ -260,21 +260,20 @@ An overview of all the command-line opti
 Suppressing Undesired Diagnostics
 =
 
-:program:`clang-tidy` diagnostics are intended to call out code that does
-not adhere to a coding standard, or is otherwise problematic in some way.
-However, if it is known that the code is correct, the check-specific ways
-to silence the diagnostics could be used, if they are available (e.g.
-bugprone-use-after-move can be silenced by re-initializing the variable after 
it
-has been moved out, bugprone-string-integer-assignment can be suppressed by
-explicitly casting the integer to char, readability-implicit-bool-conversion 
can
-also be suppressed by using explicit casts, etc.). If they are not available or
-if changing the semantics of the code is not desired, the ``NOLINT`` or
-``NOLINTNEXTLINE`` comments can be used instead. For example:
+:program:`clang-tidy` diagnostics are intended to call out code that does not
+adhere to a coding standard, or is otherwise problematic in some way.  However,
+if it is known that the code is correct, the check-specific ways to silence the
+diagnostics could be used, if they are available (e.g.  bugprone-use-after-move
+can be silenced by re-initializing the variable after it has been moved out,
+bugprone-string-integer-assignment can be suppressed by explicitly casting the
+integer to ``char``, readability-implicit-bool-conversion can also be 
suppressed
+by using explicit casts, etc.). If they are not available or if changing the
+semantics of the code is not desired, the ``NOLINT`` or ``NOLINTNEXTLINE``
+comments can be used instead. For example:
 
 .. code-block:: c++
 
-  class Foo
-  {
+  class Foo {
 // Silent all the diagnostics for the line
 Foo(int param); // NOLINT
 
@@ -283,7 +282,7 @@ if changing the semantics of the code is
 
 // Silent only the specified diagnostics for the next line
 // NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)
-Foo(bool param); 
+Foo(bool param);
   };
 
 The formal syntax of ``NOLINT``/``NOLINTNEXTLINE`` is the following:
@@ -307,8 +306,8 @@ The formal syntax of ``NOLINT``/``NOLINT
 
 Note that whitespaces between ``NOLINT``/``NOLINTNEXTLINE`` and the opening
 parenthesis are not allowed (in this case the comment will be treated just as
-``NOLINT``/``NOLINTNEXTLINE``), whereas in check names list (inside
-the parenthesis) whitespaces can be used and will be ignored.
+``NOLINT``/``NOLINTNEXTLINE``), whereas in check names list (inside the
+parenthesis) whitespaces can be used and will be ignored.
 
 .. _LibTooling: http://clang.llvm.org/docs/LibTooling.html
 .. _How To Setup Tooling For LLVM: 
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html


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


[clang-tools-extra] r345979 - [clang-tidy] .reset(new X) -> make_unique() in a comment. NFC

2018-11-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Nov  2 08:03:43 2018
New Revision: 345979

URL: http://llvm.org/viewvc/llvm-project?rev=345979&view=rev
Log:
[clang-tidy] .reset(new X) -> make_unique() in a comment. NFC

Modified:
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h

Modified: clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h?rev=345979&r1=345978&r2=345979&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h Fri Nov  2 
08:03:43 2018
@@ -31,8 +31,8 @@ namespace utils {
 /// class MyCheck : public ClangTidyCheck {
 ///  public:
 ///   void registerPPCallbacks(CompilerInstance& Compiler) override {
-/// Inserter.reset(new IncludeInserter(&Compiler.getSourceManager(),
-///&Compiler.getLangOpts()));
+/// Inserter = 
llvm::make_unique(&Compiler.getSourceManager(),
+///   &Compiler.getLangOpts());
 /// Compiler.getPreprocessor().addPPCallbacks(
 /// Inserter->CreatePPCallback());
 ///   }


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


[clang-tools-extra] r345984 - [clang-tidy] Fixed code sample in a comment. NFC

2018-11-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Nov  2 08:29:37 2018
New Revision: 345984

URL: http://llvm.org/viewvc/llvm-project?rev=345984&view=rev
Log:
[clang-tidy] Fixed code sample in a comment. NFC

Modified:
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h

Modified: clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h?rev=345984&r1=345983&r2=345984&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h Fri Nov  2 
08:29:37 2018
@@ -25,16 +25,18 @@ namespace utils {
 /// \brief Produces fixes to insert specified includes to source files, if not
 /// yet present.
 ///
-/// ``IncludeInserter`` can be used by ``ClangTidyCheck`` in the following
-/// fashion:
+/// ``IncludeInserter`` can be used in clang-tidy checks in the following way:
 /// \code
+/// #include "../utils/IncludeInserter.h"
+/// #include "clang/Frontend/CompilerInstance.h"
+///
 /// class MyCheck : public ClangTidyCheck {
 ///  public:
 ///   void registerPPCallbacks(CompilerInstance& Compiler) override {
 /// Inserter = 
llvm::make_unique(&Compiler.getSourceManager(),
 ///   &Compiler.getLangOpts());
 /// Compiler.getPreprocessor().addPPCallbacks(
-/// Inserter->CreatePPCallback());
+/// Inserter->CreatePPCallbacks());
 ///   }
 ///
 ///   void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
@@ -49,7 +51,7 @@ namespace utils {
 ///   }
 ///
 ///  private:
-///   std::unique_ptr Inserter;
+///   std::unique_ptr Inserter;
 /// };
 /// \endcode
 class IncludeInserter {


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


[clang-tools-extra] r347053 - [clang-tidy] Expanded a test NFC

2018-11-16 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Nov 16 06:57:51 2018
New Revision: 347053

URL: http://llvm.org/viewvc/llvm-project?rev=347053&view=rev
Log:
[clang-tidy] Expanded a test NFC

Expanded the readability-inconsistent-declaration-parameter-name-macros.cpp to
check notes and added a test with pasted tokens.

Modified:

clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-macros.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-macros.cpp?rev=347053&r1=347052&r2=347053&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-macros.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-inconsistent-declaration-parameter-name-macros.cpp
 Fri Nov 16 06:57:51 2018
@@ -3,23 +3,45 @@
 // RUN:   -- -std=c++11
 
 #define MACRO() \
-  void f(int x);
+  void f(int x)
 
-struct S {
+struct S1 {
   MACRO();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'S::f' has a definition 
with different parameter names
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'S1::f' has a definition 
with different parameter names
+  // CHECK-NOTES: :[[@LINE-5]]:8: note: expanded from macro 'MACRO'
+  // CHECK-NOTES: :[[@LINE+4]]:10: note: the definition seen here
+  // CHECK-NOTES: :[[@LINE-4]]:3: note: differing parameters are named here: 
('x'), in definition: ('y')
+  // CHECK-NOTES: :[[@LINE-8]]:8: note: expanded from macro 'MACRO'
 };
+void S1::f(int y) {}
 
-void S::f(int y) {
-}
+struct S2 {
+  int g() const;
+  void set_g(int g);
+  // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'S2::set_g' has a 
definition with different parameter names
+  // CHECK-NOTES: :[[@LINE+14]]:1: note: the definition seen here
+  // CHECK-NOTES: :[[@LINE+9]]:12: note: expanded from macro 'DEFINITION'
+  // This one is unfortunate, but the location this points to is in a scratch
+  // space, so it's not helpful to the user.
+  // CHECK-NOTES: {{^}}note: expanded from here{{$}}
+  // CHECK-NOTES: :[[@LINE-7]]:8: note: differing parameters are named here: 
('g'), in definition: ('w')
+};
+
+#define DEFINITION(name, parameter)\
+  int S2::name() const { return 0; }   \
+  void S2::set_##name(int parameter) { \
+(void)parameter;   \
+  }
+
+DEFINITION(g, w)
 
 //
 
 #define DECLARE_FUNCTION_WITH_PARAM_NAME(function_name, param_name) \
   void function_name(int param_name)
 
-// CHECK-MESSAGES: :[[@LINE+1]]:34: warning: function 'macroFunction' has 1 
other declaration with different parameter names 
[readability-inconsistent-declaration-parameter-name]
+// CHECK-NOTES: :[[@LINE+1]]:34: warning: function 'macroFunction' has 1 other 
declaration with different parameter names 
[readability-inconsistent-declaration-parameter-name]
 DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, a);
-// CHECK-MESSAGES: :[[@LINE+2]]:34: note: the 1st inconsistent declaration 
seen here
-// CHECK-MESSAGES: :[[@LINE+1]]:34: note: differing parameters are named here: 
('b'), in the other declaration: ('a')
+// CHECK-NOTES: :[[@LINE+2]]:34: note: the 1st inconsistent declaration seen 
here
+// CHECK-NOTES: :[[@LINE+1]]:34: note: differing parameters are named here: 
('b'), in the other declaration: ('a')
 DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, b);


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


r347371 - Implement YAML serialization of notes in clang::tooling::Diagnostic.

2018-11-20 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Nov 20 17:06:32 2018
New Revision: 347371

URL: http://llvm.org/viewvc/llvm-project?rev=347371&view=rev
Log:
Implement YAML serialization of notes in clang::tooling::Diagnostic.

Modified:
cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp

Modified: cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h?rev=347371&r1=347370&r2=347371&view=diff
==
--- cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h (original)
+++ cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h Tue Nov 20 17:06:32 2018
@@ -22,10 +22,19 @@
 #include 
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic)
+LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::DiagnosticMessage)
 
 namespace llvm {
 namespace yaml {
 
+template <> struct MappingTraits {
+  static void mapping(IO &Io, clang::tooling::DiagnosticMessage &M) {
+Io.mapRequired("Message", M.Message);
+Io.mapOptional("FilePath", M.FilePath);
+Io.mapOptional("FileOffset", M.FileOffset);
+  }
+};
+
 template <> struct MappingTraits {
   /// Helper to (de)serialize a Diagnostic since we don't have direct
   /// access to its data members.
@@ -59,6 +68,7 @@ template <> struct MappingTraitsMessage.Message);
 Io.mapRequired("FileOffset", Keys->Message.FileOffset);
 Io.mapRequired("FilePath", Keys->Message.FilePath);
+Io.mapOptional("Notes", Keys->Notes);
 
 // FIXME: Export properly all the different fields.
 

Modified: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp?rev=347371&r1=347370&r2=347371&view=diff
==
--- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Tue Nov 20 17:06:32 2018
@@ -20,16 +20,21 @@ using namespace llvm;
 using namespace clang::tooling;
 using clang::tooling::Diagnostic;
 
-static Diagnostic makeDiagnostic(StringRef DiagnosticName,
- const std::string &Message, int FileOffset,
- const std::string &FilePath,
- const StringMap &Fix) {
+static DiagnosticMessage makeMessage(const std::string &Message, int 
FileOffset,
+ const std::string &FilePath) {
   DiagnosticMessage DiagMessage;
   DiagMessage.Message = Message;
   DiagMessage.FileOffset = FileOffset;
   DiagMessage.FilePath = FilePath;
-  return Diagnostic(DiagnosticName, DiagMessage, Fix, {}, Diagnostic::Warning,
-"path/to/build/directory");
+  return DiagMessage;
+}
+
+static Diagnostic makeDiagnostic(StringRef DiagnosticName,
+ const std::string &Message, int FileOffset,
+ const std::string &FilePath,
+ const StringMap &Fix) {
+  return Diagnostic(DiagnosticName, makeMessage(Message, FileOffset, FilePath),
+Fix, {}, Diagnostic::Warning, "path/to/build/directory");
 }
 
 TEST(DiagnosticsYamlTest, serializesDiagnostics) {
@@ -50,6 +55,10 @@ TEST(DiagnosticsYamlTest, serializesDiag
 
   TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72,
"path/to/source2.cpp", {}));
+  TUD.Diagnostics.back().Notes.push_back(
+  makeMessage("Note1", 88, "path/to/note1.cpp"));
+  TUD.Diagnostics.back().Notes.push_back(
+  makeMessage("Note2", 99, "path/to/note2.cpp"));
 
   std::string YamlContent;
   raw_string_ostream YamlContentStream(YamlContent);
@@ -82,6 +91,13 @@ TEST(DiagnosticsYamlTest, serializesDiag
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
+"Notes:   \n"
+"  - Message: Note1\n"
+"FilePath:'path/to/note1.cpp'\n"
+"FileOffset:  88\n"
+"  - Message: Note2\n"
+"FilePath:'path/to/note2.cpp'\n"
+"FileOffset:  99\n"
 "Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
@@ -113,6 +129,13 @@ TEST(DiagnosticsYamlTest, deserializesDi
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
+"Notes:\n"
+"  - Message: Note1\n"
+"FilePath:'path/to/note1.cpp'\n"
+"FileOffset:

r347372 - clang::tooling::Diagnostic: Don't store offset in the scratch space.

2018-11-20 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Nov 20 17:08:46 2018
New Revision: 347372

URL: http://llvm.org/viewvc/llvm-project?rev=347372&view=rev
Log:
clang::tooling::Diagnostic: Don't store offset in the scratch space.

These offsets are useless (and even harmful in certain cases) in exported
diagnostics. The test will be added to clang-tidy, since it's the main user of
the clang::tooling::Diagnostic class.

Modified:
cfe/trunk/lib/Tooling/Core/Diagnostic.cpp

Modified: cfe/trunk/lib/Tooling/Core/Diagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/Diagnostic.cpp?rev=347372&r1=347371&r2=347372&view=diff
==
--- cfe/trunk/lib/Tooling/Core/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Tooling/Core/Diagnostic.cpp Tue Nov 20 17:08:46 2018
@@ -23,10 +23,15 @@ DiagnosticMessage::DiagnosticMessage(llv
 DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message,
  const SourceManager &Sources,
  SourceLocation Loc)
-: Message(Message) {
+: Message(Message), FileOffset(0) {
   assert(Loc.isValid() && Loc.isFileID());
   FilePath = Sources.getFilename(Loc);
-  FileOffset = Sources.getFileOffset(Loc);
+
+  // Don't store offset in the scratch space. It doesn't tell anything to the
+  // user. Moreover, it depends on the history of macro expansions and thus
+  // prevents deduplication of warnings in headers.
+  if (!FilePath.empty())
+FileOffset = Sources.getFileOffset(Loc);
 }
 
 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,


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


[clang-tools-extra] r347373 - [clang-tidy] Add a test for proper handling of locations in scratch space.

2018-11-20 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Nov 20 17:11:18 2018
New Revision: 347373

URL: http://llvm.org/viewvc/llvm-project?rev=347373&view=rev
Log:
[clang-tidy] Add a test for proper handling of locations in scratch space.

This test examines the behavior change of clang::tooling::Diagnostic in r347372.

Added:
clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp?rev=347373&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp Tue Nov 20 
17:11:18 2018
@@ -0,0 +1,28 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
+// RUN: clang-tidy %t-input.cpp 
-checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' 
-export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
+// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s 
-implicit-check-not='{{warning|error|note}}:'
+// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
+#define X(n) void n ## n() {}
+X(f)
+
+// CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 
'ff' [clang-diagnostic-missing-prototypes]
+// CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
+// CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
+
+// CHECK-YAML: ---
+// CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
+// CHECK-YAML-NEXT: Diagnostics:
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-missing-prototypes
+// CHECK-YAML-NEXT: Message: 'no previous prototype for function 
''ff'''
+// CHECK-YAML-NEXT: FileOffset:  30
+// CHECK-YAML-NEXT: FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT: Notes:
+// CHECK-YAML-NEXT:   - Message: 'expanded from macro ''X'''
+// CHECK-YAML-NEXT: FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT: FileOffset:  18
+// CHECK-YAML-NEXT:   - Message: expanded from here
+// CHECK-YAML-NEXT: FilePath:''
+// CHECK-YAML-NEXT: FileOffset:  0
+// CHECK-YAML-NEXT: Replacements:[]
+// CHECK-YAML-NEXT: ...
+


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


[clang-tools-extra] r347470 - [clang-tidy] Ignore template instantiations in modernize-use-using

2018-11-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Nov 22 08:10:18 2018
New Revision: 347470

URL: http://llvm.org/viewvc/llvm-project?rev=347470&view=rev
Log:
[clang-tidy] Ignore template instantiations in modernize-use-using

The test I'm adding passes without the change due to the deduplication logic in
ClangTidyDiagnosticConsumer::take(). However this bug manifests in our internal
integration with clang-tidy.
I've verified the fix by locally changing LessClangTidyError to consider
replacements.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp?rev=347470&r1=347469&r2=347470&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp Thu Nov 22 
08:10:18 2018
@@ -24,7 +24,8 @@ UseUsingCheck::UseUsingCheck(StringRef N
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
 return;
-  Finder->addMatcher(typedefDecl().bind("typedef"), this);
+  Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
+ this);
 }
 
 // Checks if 'typedef' keyword can be removed - we do it only if

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp?rev=347470&r1=347469&r2=347470&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp Thu Nov 22 
08:10:18 2018
@@ -162,3 +162,24 @@ typedef unsigned Map[lol];
 typedef void (*fun_type)();
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using fun_type = void (*)();
+
+namespace template_instantiations {
+template 
+class C {
+ protected:
+  typedef C super;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+  // CHECK-FIXES: using super = C;
+  virtual void f();
+
+public:
+  virtual ~C();
+};
+
+class D : public C {
+  void f() override { super::f(); }
+};
+class E : public C {
+  void f() override { super::f(); }
+};
+}


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


[clang-tools-extra] r347495 - [clang-tidy] Ignore matches in template instantiations (cert-dcl21-cpp)

2018-11-23 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Nov 23 06:30:14 2018
New Revision: 347495

URL: http://llvm.org/viewvc/llvm-project?rev=347495&view=rev
Log:
[clang-tidy] Ignore matches in template instantiations (cert-dcl21-cpp)

The test fails with a local modification to
clang-tidy/ClangTidyDiagnosticConsumer.cpp to include fixes into the key when
deduplicating the warnings.

Modified:
clang-tools-extra/trunk/clang-tidy/cert/PostfixOperatorCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/PostfixOperatorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/PostfixOperatorCheck.cpp?rev=347495&r1=347494&r2=347495&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/PostfixOperatorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/PostfixOperatorCheck.cpp Fri Nov 23 
06:30:14 2018
@@ -23,7 +23,8 @@ void PostfixOperatorCheck::registerMatch
 return;
 
   Finder->addMatcher(functionDecl(anyOf(hasOverloadedOperatorName("++"),
-hasOverloadedOperatorName("--")))
+hasOverloadedOperatorName("--")),
+  unless(isInstantiated()))
  .bind("decl"),
  this);
 }


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


[clang-tools-extra] r347520 - A bit of AST matcher cleanup, NFC.

2018-11-24 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Sat Nov 24 18:41:01 2018
New Revision: 347520

URL: http://llvm.org/viewvc/llvm-project?rev=347520&view=rev
Log:
A bit of AST matcher cleanup, NFC.

Removed the uses of the allOf() matcher inside node matchers that are implicit
allOf(). Replaced uses of allOf() with the explicit node matcher where it makes
matchers more readable. Replace anyOf(hasName(), hasName(), ...) with the more
efficient and readable hasAnyName().

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp

clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp

clang-tools-extra/trunk/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp

clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tools-extra/trunk/clang-tidy/zircon/TemporaryObjectsCheck.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=347520&r1=347519&r2=347520&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Sat Nov 24 
18:41:01 2018
@@ -450,8 +450,8 @@ void ChangeNamespaceTool::registerMatche
   typeLoc(IsInMovedNs,
   loc(qualType(hasDeclaration(DeclMatcher.bind("from_decl",
   unless(anyOf(hasParent(typeLoc(loc(qualType(
-   allOf(hasDeclaration(DeclMatcher),
- unless(templateSpecializationType())),
+   hasDeclaration(DeclMatcher),
+   unless(templateSpecializationType()),
hasParent(nestedNameSpecifierLoc()),
hasAncestor(isImplicit()),
hasAncestor(UsingShadowDeclInClass),
@@ -505,13 +505,12 @@ void ChangeNamespaceTool::registerMatche
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  expr(allOf(hasAncestor(decl().bind("dc")), IsInMovedNs,
- unless(hasAncestor(isImplicit())),
- anyOf(callExpr(callee(FuncMatcher)).bind("call"),
-   declRefExpr(to(FuncMatcher.bind("func_decl")))
-   .bind("func_ref",
-  this);
+  Finder->addMatcher(expr(hasAncestor(decl().bind("dc")), IsInMovedNs,
+  unless(hasAncestor(isImplicit())),
+  anyOf(callExpr(callee(FuncMatcher)).bind("call"),
+declRefExpr(to(FuncMatcher.bind("func_decl")))
+.bind("func_ref"))),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-ex

Re: [clang-tools-extra] r347520 - A bit of AST matcher cleanup, NFC.

2018-11-25 Thread Alexander Kornienko via cfe-commits
On Sun, Nov 25, 2018 at 1:52 PM Aaron Ballman 
wrote:

> On Sat, Nov 24, 2018 at 9:43 PM Alexander Kornienko via cfe-commits
>  wrote:
> >
> > Author: alexfh
> > Date: Sat Nov 24 18:41:01 2018
> > New Revision: 347520
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=347520&view=rev
> > Log:
> > A bit of AST matcher cleanup, NFC.
> >
> > Removed the uses of the allOf() matcher inside node matchers that are
> implicit
> > allOf(). Replaced uses of allOf() with the explicit node matcher where
> it makes
> > matchers more readable. Replace anyOf(hasName(), hasName(), ...) with
> the more
> > efficient and readable hasAnyName().
>
> Would it make sense to have a check under the llvm module for this
> coding pattern?
>

Probably yes, but I wouldn't be too optimistic about the positive impact of
that check compared to the cost of creating and supporting it.

If someone has a large enough chunk of time they could devote to improving
clang-tidy performance, there was an interesting idea about optimizing AST
matchers at runtime. E.g. currently `unless(isInTemplateInstantiation())`
matchers go up the ancestor chain, but a more efficient implementation
could just skip traversal of template instantiations for the matchers that
have the `unless(isInTemplateInstantiation())` constraint. To implement
this, the matchers framework would need to analyze the matchers and rewrite
them (instead of just passing control to them).


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


[clang-tools-extra] r347546 - [clang-tidy] PrintStackTraceOnErrorSignal

2018-11-26 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Nov 26 03:11:52 2018
New Revision: 347546

URL: http://llvm.org/viewvc/llvm-project?rev=347546&view=rev
Log:
[clang-tidy] PrintStackTraceOnErrorSignal

Modified:
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=347546&r1=347545&r2=347546&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Nov 26 
03:11:52 2018
@@ -19,6 +19,7 @@
 #include "clang/Config/config.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 using namespace clang::ast_matchers;
@@ -328,6 +329,7 @@ getVfsOverlayFromFile(const std::string
 }
 
 static int clangTidyMain(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
 cl::ZeroOrMore);
   llvm::IntrusiveRefCntPtr BaseFS(


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


[clang-tools-extra] r347652 - [clang-tidy] Avoid inconsistent notes in readability-container-size-empty

2018-11-27 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Nov 27 02:53:44 2018
New Revision: 347652

URL: http://llvm.org/viewvc/llvm-project?rev=347652&view=rev
Log:
[clang-tidy] Avoid inconsistent notes in readability-container-size-empty

When a warning is issued in a template instantiation, the check would previously
use template arguments in a note, which would result in inconsistent or
duplicate warnings (depending on how deduplication was done). This patch removes
template arguments from the note.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=347652&r1=347651&r2=347652&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
Tue Nov 27 02:53:44 2018
@@ -213,6 +213,14 @@ void ContainerSizeEmptyCheck::check(cons
   }
 
   const auto *Container = Result.Nodes.getNodeAs("container");
+  if (const auto *CTS = dyn_cast(Container)) {
+// The definition of the empty() method is the same for all implicit
+// instantiations. In order to avoid duplicate or inconsistent warnings
+// (depending on how deduplication is done), we use the same class name
+// for all implicit instantiations of a template.
+if (CTS->getSpecializationKind() == TSK_ImplicitInstantiation)
+  Container = CTS->getSpecializedTemplate();
+  }
   const auto *Empty = Result.Nodes.getNodeAs("empty");
 
   diag(Empty->getLocation(), "method %0::empty() defined here",

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp?rev=347652&r1=347651&r2=347652&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
Tue Nov 27 02:53:44 2018
@@ -113,12 +113,12 @@ int main() {
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -407,6 +407,7 @@ template  void f() {
   if (v.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness instead of 'size' [readability-container-size-empty]
+  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: {{^  }}if (!v.empty()){{$}}
   if (v == std::vector())
 ;
@@ -415,20 +416,24 @@ template  void f() {
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(v);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be 
used
+  // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
   // CHECK-FIXES: CHECKSIZE(v);
 
   TemplatedContainer templated_container;
   if (templated_container.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined 
here
   // CHECK-FIXES: {{^  }}if (!templated_container.empty()){{$}}
   if (templated_container != TemplatedContainer())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined 
here
   // CHECK-FIXES: {{^  }}if (!templated_container.empty()){{$}}
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(templated_container);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be 
used
+  // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined 
here
   // CHECK-FIXES: CHECKSIZE(templated_container);
 }
 


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


[clang-tools-extra] r347651 - [clang-tidy] Minor fixes in a test

2018-11-27 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Nov 27 02:53:38 2018
New Revision: 347651

URL: http://llvm.org/viewvc/llvm-project?rev=347651&view=rev
Log:
[clang-tidy] Minor fixes in a test

Use CHECK-FIXES where it was intended instead of CHECK-MESSAGES. Fixed compiler
warnings to pacify YouCompleteMe.

Modified:
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp?rev=347651&r1=347650&r2=347651&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
Tue Nov 27 02:53:38 2018
@@ -105,10 +105,10 @@ int main() {
   std::string str;
   std::string str2;
   std::wstring wstr;
-  str.size() + 0;
-  str.size() - 0;
-  0 + str.size();
-  0 - str.size();
+  (void)(str.size() + 0);
+  (void)(str.size() - 0);
+  (void)(0 + str.size());
+  (void)(0 - str.size());
   if (intSet.size() == 0)
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness instead of 'size' [readability-container-size-empty]
@@ -399,8 +399,8 @@ int main() {
   // CHECK-FIXES: {{^  }}if (derived.empty()){{$}}
 }
 
-#define CHECKSIZE(x) if (x.size())
-// CHECK-FIXES: #define CHECKSIZE(x) if (x.size())
+#define CHECKSIZE(x) if (x.size()) {}
+// CHECK-FIXES: #define CHECKSIZE(x) if (x.size()) {}
 
 template  void f() {
   std::vector v;
@@ -415,7 +415,7 @@ template  void f() {
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(v);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be 
used
-  // CHECK-MESSAGES: CHECKSIZE(v);
+  // CHECK-FIXES: CHECKSIZE(v);
 
   TemplatedContainer templated_container;
   if (templated_container.size())
@@ -429,7 +429,7 @@ template  void f() {
   // CHECK-FIXES-NEXT: ;
   CHECKSIZE(templated_container);
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be 
used
-  // CHECK-MESSAGES: CHECKSIZE(templated_container);
+  // CHECK-FIXES: CHECKSIZE(templated_container);
 }
 
 void g() {


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


Re: r354795 - Make static counters in ASTContext non-static.

2019-02-25 Thread Alexander Kornienko via cfe-commits
Thank you for taking care of this! That's a bug indeed. Will recommit with
a fix.

On Mon, Feb 25, 2019 at 9:25 PM Vlad Tsyrklevich 
wrote:

> I've reverted this commit in r354812, it was causing MSan failures like
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/29886/steps/check-clang%20msan/logs/stdio
>  Though
> these error reports don't clearly implicate this change, from your change
> it seems like the failure is occurring because you changed static
> (zero-initialized) variables to member (uninitialized) variables that were
> then never initialized before being used. The build recovered after the
> revert landed in
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/29894
>
> On Mon, Feb 25, 2019 at 8:07 AM Alexander Kornienko via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: alexfh
>> Date: Mon Feb 25 08:08:46 2019
>> New Revision: 354795
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=354795&view=rev
>> Log:
>> Make static counters in ASTContext non-static.
>>
>> Summary:
>> Fixes a data race and makes it possible to run clang-based tools in
>> multithreaded environment with TSan.
>>
>> Reviewers: ilya-biryukov, riccibruno
>>
>> Reviewed By: riccibruno
>>
>> Subscribers: riccibruno, jfb, cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D58612
>>
>> Modified:
>> cfe/trunk/include/clang/AST/ASTContext.h
>> cfe/trunk/lib/AST/ASTContext.cpp
>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=354795&r1=354794&r2=354795&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>> +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Feb 25 08:08:46 2019
>> @@ -2809,46 +2809,46 @@ public:
>>
>>  
>> //======//
>>
>>/// The number of implicitly-declared default constructors.
>> -  static unsigned NumImplicitDefaultConstructors;
>> +  unsigned NumImplicitDefaultConstructors;
>>
>>/// The number of implicitly-declared default constructors for
>>/// which declarations were built.
>> -  static unsigned NumImplicitDefaultConstructorsDeclared;
>> +  unsigned NumImplicitDefaultConstructorsDeclared;
>>
>>/// The number of implicitly-declared copy constructors.
>> -  static unsigned NumImplicitCopyConstructors;
>> +  unsigned NumImplicitCopyConstructors;
>>
>>/// The number of implicitly-declared copy constructors for
>>/// which declarations were built.
>> -  static unsigned NumImplicitCopyConstructorsDeclared;
>> +  unsigned NumImplicitCopyConstructorsDeclared;
>>
>>/// The number of implicitly-declared move constructors.
>> -  static unsigned NumImplicitMoveConstructors;
>> +  unsigned NumImplicitMoveConstructors;
>>
>>/// The number of implicitly-declared move constructors for
>>/// which declarations were built.
>> -  static unsigned NumImplicitMoveConstructorsDeclared;
>> +  unsigned NumImplicitMoveConstructorsDeclared;
>>
>>/// The number of implicitly-declared copy assignment operators.
>> -  static unsigned NumImplicitCopyAssignmentOperators;
>> +  unsigned NumImplicitCopyAssignmentOperators;
>>
>>/// The number of implicitly-declared copy assignment operators for
>>/// which declarations were built.
>> -  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
>> +  unsigned NumImplicitCopyAssignmentOperatorsDeclared;
>>
>>/// The number of implicitly-declared move assignment operators.
>> -  static unsigned NumImplicitMoveAssignmentOperators;
>> +  unsigned NumImplicitMoveAssignmentOperators;
>>
>>/// The number of implicitly-declared move assignment operators for
>>/// which declarations were built.
>> -  static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
>> +  unsigned NumImplicitMoveAssignmentOperatorsDeclared;
>>
>>/// The number of implicitly-declared destructors.
>> -  static unsigned NumImplicitDestructors;
>> +  unsigned NumImplicitDestructors;
>>
>>/// The number of implicitly-declared destructors for which
>>/// declarations were built.
>> -  static unsigned NumImplicitDest

r354827 - Reapply "Make static counters in ASTContext non-static." with fixes.

2019-02-25 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Feb 25 14:22:09 2019
New Revision: 354827

URL: http://llvm.org/viewvc/llvm-project?rev=354827&view=rev
Log:
Reapply "Make static counters in ASTContext non-static." with fixes.

This reverts commit e50038e4dc53caee1acc811362ac0b15e00ef5eb.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=354827&r1=354826&r2=354827&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Feb 25 14:22:09 2019
@@ -2809,46 +2809,46 @@ public:
   
//======//
 
   /// The number of implicitly-declared default constructors.
-  static unsigned NumImplicitDefaultConstructors;
+  unsigned NumImplicitDefaultConstructors = 0;
 
   /// The number of implicitly-declared default constructors for
   /// which declarations were built.
-  static unsigned NumImplicitDefaultConstructorsDeclared;
+  unsigned NumImplicitDefaultConstructorsDeclared = 0;
 
   /// The number of implicitly-declared copy constructors.
-  static unsigned NumImplicitCopyConstructors;
+  unsigned NumImplicitCopyConstructors = 0;
 
   /// The number of implicitly-declared copy constructors for
   /// which declarations were built.
-  static unsigned NumImplicitCopyConstructorsDeclared;
+  unsigned NumImplicitCopyConstructorsDeclared = 0;
 
   /// The number of implicitly-declared move constructors.
-  static unsigned NumImplicitMoveConstructors;
+  unsigned NumImplicitMoveConstructors = 0;
 
   /// The number of implicitly-declared move constructors for
   /// which declarations were built.
-  static unsigned NumImplicitMoveConstructorsDeclared;
+  unsigned NumImplicitMoveConstructorsDeclared = 0;
 
   /// The number of implicitly-declared copy assignment operators.
-  static unsigned NumImplicitCopyAssignmentOperators;
+  unsigned NumImplicitCopyAssignmentOperators = 0;
 
   /// The number of implicitly-declared copy assignment operators for
   /// which declarations were built.
-  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
+  unsigned NumImplicitCopyAssignmentOperatorsDeclared = 0;
 
   /// The number of implicitly-declared move assignment operators.
-  static unsigned NumImplicitMoveAssignmentOperators;
+  unsigned NumImplicitMoveAssignmentOperators = 0;
 
   /// The number of implicitly-declared move assignment operators for
   /// which declarations were built.
-  static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
+  unsigned NumImplicitMoveAssignmentOperatorsDeclared = 0;
 
   /// The number of implicitly-declared destructors.
-  static unsigned NumImplicitDestructors;
+  unsigned NumImplicitDestructors = 0;
 
   /// The number of implicitly-declared destructors for which
   /// declarations were built.
-  static unsigned NumImplicitDestructorsDeclared;
+  unsigned NumImplicitDestructorsDeclared = 0;
 
 public:
   /// Initialize built-in types.

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=354827&r1=354826&r2=354827&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Feb 25 14:22:09 2019
@@ -94,19 +94,6 @@
 
 using namespace clang;
 
-unsigned ASTContext::NumImplicitDefaultConstructors;
-unsigned ASTContext::NumImplicitDefaultConstructorsDeclared;
-unsigned ASTContext::NumImplicitCopyConstructors;
-unsigned ASTContext::NumImplicitCopyConstructorsDeclared;
-unsigned ASTContext::NumImplicitMoveConstructors;
-unsigned ASTContext::NumImplicitMoveConstructorsDeclared;
-unsigned ASTContext::NumImplicitCopyAssignmentOperators;
-unsigned ASTContext::NumImplicitCopyAssignmentOperatorsDeclared;
-unsigned ASTContext::NumImplicitMoveAssignmentOperators;
-unsigned ASTContext::NumImplicitMoveAssignmentOperatorsDeclared;
-unsigned ASTContext::NumImplicitDestructors;
-unsigned ASTContext::NumImplicitDestructorsDeclared;
-
 enum FloatingRank {
   Float16Rank, HalfRank, FloatRank, DoubleRank, LongDoubleRank, Float128Rank
 };

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=354827&r1=354826&r2=354827&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Feb 25 14:22:09 2019
@@ -7971,14 +7971,14 @@ void Sema::ActOnFinishCXXMemberSpecifica
 /// definition of the class is complete.
 void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) {
   if (ClassDecl->needsImplicitDefaultConstructor()) {
-   

Re: r354795 - Make static counters in ASTContext non-static.

2019-02-25 Thread Alexander Kornienko via cfe-commits
Done. r354827 should be better.

On Mon, Feb 25, 2019 at 11:18 PM Alexander Kornienko 
wrote:

> Thank you for taking care of this! That's a bug indeed. Will recommit with
> a fix.
>
> On Mon, Feb 25, 2019 at 9:25 PM Vlad Tsyrklevich 
> wrote:
>
>> I've reverted this commit in r354812, it was causing MSan failures like
>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/29886/steps/check-clang%20msan/logs/stdio
>>  Though
>> these error reports don't clearly implicate this change, from your change
>> it seems like the failure is occurring because you changed static
>> (zero-initialized) variables to member (uninitialized) variables that were
>> then never initialized before being used. The build recovered after the
>> revert landed in
>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/29894
>>
>> On Mon, Feb 25, 2019 at 8:07 AM Alexander Kornienko via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: alexfh
>>> Date: Mon Feb 25 08:08:46 2019
>>> New Revision: 354795
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=354795&view=rev
>>> Log:
>>> Make static counters in ASTContext non-static.
>>>
>>> Summary:
>>> Fixes a data race and makes it possible to run clang-based tools in
>>> multithreaded environment with TSan.
>>>
>>> Reviewers: ilya-biryukov, riccibruno
>>>
>>> Reviewed By: riccibruno
>>>
>>> Subscribers: riccibruno, jfb, cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revision: https://reviews.llvm.org/D58612
>>>
>>> Modified:
>>> cfe/trunk/include/clang/AST/ASTContext.h
>>> cfe/trunk/lib/AST/ASTContext.cpp
>>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>>>
>>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=354795&r1=354794&r2=354795&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>>> +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Feb 25 08:08:46 2019
>>> @@ -2809,46 +2809,46 @@ public:
>>>
>>>  
>>> //======//
>>>
>>>/// The number of implicitly-declared default constructors.
>>> -  static unsigned NumImplicitDefaultConstructors;
>>> +  unsigned NumImplicitDefaultConstructors;
>>>
>>>/// The number of implicitly-declared default constructors for
>>>/// which declarations were built.
>>> -  static unsigned NumImplicitDefaultConstructorsDeclared;
>>> +  unsigned NumImplicitDefaultConstructorsDeclared;
>>>
>>>/// The number of implicitly-declared copy constructors.
>>> -  static unsigned NumImplicitCopyConstructors;
>>> +  unsigned NumImplicitCopyConstructors;
>>>
>>>/// The number of implicitly-declared copy constructors for
>>>/// which declarations were built.
>>> -  static unsigned NumImplicitCopyConstructorsDeclared;
>>> +  unsigned NumImplicitCopyConstructorsDeclared;
>>>
>>>/// The number of implicitly-declared move constructors.
>>> -  static unsigned NumImplicitMoveConstructors;
>>> +  unsigned NumImplicitMoveConstructors;
>>>
>>>/// The number of implicitly-declared move constructors for
>>>/// which declarations were built.
>>> -  static unsigned NumImplicitMoveConstructorsDeclared;
>>> +  unsigned NumImplicitMoveConstructorsDeclared;
>>>
>>>/// The number of implicitly-declared copy assignment operators.
>>> -  static unsigned NumImplicitCopyAssignmentOperators;
>>> +  unsigned NumImplicitCopyAssignmentOperators;
>>>
>>>/// The number of implicitly-declared copy assignment operators for
>>>/// which declarations were built.
>>> -  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
>>> +  unsigned NumImplicitCopyAssignmentOperatorsDeclared;
>>>
>>>/// The number of implicitly-declared move assignment operators.
>>> -  static unsigned NumImplicitMoveAssignmentOperators;
>>> +  unsigned NumImplicitMoveAssignmentOperators;
>>>
>>>/// The number of implicitly-declared move assignment operators for
>>>/// which declarations we

[clang-tools-extra] r355401 - [clang-tidy] Fix bugprone-string-constructor crash

2019-03-05 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Mar  5 06:09:57 2019
New Revision: 355401

URL: http://llvm.org/viewvc/llvm-project?rev=355401&view=rev
Log:
[clang-tidy] Fix bugprone-string-constructor crash

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

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp?rev=355401&r1=355400&r2=355401&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp Tue 
Mar  5 06:09:57 2019
@@ -138,7 +138,8 @@ void StringConstructorCheck::check(const
 }
   } else if (const auto *Ptr = Result.Nodes.getNodeAs("from-ptr")) {
 Expr::EvalResult ConstPtr;
-if (Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
+if (!Ptr->isInstantiationDependent() &&
+Ptr->EvaluateAsRValue(ConstPtr, Ctx) &&
 ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isNullValue()) ||
  (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer( {
   diag(Loc, "constructing string from nullptr is undefined behaviour");

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp?rev=355401&r1=355400&r2=355401&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp Tue 
Mar  5 06:09:57 2019
@@ -65,3 +65,11 @@ void Valid() {
   std::string s2("test", 3);
   std::string s3("test");
 }
+
+namespace instantiation_dependent_exprs {
+template
+struct S {
+  bool x;
+  std::string f() { return x ? "a" : "b"; }
+};
+}


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


Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-18 Thread Alexander Kornienko via cfe-commits
On Fri, Mar 15, 2019 at 1:21 AM Artem Dergachev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: dergachev
> Date: Thu Mar 14 17:22:59 2019
> New Revision: 356222
>
> URL: http://llvm.org/viewvc/llvm-project?rev=356222&view=rev
> Log:
> [analyzer] Support C++17 aggregates with bases without constructors.
>
> RegionStore now knows how to bind a nonloc::CompoundVal that represents the
> value of an aggregate initializer when it has its initial segment of
> sub-values
> correspond to base classes.
>
> Additionally, fixes the crash from pr40022.
>
> Differential Revision: https://reviews.llvm.org/D59054
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
> cfe/trunk/test/Analysis/array-struct-region.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=356222&r1=356221&r2=356222&view=diff
>
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Thu Mar 14 17:22:59
> 2019
> @@ -2334,12 +2334,57 @@ RegionBindingsRef RegionStoreManager::bi
>if (V.isUnknown() || !V.getAs())
>  return bindAggregate(B, R, UnknownVal());
>
> +  // The raw CompoundVal is essentially a symbolic InitListExpr: an
> (immutable)
> +  // list of other values. It appears pretty much only when there's an
> actual
> +  // initializer list expression in the program, and the analyzer tries to
> +  // unwrap it as soon as possible.
> +  // This code is where such unwrap happens: when the compound value is
> put into
> +  // the object that it was supposed to initialize (it's an *initializer*
> list,
> +  // after all), instead of binding the whole value to the whole object,
> we bind
> +  // sub-values to sub-objects. Sub-values may themselves be compound
> values,
> +  // and in this case the procedure becomes recursive.
> +  // FIXME: The annoying part about compound values is that they don't
> carry
> +  // any sort of information about which value corresponds to which
> sub-object.
> +  // It's simply a list of values in the middle of nowhere; we expect to
> match
> +  // them to sub-objects, essentially, "by index": first value binds to
> +  // the first field, second value binds to the second field, etc.
> +  // It would have been much safer to organize non-lazy compound values as
> +  // a mapping from fields/bases to values.
>const nonloc::CompoundVal& CV = V.castAs();
>nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
>
> -  RecordDecl::field_iterator FI, FE;
>RegionBindingsRef NewB(B);
>
> +  // In C++17 aggregates may have base classes, handle those as well.
> +  // They appear before fields in the initializer list / compound value.
> +  if (const auto *CRD = dyn_cast(RD)) {
> +assert(CRD->isAggregate() &&
> +   "Non-aggregates are constructed with a constructor!");


Now we see this assertion being triggered on a substantial number of files
in our codebase:
llvm/tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in (anonymous
namespace)::RegionBindingsRef (anonymous
namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef, const
clang::ento::TypedValueRegion *, clang::ento::SVal): CRD->isAggregate() &&
"Non-aggregates are constructed with a constructor!"
Stack trace:
@ 0x5596b00a84e6 96  __assert_fail
@ 0x5596b6e6ea14304  (anonymous
namespace)::RegionStoreManager::bindStruct()
@ 0x5596afb30228128  (anonymous
namespace)::RegionStoreManager::Bind()
@ 0x5596af822abf128  clang::ento::ProgramState::bindLoc()
@ 0x5596b6e2b657112
clang::ento::ExprEngine::processPointerEscapedOnBind()
@ 0x5596b907f65f512  clang::ento::ExprEngine::evalBind()
@ 0x5596b6e30ea7560
clang::ento::ExprEngine::VisitDeclStmt()
@ 0x5596b8da1fe2752  clang::ento::ExprEngine::Visit()
@ 0x5596b8d9cb2f400  clang::ento::ExprEngine::ProcessStmt()
@ 0x5596af78431e112
clang::ento::ExprEngine::processCFGElement()
@ 0x5596af6578e0 48
clang::ento::CoreEngine::HandlePostStmt()
@ 0x5596b03b151b272
clang::ento::CoreEngine::ExecuteWorkList()
@ 0x5596af6f8efe   1248  (anonymous
namespace)::AnalysisConsumer::HandleCode()
@ 0x5596b6c54a77448  (anonymous
namespace)::AnalysisConsumer::HandleTranslationUnit()
@ 0x5596b706f08c 48
clang::MultiplexConsumer::HandleTranslationUnit()
@ 0x5596aff72e24144  clang::ParseAST()
@ 0x5596b7053bc3 48  clang::FrontendAction::Execute()
@ 0x5596b7002ba0160
clang::CompilerInstance::ExecuteAction()
@ 0x5596b6f91a61464
clang::tooling::FrontendActionFactory::runInvocation()
@ 0x5596b6f917ea 80
clang::t

Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-19 Thread Alexander Kornienko via cfe-commits
A reduced test case:
$ cat test-RegionStoreManager__bindStruct.cc
struct a {};
class b : a {};
b c() { b d{c()}; }
$ ./clang-tidy -checks="-*,clang-analyzer*"
test-RegionStoreManager__bindStruct.cc -- -std=c++17
assert.h assertion failed at
tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in (anonymous
namespace)::RegionBindingsRef (anonym
ous namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef,
const clang::ento::TypedValueRegion *, clang::ento::SVal):
CRD->isAggregate() && "Non-aggregates are constructed with a constructor!"
@ 0x559908170326  __assert_fail
@ 0x5599068d4854  (anonymous
namespace)::RegionStoreManager::bindStruct()
@ 0x5599068c93c8  (anonymous namespace)::RegionStoreManager::Bind()
@ 0x5599068b409f  clang::ento::ProgramState::bindLoc()
@ 0x559906865935
clang::ento::ExprEngine::processPointerEscapedOnBind()
@ 0x55990685d4b3  clang::ento::ExprEngine::evalBind()
@ 0x559906872a43  clang::ento::ExprEngine::VisitDeclStmt()
@ 0x55990685c16f  clang::ento::ExprEngine::Visit()
@ 0x559906858b1f  clang::ento::ExprEngine::ProcessStmt()
@ 0x559906858808  clang::ento::ExprEngine::processCFGElement()
@ 0x55990684cb65  clang::ento::CoreEngine::HandlePostStmt()
@ 0x55990684bf5c  clang::ento::CoreEngine::ExecuteWorkList()
@ 0x5599065b635b  (anonymous
namespace)::AnalysisConsumer::HandleCode()
@ 0x5599065a0135  (anonymous
namespace)::AnalysisConsumer::HandleTranslationUnit()
@ 0x559906bb7cbc  clang::MultiplexConsumer::HandleTranslationUnit()
@ 0x559906d226d4  clang::ParseAST()
@ 0x559906b98a83  clang::FrontendAction::Execute()
@ 0x559906b31cd1  clang::CompilerInstance::ExecuteAction()
@ 0x559906a9cf61
clang::tooling::FrontendActionFactory::runInvocation()
@ 0x55990620cc07
clang::tidy::runClangTidy()::ActionFactory::runInvocation()
@ 0x559906a9ccca  clang::tooling::ToolInvocation::runInvocation()
@ 0x559906a9c646  clang::tooling::ToolInvocation::run()
@ 0x559906a9ef22  clang::tooling::ClangTool::run()
@ 0x559906207ecf  clang::tidy::runClangTidy()
@ 0x559902d47c45  main

On Tue, Mar 19, 2019 at 1:14 AM Alexander Kornienko 
wrote:

> On Fri, Mar 15, 2019 at 1:21 AM Artem Dergachev via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: dergachev
>> Date: Thu Mar 14 17:22:59 2019
>> New Revision: 356222
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=356222&view=rev
>> Log:
>> [analyzer] Support C++17 aggregates with bases without constructors.
>>
>> RegionStore now knows how to bind a nonloc::CompoundVal that represents
>> the
>> value of an aggregate initializer when it has its initial segment of
>> sub-values
>> correspond to base classes.
>>
>> Additionally, fixes the crash from pr40022.
>>
>> Differential Revision: https://reviews.llvm.org/D59054
>>
>> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>> cfe/trunk/test/Analysis/array-struct-region.cpp
>>
>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=356222&r1=356221&r2=356222&view=diff
>>
>> ==
>> --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Thu Mar 14 17:22:59
>> 2019
>> @@ -2334,12 +2334,57 @@ RegionBindingsRef RegionStoreManager::bi
>>if (V.isUnknown() || !V.getAs())
>>  return bindAggregate(B, R, UnknownVal());
>>
>> +  // The raw CompoundVal is essentially a symbolic InitListExpr: an
>> (immutable)
>> +  // list of other values. It appears pretty much only when there's an
>> actual
>> +  // initializer list expression in the program, and the analyzer tries
>> to
>> +  // unwrap it as soon as possible.
>> +  // This code is where such unwrap happens: when the compound value is
>> put into
>> +  // the object that it was supposed to initialize (it's an
>> *initializer* list,
>> +  // after all), instead of binding the whole value to the whole object,
>> we bind
>> +  // sub-values to sub-objects. Sub-values may themselves be compound
>> values,
>> +  // and in this case the procedure becomes recursive.
>> +  // FIXME: The annoying part about compound values is that they don't
>> carry
>> +  // any sort of information about which value corresponds to which
>> sub-object.
>> +  // It's simply a list of values in the middl

Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-19 Thread Alexander Kornienko via cfe-commits
Filed this as https://bugs.llvm.org/show_bug.cgi?id=41142. Any hope for a
prompt fix here?

On Tue, Mar 19, 2019 at 5:34 PM Alexander Kornienko 
wrote:

> A reduced test case:
> $ cat test-RegionStoreManager__bindStruct.cc
> struct a {};
> class b : a {};
> b c() { b d{c()}; }
> $ ./clang-tidy -checks="-*,clang-analyzer*"
> test-RegionStoreManager__bindStruct.cc -- -std=c++17
> assert.h assertion failed at
> tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in (anonymous
> namespace)::RegionBindingsRef (anonym
> ous namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef,
> const clang::ento::TypedValueRegion *, clang::ento::SVal):
> CRD->isAggregate() && "Non-aggregates are constructed with a constructor!"
> @ 0x559908170326  __assert_fail
> @ 0x5599068d4854  (anonymous
> namespace)::RegionStoreManager::bindStruct()
> @ 0x5599068c93c8  (anonymous namespace)::RegionStoreManager::Bind()
> @ 0x5599068b409f  clang::ento::ProgramState::bindLoc()
> @ 0x559906865935
> clang::ento::ExprEngine::processPointerEscapedOnBind()
> @ 0x55990685d4b3  clang::ento::ExprEngine::evalBind()
> @ 0x559906872a43  clang::ento::ExprEngine::VisitDeclStmt()
> @ 0x55990685c16f  clang::ento::ExprEngine::Visit()
> @ 0x559906858b1f  clang::ento::ExprEngine::ProcessStmt()
> @ 0x559906858808  clang::ento::ExprEngine::processCFGElement()
> @ 0x55990684cb65  clang::ento::CoreEngine::HandlePostStmt()
> @ 0x55990684bf5c  clang::ento::CoreEngine::ExecuteWorkList()
> @ 0x5599065b635b  (anonymous
> namespace)::AnalysisConsumer::HandleCode()
> @ 0x5599065a0135  (anonymous
> namespace)::AnalysisConsumer::HandleTranslationUnit()
> @ 0x559906bb7cbc  clang::MultiplexConsumer::HandleTranslationUnit()
> @ 0x559906d226d4  clang::ParseAST()
> @ 0x559906b98a83  clang::FrontendAction::Execute()
> @ 0x559906b31cd1  clang::CompilerInstance::ExecuteAction()
> @ 0x559906a9cf61
> clang::tooling::FrontendActionFactory::runInvocation()
> @ 0x55990620cc07
> clang::tidy::runClangTidy()::ActionFactory::runInvocation()
> @ 0x559906a9ccca  clang::tooling::ToolInvocation::runInvocation()
> @ 0x559906a9c646  clang::tooling::ToolInvocation::run()
> @ 0x559906a9ef22  clang::tooling::ClangTool::run()
> @ 0x559906207ecf  clang::tidy::runClangTidy()
> @ 0x559902d47c45  main
>
> On Tue, Mar 19, 2019 at 1:14 AM Alexander Kornienko 
> wrote:
>
>> On Fri, Mar 15, 2019 at 1:21 AM Artem Dergachev via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: dergachev
>>> Date: Thu Mar 14 17:22:59 2019
>>> New Revision: 356222
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=356222&view=rev
>>> Log:
>>> [analyzer] Support C++17 aggregates with bases without constructors.
>>>
>>> RegionStore now knows how to bind a nonloc::CompoundVal that represents
>>> the
>>> value of an aggregate initializer when it has its initial segment of
>>> sub-values
>>> correspond to base classes.
>>>
>>> Additionally, fixes the crash from pr40022.
>>>
>>> Differential Revision: https://reviews.llvm.org/D59054
>>>
>>> Modified:
>>> cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>>> cfe/trunk/test/Analysis/array-struct-region.cpp
>>>
>>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=356222&r1=356221&r2=356222&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
>>> +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Thu Mar 14
>>> 17:22:59 2019
>>> @@ -2334,12 +2334,57 @@ RegionBindingsRef RegionStoreManager::bi
>>>if (V.isUnknown() || !V.getAs())
>>>  return bindAggregate(B, R, UnknownVal());
>>>
>>> +  // The raw CompoundVal is essentially a symbolic InitListExpr: an
>>> (immutable)
>>> +  // list of other values. It appears pretty much only when there's an
>>> actual
>>> +  // initializer list expression in the program, and the analyzer tries
>>> to
>>> +  // unwrap it as soon as possible.
>>> +  // This code is where such unwrap happens: when the compound value is
>>> put into
>>> +  // the object that it was supposed to i

Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-19 Thread Alexander Kornienko via cfe-commits
On Tue, Mar 19, 2019 at 6:24 PM Artem Dergachev  wrote:

> Hi,
>
> I'll try to fix this ASAP!
>

Thanks!

> It sounds as if i don't have nearly enough C++17 codebases for testing,
> are there any obvious open-source projects that you could recommend?


No, but this particular example comes from C++11 code that just has subtly
different semantics in C++17. I guess, just adding -std=c++17 on existing
code (LLVM, for example ;) could help uncover some of the issues. I
believe, we can also continue providing reports in case CSA fails
assertions on our code.


> I'd
> love to try to reincarnate
>
> http://green.lab.llvm.org/green/view/Experimental/job/StaticAnalyzerBenchmarks/
> with those.
>
> On 3/19/19 9:37 AM, Alexander Kornienko wrote:
> > Filed this as https://bugs.llvm.org/show_bug.cgi?id=41142. Any hope
> > for a prompt fix here?
> >
> > On Tue, Mar 19, 2019 at 5:34 PM Alexander Kornienko  > <mailto:ale...@google.com>> wrote:
> >
> > A reduced test case:
> > $ cat test-RegionStoreManager__bindStruct.cc
> > struct a {};
> > class b : a {};
> > b c() { b d{c()}; }
> > $ ./clang-tidy -checks="-*,clang-analyzer*"
> > test-RegionStoreManager__bindStruct.cc -- -std=c++17
> > assert.h assertion failed at
> > tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in
> > (anonymous namespace)::RegionBindingsRef (anonym
> > ous
> > namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef,
> > const clang::ento::TypedValueRegion *, clang::ento::SVal):
> > CRD->isAggregate() && "Non-aggregates are constructed with a
> > constructor!"
> > @ 0x559908170326  __assert_fail
> > @ 0x5599068d4854  (anonymous
> > namespace)::RegionStoreManager::bindStruct()
> > @ 0x5599068c93c8  (anonymous
> > namespace)::RegionStoreManager::Bind()
> > @ 0x5599068b409f clang::ento::ProgramState::bindLoc()
> > @ 0x559906865935
> > clang::ento::ExprEngine::processPointerEscapedOnBind()
> > @ 0x55990685d4b3 clang::ento::ExprEngine::evalBind()
> > @ 0x559906872a43 clang::ento::ExprEngine::VisitDeclStmt()
> > @ 0x55990685c16f clang::ento::ExprEngine::Visit()
> > @ 0x559906858b1f clang::ento::ExprEngine::ProcessStmt()
> > @ 0x559906858808 clang::ento::ExprEngine::processCFGElement()
> > @ 0x55990684cb65 clang::ento::CoreEngine::HandlePostStmt()
> > @ 0x55990684bf5c clang::ento::CoreEngine::ExecuteWorkList()
> > @ 0x5599065b635b  (anonymous
> > namespace)::AnalysisConsumer::HandleCode()
> > @ 0x5599065a0135  (anonymous
> > namespace)::AnalysisConsumer::HandleTranslationUnit()
> > @ 0x559906bb7cbc
> > clang::MultiplexConsumer::HandleTranslationUnit()
> > @ 0x559906d226d4  clang::ParseAST()
> > @ 0x559906b98a83 clang::FrontendAction::Execute()
> > @ 0x559906b31cd1 clang::CompilerInstance::ExecuteAction()
> > @ 0x559906a9cf61
> > clang::tooling::FrontendActionFactory::runInvocation()
> > @ 0x55990620cc07
> > clang::tidy::runClangTidy()::ActionFactory::runInvocation()
> > @ 0x559906a9ccca
> > clang::tooling::ToolInvocation::runInvocation()
> > @ 0x559906a9c646 clang::tooling::ToolInvocation::run()
> > @ 0x559906a9ef22 clang::tooling::ClangTool::run()
> > @ 0x559906207ecf  clang::tidy::runClangTidy()
> > @ 0x559902d47c45  main
> >
> > On Tue, Mar 19, 2019 at 1:14 AM Alexander Kornienko
> > mailto:ale...@google.com>> wrote:
> >
> > On Fri, Mar 15, 2019 at 1:21 AM Artem Dergachev via
> > cfe-commits  > <mailto:cfe-commits@lists.llvm.org>> wrote:
> >
> > Author: dergachev
> > Date: Thu Mar 14 17:22:59 2019
> > New Revision: 356222
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=356222&view=rev
> > Log:
> > [analyzer] Support C++17 aggregates with bases without
> > constructors.
> >
> > RegionStore now knows how to bind a nonloc::CompoundVal
> > that represents the
> > value of an aggregate initializer when it has its initial
> > segment of sub-values
> >

Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-21 Thread Alexander Kornienko via cfe-commits
Thanks for the fix! Meanwhile, I found a couple of code samples that
trigger this assertion with a slightly different stack trace. Not sure if
they are substantially different though.

#1:
$ cat t.cc
inline namespace a {
class b typedef c;
}
class A {};
namespace a {
class b : A {};
}  // namespace a
class d {
 public:
  operator c();
};
d e() { c f{e()}; }
$ clang-tidy -checks="-*,clang-analyzer*" t.cc -- -std=c++17
assert.h assertion failed at
llvm/tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in (anonymous
namespace)::RegionBindingsRef (anonymous
namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef, const
clang::ento::TypedValueRegion *, clang::ento::SVal): CRD->isAggregate() &&
"Non-aggregates are constructed with a constructor!"
@ 0x5605d5ca35c6  __assert_fail
@ 0x5605d44064e4  (anonymous
namespace)::RegionStoreManager::bindStruct()
@ 0x5605d43fb058  (anonymous namespace)::RegionStoreManager::Bind()
@ 0x5605d43e5d2f  clang::ento::ProgramState::bindLoc()
@ 0x5605d43975c5
clang::ento::ExprEngine::processPointerEscapedOnBind()
@ 0x5605d438f143  clang::ento::ExprEngine::evalBind()
@ 0x5605d43a46d3  clang::ento::ExprEngine::VisitDeclStmt()
@ 0x5605d438ddff  clang::ento::ExprEngine::Visit()
@ 0x5605d438a7af  clang::ento::ExprEngine::ProcessStmt()
@ 0x5605d438a498  clang::ento::ExprEngine::processCFGElement()
@ 0x5605d437e7f5  clang::ento::CoreEngine::HandlePostStmt()
@ 0x5605d437dbec  clang::ento::CoreEngine::ExecuteWorkList()
@ 0x5605d40e7feb  (anonymous
namespace)::AnalysisConsumer::HandleCode()
@ 0x5605d40d1dc5  (anonymous
namespace)::AnalysisConsumer::HandleTranslationUnit()
@ 0x5605d46ea43c  clang::MultiplexConsumer::HandleTranslationUnit()
@ 0x5605d4854e54  clang::ParseAST()
@ 0x5605d46cb203  clang::FrontendAction::Execute()
@ 0x5605d4664451  clang::CompilerInstance::ExecuteAction()
@ 0x5605d45cef61
clang::tooling::FrontendActionFactory::runInvocation()
@ 0x5605d3d3e997
clang::tidy::runClangTidy()::ActionFactory::runInvocation()
@ 0x5605d45cecca  clang::tooling::ToolInvocation::runInvocation()
@ 0x5605d45ce646  clang::tooling::ToolInvocation::run()
@ 0x5605d45d0f22  clang::tooling::ClangTool::run()
@ 0x5605d3d39c5f  clang::tidy::runClangTidy()
@ 0x5605d0860c45  main

#2 is still being reduced.


On Wed, Mar 20, 2019 at 2:37 AM Artem Dergachev  wrote:

> On 3/19/19 11:10 AM, Richard Smith wrote:
> > It sounds like there might be a missing check for
> > InitListExpr::isTransparent somewhere. (A transparent InitListExpr
> > should be treated as equivalent to its one and only subexpression.)
> > Either that, or the static analyzer isn't aware that an object of
> > class type can be initialized directly from a function call, not via a
> > constructor.
>
> Indeed, thanks! And, as usual, more bugs on top of that.
> (https://reviews.llvm.org/D59573)
>
> On 3/19/19 11:00 AM, Alexander Kornienko wrote:
> > just adding -std=c++17 on existing code (LLVM, for example ;) could
> > help uncover some of the issues
>
> Hmm, fair enough :D I'm glad i asked :)
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356750 - [clang-tidy] Expand modular headers for PPCallbacks

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 06:42:48 2019
New Revision: 356750

URL: http://llvm.org/viewvc/llvm-project?rev=356750&view=rev
Log:
[clang-tidy] Expand modular headers for PPCallbacks

Summary:
Add a way to expand modular headers for PPCallbacks. Checks can opt-in for this
expansion by overriding the new registerPPCallbacks virtual method and
registering their PPCallbacks in the preprocessor created for this specific
purpose.

Use module expansion in the readability-identifier-naming check

Reviewers: gribozavr, usaxena95, sammccall

Reviewed By: gribozavr

Subscribers: nemanjai, mgorny, xazax.hun, kbarton, jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D59528

Added:
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/

clang-tools-extra/trunk/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/a.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/b.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/c.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/module.modulemap

clang-tools-extra/trunk/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=356750&r1=356749&r2=356750&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Mar 22 06:42:48 2019
@@ -8,6 +8,7 @@ add_clang_library(clangTidy
   ClangTidyDiagnosticConsumer.cpp
   ClangTidyOptions.cpp
   ClangTidyProfiling.cpp
+  ExpandModularHeadersPPCallbacks.cpp
 
   DEPENDS
   ClangSACheckers

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=356750&r1=356749&r2=356750&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Fri Mar 22 06:42:48 2019
@@ -18,6 +18,7 @@
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyModuleRegistry.h"
 #include "ClangTidyProfiling.h"
+#include "ExpandModularHeadersPPCallbacks.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
@@ -290,8 +291,10 @@ private:
 } // namespace
 
 ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
-ClangTidyContext &Context)
-: Context(Context), CheckFactories(new ClangTidyCheckFactories) {
+ClangTidyContext &Context,
+IntrusiveRefCntPtr OverlayFS)
+: Context(Context), OverlayFS(OverlayFS),
+  CheckFactories(new ClangTidyCheckFactories) {
   for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
  E = ClangTidyModuleRegistry::end();
I != E; ++I) {
@@ -351,7 +354,8 @@ ClangTidyASTConsumerFactory::CreateASTCo
 clang::CompilerInstance &Compiler, StringRef File) {
   // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
   // modify Compiler.
-  Context.setSourceManager(&Compiler.getSourceManager());
+  SourceManager *SM = &Compiler.getSourceManager();
+  Context.setSourceManager(SM);
   Context.setCurrentFile(File);
   Context.setASTContext(&Compiler.getASTContext());
 
@@ -377,9 +381,20 @@ ClangTidyASTConsumerFactory::CreateASTCo
   std::unique_ptr Finder(
   new ast_matchers::MatchFinder(std::move(FinderOptions)));
 
+  Preprocessor *PP = &Compiler.getPreprocessor();
+  Preprocessor *ModuleExpanderPP = PP;
+
+  if (Context.getLangOpts().Modules && OverlayFS != nullptr) {
+auto ModuleExpander = llvm::make_unique(
+&Compiler, OverlayFS);
+ModuleExpanderPP = ModuleExpander->getPreprocessor();
+PP->addPPCallbacks(std::move(ModuleExpander));
+  }
+
   for (auto &Check : Checks) {
 Check->registerMatchers(&*Finder);
 Check->registerPPCallbacks(Compiler);
+Check->registerPPCallbacks(*SM, PP, ModuleExpanderPP);
   }
 
   std::vector> Consumers;
@@ -505,7 +520,7 @@ std::vector
 runClangTidy(clang::tidy::ClangTidyContext &Context,
   

[clang-tools-extra] r356756 - [clang-tidy] Fix a compiler warning.

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 08:07:18 2019
New Revision: 356756

URL: http://llvm.org/viewvc/llvm-project?rev=356756&view=rev
Log:
[clang-tidy] Fix a compiler warning.

Rename the Preprocessor field to fix the

  declaration of ‘std::unique_ptr 
clang::tooling::ExpandModularHeadersPPCallbacks::Preprocessor’ changes the 
meaning of ‘Preprocessor’ from ‘class clang::Preprocessor’ [-fpermissive]

warning.

Modified:
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h

Modified: clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp?rev=356756&r1=356755&r2=356756&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.cpp Fri 
Mar 22 08:07:18 2019
@@ -78,12 +78,12 @@ ExpandModularHeadersPPCallbacks::ExpandM
   auto PO = std::make_shared();
   *PO = Compiler.getPreprocessorOpts();
 
-  Preprocessor = llvm::make_unique(
-  PO, Diags, LangOpts, Sources, *HeaderInfo, ModuleLoader,
-  /*IILookup=*/nullptr,
-  /*OwnsHeaderSearch=*/false);
-  Preprocessor->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
-  InitializePreprocessor(*Preprocessor, *PO, Compiler.getPCHContainerReader(),
+  PP = llvm::make_unique(PO, Diags, LangOpts, Sources,
+  *HeaderInfo, ModuleLoader,
+  /*IILookup=*/nullptr,
+  /*OwnsHeaderSearch=*/false);
+  PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
+  InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
  Compiler.getFrontendOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
@@ -92,7 +92,7 @@ ExpandModularHeadersPPCallbacks::ExpandM
 ExpandModularHeadersPPCallbacks::~ExpandModularHeadersPPCallbacks() = default;
 
 Preprocessor *ExpandModularHeadersPPCallbacks::getPreprocessor() const {
-  return Preprocessor.get();
+  return PP.get();
 }
 
 void ExpandModularHeadersPPCallbacks::handleModuleFile(
@@ -129,11 +129,11 @@ void ExpandModularHeadersPPCallbacks::pa
 
   if (!StartedLexing) {
 StartedLexing = true;
-Preprocessor->Lex(CurrentToken);
+PP->Lex(CurrentToken);
   }
   while (!CurrentToken.is(tok::eof) &&
  Sources.isBeforeInTranslationUnit(CurrentToken.getLocation(), Loc)) {
-Preprocessor->Lex(CurrentToken);
+PP->Lex(CurrentToken);
   }
 }
 
@@ -142,7 +142,7 @@ void ExpandModularHeadersPPCallbacks::Fi
 SrcMgr::CharacteristicKind FileType, FileID PrevFID = FileID()) {
   if (!EnteredMainFile) {
 EnteredMainFile = true;
-Preprocessor->EnterMainSourceFile();
+PP->EnterMainSourceFile();
   }
 }
 
@@ -162,7 +162,7 @@ void ExpandModularHeadersPPCallbacks::In
 
 void ExpandModularHeadersPPCallbacks::EndOfMainFile() {
   while (!CurrentToken.is(tok::eof))
-Preprocessor->Lex(CurrentToken);
+PP->Lex(CurrentToken);
 }
 
 // Handle all other callbacks.

Modified: clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h?rev=356756&r1=356755&r2=356756&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ExpandModularHeadersPPCallbacks.h Fri 
Mar 22 08:07:18 2019
@@ -125,7 +125,7 @@ private:
   TrivialModuleLoader ModuleLoader;
 
   std::unique_ptr HeaderInfo;
-  std::unique_ptr Preprocessor;
+  std::unique_ptr PP;
   bool EnteredMainFile = false;
   bool StartedLexing = false;
   Token CurrentToken;


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


[clang-tools-extra] r356788 - [clangd] Call the new ClangTidyCheck::registerPPCallbacks overload

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 11:16:51 2019
New Revision: 356788

URL: http://llvm.org/viewvc/llvm-project?rev=356788&view=rev
Log:
[clangd] Call the new ClangTidyCheck::registerPPCallbacks overload

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=356788&r1=356787&r2=356788&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Mar 22 11:16:51 2019
@@ -295,10 +295,12 @@ ParsedAST::build(std::unique_ptrsetASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(MainInput.getFile());
 CTFactories.createChecks(CTContext.getPointer(), CTChecks);
+Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   // FIXME: the PP callbacks skip the entire preamble.
   // Checks that want to see #includes in the main file do not see them.
   Check->registerPPCallbacks(*Clang);
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
   Check->registerMatchers(&CTFinder);
 }
   }


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


[clang-tools-extra] r356792 - [clang-tidy] anyOf(hasName(..), hasName(..)) -> hasAnyName

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 11:37:45 2019
New Revision: 356792

URL: http://llvm.org/viewvc/llvm-project?rev=356792&view=rev
Log:
[clang-tidy] anyOf(hasName(..), hasName(..)) -> hasAnyName

+ a minor style fix

Modified:
clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp
clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp?rev=356792&r1=356791&r2=356792&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp Fri Mar 22 
11:37:45 2019
@@ -19,10 +19,10 @@ namespace clang {
 namespace tidy {
 namespace cert {
 
-const char SetLongJmpCheck::DiagWording[] =
+namespace {
+const char DiagWording[] =
 "do not call %0; consider using exception handling instead";
 
-namespace {
 class SetJmpMacroCallbacks : public PPCallbacks {
   SetLongJmpCheck &Check;
 
@@ -36,7 +36,7 @@ public:
   return;
 
 if (II->getName() == "setjmp")
-  Check.diag(Range.getBegin(), Check.DiagWording) << II;
+  Check.diag(Range.getBegin(), DiagWording) << II;
   }
 };
 } // namespace
@@ -62,10 +62,10 @@ void SetLongJmpCheck::registerMatchers(M
   // In case there is an implementation that happens to define setjmp as a
   // function instead of a macro, this will also catch use of it. However, we
   // are primarily searching for uses of longjmp.
-  Finder->addMatcher(callExpr(callee(functionDecl(anyOf(hasName("setjmp"),
-hasName("longjmp")
- .bind("expr"),
- this);
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasAnyName("setjmp", "longjmp"
+  .bind("expr"),
+  this);
 }
 
 void SetLongJmpCheck::check(const MatchFinder::MatchResult &Result) {

Modified: clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h?rev=356792&r1=356791&r2=356792&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h Fri Mar 22 
11:37:45 2019
@@ -26,8 +26,6 @@ public:
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void registerPPCallbacks(CompilerInstance &Compiler) override;
-
-  static const char DiagWording[];
 };
 
 } // namespace cert


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


[clang-tools-extra] r356795 - Fix clang-move test.

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 11:52:10 2019
New Revision: 356795

URL: http://llvm.org/viewvc/llvm-project?rev=356795&view=rev
Log:
Fix clang-move test.

Modified:
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=356795&r1=356794&r2=356795&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Mar 22 
11:52:10 2019
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "ClangMove.h"
+#include "Move.h"
 #include "unittests/Tooling/RewriterTestContext.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"


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


[clang-tools-extra] r356796 - [clang-tidy] Move all checks to the new registerPPCallbacks API

2019-03-22 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 22 11:58:12 2019
New Revision: 356796

URL: http://llvm.org/viewvc/llvm-project?rev=356796&view=rev
Log:
[clang-tidy] Move all checks to the new registerPPCallbacks API

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/LambdaFunctionNameCheck.h
clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/MacroParenthesesCheck.h

clang-tools-extra/trunk/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.h
clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.cpp
clang-tools-extra/trunk/clang-tidy/cert/SetLongJmpCheck.h
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.h

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h

clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

clang-tools-extra/trunk/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.h
clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.h
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/MoveConstructorInitCheck.h

clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h

clang-tools-extra/trunk/clang-tidy/readability/RedundantPreprocessorCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantPreprocessorCheck.h
clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.h
clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp?rev=356796&r1=356795&r2=356796&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.cpp Fri 
Mar 22 11:58:12 2019
@@ -114,11 +114,10 @@ void StringFindStartswithCheck::check(co
 }
 
 void StringFindStartswithCheck::registerPPCallbacks(
-CompilerInstance &Compiler) {
-  IncludeInserter = llvm::make_unique(
-  Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
-  Compiler.getPreprocessor().addPPCallbacks(
-  IncludeInserter->CreatePPCallbacks());
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  IncludeInserter = llvm::make_unique(SM, 
getLangOpts(),
+  IncludeStyle);
+  PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
 }
 
 void StringFindStartswithCheck::storeOptions(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StringFindStartswithCheck.h?rev=356796&r1=356795&r2=35679

[clang-tools-extra] r356890 - [clang-tidy] Separate the check-facing interface

2019-03-25 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Mar 25 05:36:30 2019
New Revision: 356890

URL: http://llvm.org/viewvc/llvm-project?rev=356890&view=rev
Log:
[clang-tidy] Separate the check-facing interface

Summary:
Move ClangTidyCheck to a separate header/.cpp
Switch checks to #include "ClangTidyCheck.h"
Mention ClangTidyCheck.h in the docs

Reviewers: hokein, gribozavr, aaron.ballman

Reviewed By: hokein

Subscribers: mgorny, javed.absar, xazax.hun, arphaman, jdoerfert, llvm-commits, 
cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D59714

Added:
clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/docs/clang-tidy/Contributing.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=356890&r1=356889&r2=356890&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Mon Mar 25 05:36:30 2019
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_library(clangTidy
   ClangTidy.cpp
+  ClangTidyCheck.cpp
   ClangTidyModule.cpp
   ClangTidyDiagnosticConsumer.cpp
   ClangTidyOptions.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=356890&r1=356889&r2=356890&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Mon Mar 25 05:36:30 2019
@@ -449,51 +449,6 @@ ClangTidyOptions::OptionMap ClangTidyAST
   return Options;
 }
 
-DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message,
-   DiagnosticIDs::Level Level) {
-  return Context->diag(CheckName, Loc, Message, Level);
-}
-
-void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) 
{
-  // For historical reasons, checks don't implement the MatchFinder run()
-  // callback directly. We keep the run()/check() distinction to avoid 
interface
-  // churn, and to allow us to add cross-cutting logic in the future.
-  check(Result);
-}
-
-OptionsView::OptionsView(StringRef CheckName,
- const ClangTidyOptions::OptionMap &CheckOptions)
-: NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions) {}
-
-std::string OptionsView::get(StringRef LocalName, StringRef Default) const {
-  const auto &Iter = CheckOptions.find(NamePrefix + LocalName.str());
-  if (Iter != CheckOptions.end())
-return Iter->second;
-  return Default;
-}
-
-std::string OptionsView::getLocalOrGlobal(StringRef LocalName,
-  StringRef Default) const {
-  auto Iter = CheckOptions.find(NamePrefix + LocalName.str());
-  if (Iter != CheckOptions.end())
-return Iter->second;
-  // Fallback to global setting, if present.
-  Iter = CheckOptions.find(LocalName.str());
-  if (Iter != CheckOptions.end())
-return Iter->second;
-  return Default;
-}
-
-void OptionsView::store(ClangTidyOptions::OptionMap &Options,
-StringRef LocalName, StringRef Value) const {
-  Options[NamePrefix + LocalName.str()] = Value;
-}
-
-void OptionsView::store(ClangTidyOptions::OptionMap &Options,
-StringRef LocalName, int64_t Value) const {
-  store(Options, LocalName, llvm::itostr(Value));
-}
-
 std::vector
 getCheckNames(const ClangTidyOptions &Options,
   bool AllowEnablingAnalyzerAlphaCheckers) {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=356890&r1=356889&r2=356890&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Mon Mar 25 05:36:30 2019
@@ -9,16 +9,11 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
 
+#include "ClangTidyCheck.h"
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyOptions.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Tooling/Refactoring.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 
 namespace clang {
@@ -30,180 +25,6 @@ class CompilationDatabase;
 
 namespace tidy {
 
-/// \brief Provides access to the ``ClangTidyCheck`` options via check-lo

[clang-tools-extra] r356902 - [clang-tidy] ClangTidy.h -> ClangTidyCheck.h

2019-03-25 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Mar 25 07:46:51 2019
New Revision: 356902

URL: http://llvm.org/viewvc/llvm-project?rev=356902&view=rev
Log:
[clang-tidy] ClangTidy.h -> ClangTidyCheck.h

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=356902&r1=356901&r2=356902&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Mon Mar 25 07:46:51 2019
@@ -69,7 +69,7 @@ def write_header(module_path, module, ch
 #ifndef %(header_guard)s
 #define %(header_guard)s
 
-#include "../ClangTidy.h"
+#include "../ClangTidyCheck.h"
 
 namespace clang {
 namespace tidy {


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


[clang-tools-extra] r357312 - [clang-tidy] Fix PR28406

2019-03-29 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Mar 29 13:55:29 2019
New Revision: 357312

URL: http://llvm.org/viewvc/llvm-project?rev=357312&view=rev
Log:
[clang-tidy] Fix PR28406

Fix the crash resulting from a careless use of getLocWithOffset. At the
beginning of a macro expansion it produces an invalid SourceLocation that causes
an assertion failure later on.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=357312&r1=357311&r2=357312&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Fri 
Mar 29 13:55:29 2019
@@ -101,10 +101,15 @@ void RedundantVoidArgCheck::check(const
 void RedundantVoidArgCheck::processFunctionDecl(
 const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
   if (Function->isThisDeclarationADefinition()) {
-const Stmt *Body = Function->getBody();
 SourceLocation Start = Function->getBeginLoc();
-SourceLocation End =
-Body ? Body->getBeginLoc().getLocWithOffset(-1) : 
Function->getEndLoc();
+SourceLocation End = Function->getEndLoc();
+if (const Stmt *Body = Function->getBody()) {
+  End = Body->getBeginLoc();
+  if (End.isMacroID() &&
+  Result.SourceManager->isAtStartOfImmediateMacroExpansion(End))
+End = Result.SourceManager->getExpansionLoc(End);
+  End = End.getLocWithOffset(-1);
+}
 removeVoidArgumentTokens(Result, SourceRange(Start, End),
  "function definition");
   } else {
@@ -172,10 +177,8 @@ void RedundantVoidArgCheck::removeVoidAr
 
 void RedundantVoidArgCheck::removeVoidToken(Token VoidToken,
 StringRef Diagnostic) {
-  SourceLocation VoidLoc(VoidToken.getLocation());
-  auto VoidRange =
-  CharSourceRange::getTokenRange(VoidLoc, VoidLoc.getLocWithOffset(3));
-  diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidRange);
+  SourceLocation VoidLoc = VoidToken.getLocation();
+  diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidLoc);
 }
 
 void RedundantVoidArgCheck::processTypedefNameDecl(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=357312&r1=357311&r2=357312&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp 
Fri Mar 29 13:55:29 2019
@@ -489,6 +489,13 @@ void lambda_expression_with_macro_test()
   // CHECK-FIXES: []() BODY;
 }
 
+namespace qqq {
+void foo() BODY
+void bar(void) BODY;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant void argument list in 
function definition
+// CHECK-FIXES: void bar() BODY;
+}
+
 struct S_1 {
   void g_1(void) const {
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant void argument list 
in function definition [modernize-redundant-void-arg]


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


Re: [PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-04-02 Thread Alexander Kornienko via cfe-commits
On Tue, Apr 2, 2019 at 10:53 AM Mikael Holmén via Phabricator <
revi...@reviews.llvm.org> wrote:

> uabelho added a comment.
>
> Hi,
>
> I noticed that with this commit I get a whole bunch (~40) of warnings like
> the below when compiling with gcc 7.4:
>
>   [10/16] Building CXX object
> tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/clangTidyUtils.dir/HeaderGuard.cpp.o
>   In file included from
> ../tools/clang/tools/extra/clang-tidy/utils/HeaderGuard.h:12:0,
>from
> ../tools/clang/tools/extra/clang-tidy/utils/HeaderGuard.cpp:9:
>   ../tools/clang/tools/extra/clang-tidy/utils/../ClangTidy.h:161:16:
> warning: 'virtual void
> clang::tidy::ClangTidyCheck::registerPPCallbacks(const
> clang::SourceManager&, clang::Preprocessor*, clang::Preprocessor*)' was
> hidden [-Woverloaded-virtual]
>  virtual void registerPPCallbacks(const SourceManager &SM,
> Preprocessor *PP,
>   ^~~
>   In file included from
> ../tools/clang/tools/extra/clang-tidy/utils/HeaderGuard.cpp:9:0:
>   ../tools/clang/tools/extra/clang-tidy/utils/HeaderGuard.h:35:8:
> warning:   by 'virtual void
> clang::tidy::utils::HeaderGuardCheck::registerPPCallbacks(clang::CompilerInstance&)'
> [-Woverloaded-virtual]
>  void registerPPCallbacks(CompilerInstance &Compiler) override;
>   ^~~
>
> One of the registerPPCallbacks methods has the following comment
>
>   /// DEPRECATED: Use the other overload.
>   virtual void registerPPCallbacks(CompilerInstance &Compiler) {}
>
> so I suppose it will be removed at some point?
>

Indeed, the plan is to remove the old overload.


>
> I'm not super familiar with the warning, but there is at least one
> discussion about it here:
>
> https://stackoverflow.com/questions/9995421/gcc-woverloaded-virtual-warnings
>
>
> Repository:
>   rL LLVM
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D59528/new/
>
> https://reviews.llvm.org/D59528
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r357468 - [clang-tidy] make getLangOpts return a const ref

2019-04-02 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Apr  2 04:31:56 2019
New Revision: 357468

URL: http://llvm.org/viewvc/llvm-project?rev=357468&view=rev
Log:
[clang-tidy] make getLangOpts return a const ref

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h?rev=357468&r1=357467&r2=357468&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyCheck.h Tue Apr  2 04:31:56 2019
@@ -188,7 +188,7 @@ protected:
   /// \brief Returns the main file name of the current translation unit.
   StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }
   /// \brief Returns the language options from the context.
-  LangOptions getLangOpts() const { return Context->getLangOpts(); }
+  const LangOptions &getLangOpts() const { return Context->getLangOpts(); }
 };
 
 } // namespace tidy


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


  1   2   3   4   5   6   7   8   9   10   >