[clang] 226e179 - Revert "[NewPM] Provide method to run all pipeline callbacks, used for -O0"

2020-11-08 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2020-11-08T00:32:35-08:00
New Revision: 226e179f7400025d3d320a6f63ded7d747d25c4a

URL: 
https://github.com/llvm/llvm-project/commit/226e179f7400025d3d320a6f63ded7d747d25c4a
DIFF: 
https://github.com/llvm/llvm-project/commit/226e179f7400025d3d320a6f63ded7d747d25c4a.diff

LOG: Revert "[NewPM] Provide method to run all pipeline callbacks, used for -O0"

This reverts commit ae38540042668675dd16c642d850115f217ea59f.
As well as some follow-up test fixes.

The original change causes new-pass-manager.ll to fail when polly is enabled.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp
llvm/test/CodeGen/BPF/optnone-2.ll
llvm/test/Other/new-pass-manager.ll

Removed: 
clang/test/CodeGen/bpf-O0.c
llvm/test/Other/new-pm-O0-ep-callbacks.ll



diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 702982897c46..81ae79482d90 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1015,9 +1015,6 @@ static PassBuilder::OptimizationLevel mapToLevel(const 
CodeGenOptions &Opts) {
   default:
 llvm_unreachable("Invalid optimization level!");
 
-  case 0:
-return PassBuilder::OptimizationLevel::O0;
-
   case 1:
 return PassBuilder::OptimizationLevel::O1;
 
@@ -1247,10 +1244,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   ModulePassManager MPM(CodeGenOpts.DebugPassManager);
 
   if (!CodeGenOpts.DisableLLVMPasses) {
-// Map our optimization levels into one of the distinct levels used to
-// configure the pipeline.
-PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
-
 bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
 bool IsLTO = CodeGenOpts.PrepareForLTO;
 
@@ -1299,6 +1292,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 MPM.addPass(NameAnonGlobalPass());
   }
 } else {
+  // Map our optimization levels into one of the distinct levels used to
+  // configure the pipeline.
+  PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
+
   // If we reached here with a non-empty index file name, then the index
   // file was empty and we are not performing ThinLTO backend compilation
   // (used in testing in a distributed build environment). Drop any the 
type
@@ -1436,8 +1433,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 }
 
 if (CodeGenOpts.OptimizationLevel == 0) {
-  PB.runRegisteredEPCallbacks(MPM, Level, CodeGenOpts.DebugPassManager);
-
   // FIXME: the backends do not handle matrix intrinsics currently. Make
   // sure they are also lowered in O0. A lightweight version of the pass
   // should run in the backend pipeline on demand.

diff  --git a/clang/test/CodeGen/bpf-O0.c b/clang/test/CodeGen/bpf-O0.c
deleted file mode 100644
index a8957aa9b9b5..
--- a/clang/test/CodeGen/bpf-O0.c
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: %clang -O0 %s -target bpf -g -c -o /dev/null 
-fexperimental-new-pass-manager
-// REQUIRES: bpf-registered-target
-
-struct ss {
-  int a;
-};
-int foo() { return __builtin_btf_type_id(0, 0) + 
__builtin_preserve_type_info(*(struct ss *)0, 0); }

diff  --git a/llvm/include/llvm/Passes/PassBuilder.h 
b/llvm/include/llvm/Passes/PassBuilder.h
index 98af21b6276d..31c4782eaba3 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -594,20 +594,15 @@ class PassBuilder {
   /// Register a callback for a default optimizer pipeline extension point
   ///
   /// This extension point allows adding optimizations at the very end of the
-  /// function optimization pipeline.
+  /// function optimization pipeline. A key 
diff erence between this and the
+  /// legacy PassManager's OptimizerLast callback is that this extension point
+  /// is not triggered at O0. Extensions to the O0 pipeline should append their
+  /// passes to the end of the overall pipeline.
   void registerOptimizerLastEPCallback(
   const std::function &C) {
 OptimizerLastEPCallbacks.push_back(C);
   }
 
-  /// Run all registered extension point callbacks
-  ///
-  /// This runs the registered callbacks in the order they would be run in a
-  /// typical build*Pipeline(). This allows for reusing register*EPCallback()
-  /// between O0 and O[123] pipelines.
-  void runRegisteredEPCallbacks(ModulePassManager &MPM, OptimizationLevel 
Level,
-bool DebugLogging);
-
   /// Register a callback for parsing an AliasAnalysis Name to populate
   /// the given AAManager \p AA
   void registerParseAACallback(

diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f1672c9f89cc..68bbb01d1fda 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1658,49 +1658,6 @@ Pa

[PATCH] D90221: Include more attribute details when dumping AST in JSON

2020-11-08 Thread Lev Aronsky via Phabricator via cfe-commits
aronsky added a comment.

In D90221#2379793 , @aaron.ballman 
wrote:

> I think the issue is that ASTNodeTraverser is visiting all of the attribute 
> arguments (around ASTNodeTraverse.h:726) and your patch also visits them (as 
> part of what's emitted from ClangAttrEmitter.cpp).

Thanks! I will take a look at that code.

> Unfortunately, I don't think we can accept the patch as-is -- it's incomplete 
> (misses some kinds of attribute arguments), has correctness issues 
> (duplicates some kinds of attribute arguments), and would make it harder to 
> maintain the code moving forward (with the layering issue). I can definitely 
> understand not having a lot of time to investigate the right way to do this, 
> so I spent a bit of time this afternoon working on a patch that gets partway 
> to what I think needs to happen. I put up a pastebin for it here: 
> https://pastebin.com/6ybrPVu6. It does not solve the issue of duplicate 
> traversal, however, and I'm not certain I have more time to put into the 
> patch right now. Perhaps one of us will have the time to take this the last 
> mile -- I think the functionality is needed for JSON dumping.

Thank you! I appreciate your feedback and your work on the issue. I'll take a 
better look at your patch (from a quick look, it definitely looks more 
organized and correct than mine), and see if I can understand - and fix - the 
duplicate traversal issue.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90221/new/

https://reviews.llvm.org/D90221

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


[PATCH] D89158: [NewPM] Provide method to run all pipeline callbacks, used for -O0

2020-11-08 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks reopened this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

need to fix new-pass-manager.ll when polly is enabled


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89158/new/

https://reviews.llvm.org/D89158

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


[clang] 8930032 - Don't dereference a dyn_cast<> result - use cast<> instead. NFCI.

2020-11-08 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-11-08T13:06:07Z
New Revision: 8930032f53322405ca2d06cac78b9503542e5b62

URL: 
https://github.com/llvm/llvm-project/commit/8930032f53322405ca2d06cac78b9503542e5b62
DIFF: 
https://github.com/llvm/llvm-project/commit/8930032f53322405ca2d06cac78b9503542e5b62.diff

LOG: Don't dereference a dyn_cast<> result - use cast<> instead. NFCI.

We were relying on the dyn_cast<> succeeding - better use cast<> and have it 
assert that its the correct type than dereference a null result.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ccf5d24bb9eb..d8b819cf5bee 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -372,7 +372,7 @@ void CodeGenModule::checkAliases() {
   for (const GlobalDecl &GD : Aliases) {
 StringRef MangledName = getMangledName(GD);
 llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
-auto *Alias = dyn_cast(Entry);
+auto *Alias = cast(Entry);
 Alias->replaceAllUsesWith(llvm::UndefValue::get(Alias->getType()));
 Alias->eraseFromParent();
   }



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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, mgorny.
Herald added a project: clang.
njames93 requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Added some new ClangTidyOptionsProvider like classes designed for clangd work 
flow.
These providers are designed to source the options on the worker thread but in 
a thread safe manner.
This is done through making the options getter take a pointer to the filesystem 
used by the worker thread which natuarally is from a ThreadsafeFS.
Internal caching in the providers is also guarded.

The providers don't inherit from `ClangTidyOptionsProvider` instead they share 
a base class which is able to create a provider for the `ClangTidyContext` 
using a specific FileSystem.
This approach means one provider can be used for multiple contexts even though 
`ClangTidyContext` owns its provider.

Depends on D90531 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
  clang-tools-extra/clangd/unittests/TestTidyProvider.h

Index: clang-tools-extra/clangd/unittests/TestTidyProvider.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.h
@@ -0,0 +1,34 @@
+//===-- TestTidyProvider.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../TidyProvider.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+namespace clang {
+namespace clangd {
+
+class TestClangTidyProvider : public ClangdTidyProvider {
+public:
+  /// Convienence method for creating a provider that just uses \p Checks and \p
+  /// WarningsAsErrors
+  TestClangTidyProvider(llvm::StringRef Checks,
+llvm::StringRef WarningsAsErrors = {});
+  TestClangTidyProvider(const tidy::ClangTidyGlobalOptions &GlobalOptions,
+const tidy::ClangTidyOptions &Options);
+  std::vector getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+   llvm::StringRef FileName) override;
+  const tidy::ClangTidyGlobalOptions &
+  getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) override;
+
+private:
+  tidy::ClangTidyGlobalOptions GlobalOpts;
+  tidy::ClangTidyOptions Opts;
+};
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
@@ -0,0 +1,50 @@
+//===-- TestTidyProvider.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestTidyProvider.h"
+
+namespace clang {
+
+using namespace tidy;
+
+namespace clangd {
+
+TestClangTidyProvider::TestClangTidyProvider(llvm::StringRef Checks,
+ llvm::StringRef WarningsAsErrors) {
+  if (Checks.empty())
+Opts.Checks.emplace(getDefaultTidyChecks());
+  else
+Opts.Checks.emplace((Checks + "," + getUnusableTidyChecks()).str());
+  if (!WarningsAsErrors.empty())
+Opts.WarningsAsErrors.emplace(WarningsAsErrors);
+}
+
+TestClangTidyProvider::TestClangTidyProvider(
+const ClangTidyGlobalOptions &GlobalOptions,
+const ClangTidyOptions &Options)
+: GlobalOpts(GlobalOptions), Opts(Options) {
+  if (!Opts.Checks.hasValue() || Opts.Checks->empty())
+Opts.Checks = getDefaultTidyChecks().str();
+  else
+Opts.Checks->append(("," + getUnusableTidyChecks().str()));
+}
+
+std::vector
+TestClangTidyProvider::getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+  

[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303709.
nomanous added a comment.

In this update I delete some extra test code, move several comments and split 
the new type comparing code into a new function to make sure that the commonly 
used old type comparing function not affected by it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,7 +2343,21 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
-  bool hasSameType(const Type *T1, const Type *T2) const {
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  // lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  // the compiler automatically adds Objective C lifetime qualifiers for
+  // static data members. Sometimes, this will make two types not equal while
+  // they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+}
+
+bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
 


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match e

[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303712.
nomanous added a comment.

Some format fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,7 +2343,21 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
-  bool hasSameType(const Type *T1, const Type *T2) const {
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  /// lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  /// the compiler automatically adds Objective C lifetime qualifiers for
+  /// static data members. Sometimes, this will make two types not equal while
+  /// they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+}
+
+bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
 


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK==TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), diag::note_template_static_data_member_def_here)
+  <;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: c

[PATCH] D90992: [clang-tidy] Use vfs::FileSystem when getting config

2020-11-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:366
 }
-return OptionsSource(*ParsedOptions, ConfigFile.c_str());
+return OptionsSource(*ParsedOptions, ConfigFile.str());
   }

This breaks bootstrap builds against the gcc 5.3 libstdc++: 
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8864218000842553296/+/steps/package_clang/0/stdout?format=raw

```
 
/b/s/w/ir/cache/builder/src/third_party/llvm/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:366:12:
 error: no matching constructor for initialization of 
'clang::tidy::ClangTidyOptionsProvider::OptionsSource' (aka 
'pair>')
 return OptionsSource(*ParsedOptions, ConfigFile.str());
^ 
```

Can we undo the change on this line?

PTAL!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90992/new/

https://reviews.llvm.org/D90992

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303720.
njames93 added a comment.

Fix potential race when updating cache in `FileTidyProvider`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91029/new/

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
  clang-tools-extra/clangd/unittests/TestTidyProvider.h

Index: clang-tools-extra/clangd/unittests/TestTidyProvider.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.h
@@ -0,0 +1,34 @@
+//===-- TestTidyProvider.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../TidyProvider.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+namespace clang {
+namespace clangd {
+
+class TestClangTidyProvider : public ClangdTidyProvider {
+public:
+  /// Convienence method for creating a provider that just uses \p Checks and \p
+  /// WarningsAsErrors
+  TestClangTidyProvider(llvm::StringRef Checks,
+llvm::StringRef WarningsAsErrors = {});
+  TestClangTidyProvider(const tidy::ClangTidyGlobalOptions &GlobalOptions,
+const tidy::ClangTidyOptions &Options);
+  std::vector getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+   llvm::StringRef FileName) override;
+  const tidy::ClangTidyGlobalOptions &
+  getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) override;
+
+private:
+  tidy::ClangTidyGlobalOptions GlobalOpts;
+  tidy::ClangTidyOptions Opts;
+};
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
@@ -0,0 +1,50 @@
+//===-- TestTidyProvider.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestTidyProvider.h"
+
+namespace clang {
+
+using namespace tidy;
+
+namespace clangd {
+
+TestClangTidyProvider::TestClangTidyProvider(llvm::StringRef Checks,
+ llvm::StringRef WarningsAsErrors) {
+  if (Checks.empty())
+Opts.Checks.emplace(getDefaultTidyChecks());
+  else
+Opts.Checks.emplace((Checks + "," + getUnusableTidyChecks()).str());
+  if (!WarningsAsErrors.empty())
+Opts.WarningsAsErrors.emplace(WarningsAsErrors);
+}
+
+TestClangTidyProvider::TestClangTidyProvider(
+const ClangTidyGlobalOptions &GlobalOptions,
+const ClangTidyOptions &Options)
+: GlobalOpts(GlobalOptions), Opts(Options) {
+  if (!Opts.Checks.hasValue() || Opts.Checks->empty())
+Opts.Checks = getDefaultTidyChecks().str();
+  else
+Opts.Checks->append(("," + getUnusableTidyChecks().str()));
+}
+
+std::vector
+TestClangTidyProvider::getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+ llvm::StringRef FileName) {
+  std::vector RawOpts;
+  RawOpts.emplace_back(Opts, "mock-options");
+  return RawOpts;
+}
+
+const ClangTidyGlobalOptions &
+TestClangTidyProvider::getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) {
+  return GlobalOpts;
+}
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -58,8 +59,7 @@
   // Ex

[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303721.
njames93 added a comment.

Fix compile errors.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91029/new/

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
  clang-tools-extra/clangd/unittests/TestTidyProvider.h

Index: clang-tools-extra/clangd/unittests/TestTidyProvider.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.h
@@ -0,0 +1,34 @@
+//===-- TestTidyProvider.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../TidyProvider.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+namespace clang {
+namespace clangd {
+
+class TestClangTidyProvider : public ClangdTidyProvider {
+public:
+  /// Convienence method for creating a provider that just uses \p Checks and \p
+  /// WarningsAsErrors
+  TestClangTidyProvider(llvm::StringRef Checks,
+llvm::StringRef WarningsAsErrors = {});
+  TestClangTidyProvider(const tidy::ClangTidyGlobalOptions &GlobalOptions,
+const tidy::ClangTidyOptions &Options);
+  std::vector getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+   llvm::StringRef FileName) override;
+  const tidy::ClangTidyGlobalOptions &
+  getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) override;
+
+private:
+  tidy::ClangTidyGlobalOptions GlobalOpts;
+  tidy::ClangTidyOptions Opts;
+};
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
@@ -0,0 +1,50 @@
+//===-- TestTidyProvider.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestTidyProvider.h"
+
+namespace clang {
+
+using namespace tidy;
+
+namespace clangd {
+
+TestClangTidyProvider::TestClangTidyProvider(llvm::StringRef Checks,
+ llvm::StringRef WarningsAsErrors) {
+  if (Checks.empty())
+Opts.Checks.emplace(getDefaultTidyChecks());
+  else
+Opts.Checks.emplace((Checks + "," + getUnusableTidyChecks()).str());
+  if (!WarningsAsErrors.empty())
+Opts.WarningsAsErrors.emplace(WarningsAsErrors);
+}
+
+TestClangTidyProvider::TestClangTidyProvider(
+const ClangTidyGlobalOptions &GlobalOptions,
+const ClangTidyOptions &Options)
+: GlobalOpts(GlobalOptions), Opts(Options) {
+  if (!Opts.Checks.hasValue() || Opts.Checks->empty())
+Opts.Checks = getDefaultTidyChecks().str();
+  else
+Opts.Checks->append(("," + getUnusableTidyChecks().str()));
+}
+
+std::vector
+TestClangTidyProvider::getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+ llvm::StringRef FileName) {
+  std::vector RawOpts;
+  RawOpts.emplace_back(Opts, "mock-options");
+  return RawOpts;
+}
+
+const ClangTidyGlobalOptions &
+TestClangTidyProvider::getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) {
+  return GlobalOpts;
+}
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -58,8 +59,7 @@
   // Extra arguments for the compiler invocation.

[PATCH] D90534: [clang-format] Add new option PenaltyIndentedWhitespace

2020-11-08 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90534/new/

https://reviews.llvm.org/D90534

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


[PATCH] D91029: [clangd] Implement clang-tidy options from config

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303723.
njames93 added a comment.

Fix last compile error, check-clangd ran without a hitch. Testing the binary in 
another project seems to work ok.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91029/new/

https://reviews.llvm.org/D91029

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/TidyProvider.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
  clang-tools-extra/clangd/unittests/TestTidyProvider.h

Index: clang-tools-extra/clangd/unittests/TestTidyProvider.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.h
@@ -0,0 +1,34 @@
+//===-- TestTidyProvider.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../TidyProvider.h"
+#include "llvm/Support/VirtualFileSystem.h"
+
+namespace clang {
+namespace clangd {
+
+class TestClangTidyProvider : public ClangdTidyProvider {
+public:
+  /// Convienence method for creating a provider that just uses \p Checks and \p
+  /// WarningsAsErrors
+  TestClangTidyProvider(llvm::StringRef Checks,
+llvm::StringRef WarningsAsErrors = {});
+  TestClangTidyProvider(const tidy::ClangTidyGlobalOptions &GlobalOptions,
+const tidy::ClangTidyOptions &Options);
+  std::vector getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+   llvm::StringRef FileName) override;
+  const tidy::ClangTidyGlobalOptions &
+  getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) override;
+
+private:
+  tidy::ClangTidyGlobalOptions GlobalOpts;
+  tidy::ClangTidyOptions Opts;
+};
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestTidyProvider.cpp
@@ -0,0 +1,50 @@
+//===-- TestTidyProvider.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestTidyProvider.h"
+
+namespace clang {
+
+using namespace tidy;
+
+namespace clangd {
+
+TestClangTidyProvider::TestClangTidyProvider(llvm::StringRef Checks,
+ llvm::StringRef WarningsAsErrors) {
+  if (Checks.empty())
+Opts.Checks.emplace(getDefaultTidyChecks());
+  else
+Opts.Checks.emplace((Checks + "," + getUnusableTidyChecks()).str());
+  if (!WarningsAsErrors.empty())
+Opts.WarningsAsErrors.emplace(WarningsAsErrors);
+}
+
+TestClangTidyProvider::TestClangTidyProvider(
+const ClangTidyGlobalOptions &GlobalOptions,
+const ClangTidyOptions &Options)
+: GlobalOpts(GlobalOptions), Opts(Options) {
+  if (!Opts.Checks.hasValue() || Opts.Checks->empty())
+Opts.Checks = getDefaultTidyChecks().str();
+  else
+Opts.Checks->append(("," + getUnusableTidyChecks().str()));
+}
+
+std::vector
+TestClangTidyProvider::getRawOptions(llvm::vfs::FileSystem * /*unused*/,
+ llvm::StringRef FileName) {
+  std::vector RawOpts;
+  RawOpts.emplace_back(Opts, "mock-options");
+  return RawOpts;
+}
+
+const ClangTidyGlobalOptions &
+TestClangTidyProvider::getGlobalOptions(llvm::vfs::FileSystem * /*unused*/) {
+  return GlobalOpts;
+}
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
 
+#include "../TidyProvider.h"
 #include "Compiler.h"
 #include "ParsedA

[PATCH] D91033: GNU nano 4.8 /tmp/edit.7czvmlx7um4go4c0/commit-message Modified [clang-tidy][NFC] Tweak GlobList to iterate backwards

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
njames93 requested review of this revision.

By iterating backwards over the globs we can exit the loop as soon as we find a 
match.

While we're here:

- Regex doesn't need to be mutable.
- We can reserve the amount of Globs needed ahead of time.
- Using a SmallVector with size 0 is slightly more space efficient than a 
std::vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91033

Files:
  clang-tools-extra/clang-tidy/GlobList.cpp
  clang-tools-extra/clang-tidy/GlobList.h


Index: clang-tools-extra/clang-tidy/GlobList.h
===
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
-#include 
 
 namespace clang {
 namespace tidy {
@@ -39,9 +39,9 @@
 
   struct GlobListItem {
 bool IsPositive;
-mutable llvm::Regex Regex;
+llvm::Regex Regex;
   };
-  std::vector Items;
+  SmallVector Items;
 };
 
 } // end namespace tidy
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -43,6 +43,7 @@
 }
 
 GlobList::GlobList(StringRef Globs) {
+  Items.reserve(Globs.count(',') + 1);
   do {
 GlobListItem Item;
 Item.IsPositive = !ConsumeNegativeIndicator(Globs);
@@ -52,10 +53,9 @@
 }
 
 bool GlobList::contains(StringRef S) {
-  bool Contains = false;
-  for (const GlobListItem &Item : Items) {
+  for (const GlobListItem &Item : llvm::reverse(Items)) {
 if (Item.Regex.match(S))
-  Contains = Item.IsPositive;
+  return Item.IsPositive;
   }
-  return Contains;
+  return false;
 }


Index: clang-tools-extra/clang-tidy/GlobList.h
===
--- clang-tools-extra/clang-tidy/GlobList.h
+++ clang-tools-extra/clang-tidy/GlobList.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
-#include 
 
 namespace clang {
 namespace tidy {
@@ -39,9 +39,9 @@
 
   struct GlobListItem {
 bool IsPositive;
-mutable llvm::Regex Regex;
+llvm::Regex Regex;
   };
-  std::vector Items;
+  SmallVector Items;
 };
 
 } // end namespace tidy
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -43,6 +43,7 @@
 }
 
 GlobList::GlobList(StringRef Globs) {
+  Items.reserve(Globs.count(',') + 1);
   do {
 GlobListItem Item;
 Item.IsPositive = !ConsumeNegativeIndicator(Globs);
@@ -52,10 +53,9 @@
 }
 
 bool GlobList::contains(StringRef S) {
-  bool Contains = false;
-  for (const GlobListItem &Item : Items) {
+  for (const GlobListItem &Item : llvm::reverse(Items)) {
 if (Item.Regex.match(S))
-  Contains = Item.IsPositive;
+  return Item.IsPositive;
   }
-  return Contains;
+  return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 09fc779 - [NFC][tests] Replace use of GNUisms in usage of diff

2020-11-08 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2020-11-08T12:07:51-05:00
New Revision: 09fc7796e57417071523c82bdac8b3bf050648a0

URL: 
https://github.com/llvm/llvm-project/commit/09fc7796e57417071523c82bdac8b3bf050648a0
DIFF: 
https://github.com/llvm/llvm-project/commit/09fc7796e57417071523c82bdac8b3bf050648a0.diff

LOG: [NFC][tests] Replace use of GNUisms in usage of diff

... the POSIX options suffice.

This maintains compatibility with the system `diff` on platforms
like AIX.

Added: 


Modified: 
clang/test/APINotes/yaml-roundtrip-2.test
clang/test/APINotes/yaml-roundtrip.test

Removed: 




diff  --git a/clang/test/APINotes/yaml-roundtrip-2.test 
b/clang/test/APINotes/yaml-roundtrip-2.test
index 02455302fec1..b0b777b59506 100644
--- a/clang/test/APINotes/yaml-roundtrip-2.test
+++ b/clang/test/APINotes/yaml-roundtrip-2.test
@@ -1,8 +1,8 @@
 RUN: apinotes-test 
%S/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.apinotes > %t.result
-RUN: not 
diff  --strip-trailing-cr --ed %t.result 
%S/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.apinotes | FileCheck 
%s
+RUN: not 
diff  -b -e %t.result 
%S/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.apinotes | FileCheck 
%s
 
-The `--ed` parameter to `
diff ` is not implemented in the builtin 
diff , assume
-that we have a GNU compatible 
diff  when we have a shell.
+The `-e` option of `
diff ` is not implemented in the builtin 
diff , assume
+that we have a POSIX compatible 
diff  when we have a shell.
 REQUIRES: shell
 
 We expect only the document markers to be emitted

diff  --git a/clang/test/APINotes/yaml-roundtrip.test 
b/clang/test/APINotes/yaml-roundtrip.test
index bd4c89d2cdd9..bcf84afda8df 100644
--- a/clang/test/APINotes/yaml-roundtrip.test
+++ b/clang/test/APINotes/yaml-roundtrip.test
@@ -1,5 +1,5 @@
 RUN: apinotes-test 
%S/Inputs/Frameworks/Simple.framework/Headers/Simple.apinotes > %t.result
-RUN: not 
diff  --strip-trailing-cr 
%S/Inputs/Frameworks/Simple.framework/Headers/Simple.apinotes %t.result | 
FileCheck %s
+RUN: not 
diff  -b %S/Inputs/Frameworks/Simple.framework/Headers/Simple.apinotes 
%t.result | FileCheck %s
 
 Avoid Windows as the 
diff  output 
diff ers due to line-endings and 
diff erent 
diff 
 implementations.



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


[clang-tools-extra] 4dde325 - [clang-tidy] Fix build for gcc5.3 after d725f1ce

2020-11-08 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-11-08T17:25:18Z
New Revision: 4dde325004da32fa1a036accd544f57addab9f0c

URL: 
https://github.com/llvm/llvm-project/commit/4dde325004da32fa1a036accd544f57addab9f0c
DIFF: 
https://github.com/llvm/llvm-project/commit/4dde325004da32fa1a036accd544f57addab9f0c.diff

LOG: [clang-tidy] Fix build for gcc5.3 after d725f1ce

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 2ac4bbbf36b3..8c78f289502f 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -363,7 +363,7 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef 
Directory) {
  << ParsedOptions.getError().message() << "\n";
   continue;
 }
-return OptionsSource(*ParsedOptions, ConfigFile.str());
+return OptionsSource(*ParsedOptions, std::string(ConfigFile));
   }
   return llvm::None;
 }



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


[PATCH] D91035: [NFC, Refactor] Convert FunctionDefinitionKind from DeclSpech.h to a scoped enum

2020-11-08 Thread Faisal Vali via Phabricator via cfe-commits
faisalv created this revision.
faisalv added reviewers: aaron.ballman, bruno, BRevzin, wchilders.
faisalv added a project: clang.
faisalv requested review of this revision.

[NFC, Refactor] Convert FunctionDefinitionKind from DeclSpech.h to a scoped enum


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91035

Files:
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp

Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3579,7 +3579,7 @@
   // Only warn if this declarator is declaring a function at block scope, and
   // doesn't have a storage class (such as 'extern') specified.
   if (!D.isFunctionDeclarator() ||
-  D.getFunctionDefinitionKind() != FDK_Declaration ||
+  D.getFunctionDefinitionKind() != FDK::Declaration ||
   !S.CurContext->isFunctionOrMethod() ||
   D.getDeclSpec().getStorageClassSpec()
 != DeclSpec::SCS_unspecified)
@@ -5039,7 +5039,7 @@
   !(S.getLangOpts().CPlusPlus &&
 (T->isDependentType() || T->isRecordType( {
 if (T->isVoidType() && !S.getLangOpts().CPlusPlus &&
-D.getFunctionDefinitionKind() == FDK_Definition) {
+D.getFunctionDefinitionKind() == FDK::Definition) {
   // [6.9.1/3] qualified void return is invalid on a C
   // function definition.  Apparently ok on declarations and
   // in C++ though (!)
@@ -5410,7 +5410,8 @@
   //   The empty list in a function declarator that is not part of a definition
   //   of that function specifies that no information about the number or types
   //   of the parameters is supplied.
-  if (!LangOpts.CPlusPlus && D.getFunctionDefinitionKind() == FDK_Declaration) {
+  if (!LangOpts.CPlusPlus &&
+  D.getFunctionDefinitionKind() == FDK::Declaration) {
 bool IsBlock = false;
 for (const DeclaratorChunk &DeclType : D.type_objects()) {
   switch (DeclType.Kind) {
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5939,7 +5939,7 @@
   llvm::omp::TraitProperty::implementation_extension_disable_implicit_base);
   // If no base was found we create a declaration that we use as base.
   if (Bases.empty() && UseImplicitBase) {
-D.setFunctionDefinitionKind(FDK_Declaration);
+D.setFunctionDefinitionKind(FDK::Declaration);
 Decl *BaseD = HandleDeclarator(S, D, TemplateParamLists);
 BaseD->setImplicit(true);
 if (auto *BaseTemplD = dyn_cast(BaseD))
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5543,7 +5543,7 @@
 }
 
 Decl *Sema::ActOnDeclarator(Scope *S, Declarator &D) {
-  D.setFunctionDefinitionKind(FDK_Declaration);
+  D.setFunctionDefinitionKind(FDK::Declaration);
   Decl *Dcl = HandleDeclarator(S, D, MultiTemplateParamsArg());
 
   if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
@@ -9160,15 +9160,15 @@
 // If a function is defined as defaulted or deleted, mark it as such now.
 // We'll do the relevant checks on defaulted / deleted functions later.
 switch (D.getFunctionDefinitionKind()) {
-  case FDK_Declaration:
-  case FDK_Definition:
+  case FDK::Declaration:
+  case FDK::Definition:
 break;
 
-  case FDK_Defaulted:
+  case FDK::Defaulted:
 NewFD->setDefaulted();
 break;
 
-  case FDK_Deleted:
+  case FDK::Deleted:
 NewFD->setDeletedAsWritten();
 break;
 }
@@ -9871,17 +9871,17 @@
   // because Sema::ActOnStartOfFunctionDef has not been called yet.
   if (const auto *NBA = NewFD->getAttr())
 switch (D.getFunctionDefinitionKind()) {
-case FDK_Defaulted:
-case FDK_Deleted:
+case FDK::Defaulted:
+case FDK::Deleted:
   Diag(NBA->getLocation(),
diag::err_attribute_no_builtin_on_defaulted_deleted_function)
   << NBA->getSpelling();
   break;
-case FDK_Declaration:
+case FDK::Declaration:
   Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition)
   << NBA->getSpelling();
   break;
-case FDK_Definition:
+case FDK::Definition:
   break;
 }
 
@@ -13786,7 +13786,7 @@
 ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
 ParentScope, D, TemplateParameterLists, Bases);
 
-  D.setFunctionDefinitionKind(FDK_Definition);
+  D.setFunctionDefinitionKind(FDK::Definition);
   Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists);
   Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, S

[PATCH] D90392: [clang-tidy] Omit std::make_unique/make_shared for default initialization.

2020-11-08 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-make-shared.cpp:51
   // CHECK-FIXES: std::shared_ptr P1 = std::make_shared();
+  std::shared_ptr P2 = std::shared_ptr(new int);
 

ckennelly wrote:
> steveire wrote:
> > I'm a bit confused. Why don't we want to transform this?
> `std::make_shared()` is equivalent to `std::shared_ptr(new int())`. 
>  This value initializes (read: zeroes out the value).
> 
> The statement here is only default initializing (read: leaves the value 
> uninitialized).  For this use case, we should use 
> `std::make_shared_for_overwrite` when it is available.
I see. Did you consider an option to transform these anyway? It seems at least 
as likely that for real-world code bases they are not initialized accidentally 
(as opposed to being a deliberate choice as assumed here).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90392/new/

https://reviews.llvm.org/D90392

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


[PATCH] D90982: Ignore implicit nodes in IgnoreUnlessSpelledInSource mode

2020-11-08 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 303728.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90982/new/

https://reviews.llvm.org/D90982

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -132,6 +132,13 @@
 compareSnippets(Expected, rewrite(Input));
   }
 
+  template  void testRuleFailure(R Rule, StringRef Input) {
+Transformers.push_back(
+std::make_unique(std::move(Rule), consumer()));
+Transformers.back()->registerMatchers(&MatchFinder);
+ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
+  }
+
   // Transformers are referenced by MatchFinder.
   std::vector> Transformers;
   clang::ast_matchers::MatchFinder MatchFinder;
@@ -1067,6 +1074,179 @@
   EXPECT_EQ(ErrorCount, 0);
 }
 
+TEST_F(TransformerTest, ImplicitNodes_ConstructorDecl) {
+
+  std::string OtherStructPrefix = R"cpp(
+struct Other {
+)cpp";
+  std::string OtherStructSuffix = "};";
+
+  std::string CopyableStructName = "struct Copyable";
+  std::string BrokenStructName = "struct explicit Copyable";
+
+  std::string CodeSuffix = R"cpp(
+{
+Other m_i;
+Copyable();
+};
+)cpp";
+
+  std::string CopyCtor = "Other(const Other&) = default;";
+  std::string ExplicitCopyCtor = "explicit Other(const Other&) = default;";
+  std::string BrokenExplicitCopyCtor =
+  "explicit explicit explicit Other(const Other&) = default;";
+
+  std::string RewriteInput = OtherStructPrefix + CopyCtor + OtherStructSuffix +
+ CopyableStructName + CodeSuffix;
+  std::string ExpectedRewriteOutput = OtherStructPrefix + ExplicitCopyCtor +
+  OtherStructSuffix + CopyableStructName +
+  CodeSuffix;
+  std::string BrokenRewriteOutput = OtherStructPrefix + BrokenExplicitCopyCtor +
+OtherStructSuffix + BrokenStructName +
+CodeSuffix;
+
+  auto MatchedRecord =
+  cxxConstructorDecl(isCopyConstructor()).bind("copyConstructor");
+
+  auto RewriteRule =
+  changeTo(before(node("copyConstructor")), cat("explicit "));
+
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedRecord),
+RewriteRule),
+   RewriteInput, ExpectedRewriteOutput);
+
+  testRule(makeRule(traverse(TK_AsIs, MatchedRecord), RewriteRule),
+   RewriteInput, BrokenRewriteOutput);
+}
+
+TEST_F(TransformerTest, ImplicitNodes_RangeFor) {
+
+  std::string CodePrefix = R"cpp(
+struct Container
+{
+int* begin() const;
+int* end() const;
+int* cbegin() const;
+int* cend() const;
+};
+
+void foo()
+{
+  const Container c;
+)cpp";
+
+  std::string BeginCallBefore = "  c.begin();";
+  std::string BeginCallAfter = "  c.cbegin();";
+
+  std::string ForLoop = "for (auto i : c)";
+  std::string BrokenForLoop = "for (auto i :.cbegin() c)";
+
+  std::string CodeSuffix = R"cpp(
+  {
+  }
+}
+)cpp";
+
+  std::string RewriteInput =
+  CodePrefix + BeginCallBefore + ForLoop + CodeSuffix;
+  std::string ExpectedRewriteOutput =
+  CodePrefix + BeginCallAfter + ForLoop + CodeSuffix;
+  std::string BrokenRewriteOutput =
+  CodePrefix + BeginCallAfter + BrokenForLoop + CodeSuffix;
+
+  auto MatchedRecord =
+  cxxMemberCallExpr(on(expr(hasType(qualType(isConstQualified(),
+ hasDeclaration(cxxRecordDecl(
+ hasName("Container"))
+   .bind("callTarget")),
+callee(cxxMethodDecl(hasName("begin"
+  .bind("constBeginCall");
+
+  auto RewriteRule =
+  changeTo(node("constBeginCall"), cat(name("callTarget"), ".cbegin()"));
+
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedRecord),
+RewriteRule),
+   RewriteInput, ExpectedRewriteOutput);
+
+  testRule(makeRule(traverse(TK_AsIs, MatchedRecord), RewriteRule),
+   RewriteInput, BrokenRewriteOutput);
+}
+
+TEST_F(TransformerTest, ImplicitNodes_ForStmt) {
+
+  std::string CodePrefix = R"cpp(
+struct NonTrivial {
+NonTrivial() {}
+NonTrivial(NonTrivial&) {}
+NonTrivial& operator=(NonTrivial const&) { return *this; }
+
+~NonTrivial() {}
+};
+
+struct ContainsArray {
+NonTrivial arr[2];
+ContainsArray& operator=(ContainsArray const&) = default;
+};
+
+void testIt()
+{

[PATCH] D91037: [clang-tidy][bugprone-use-after-mnove] Warn on std::move for consts

2020-11-08 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
zinovy.nis requested review of this revision.

Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups.
Bug: https://bugs.llvm.org/show_bug.cgi?id=48008.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91037

Files:
  clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1073,6 +1073,29 @@
   }
 }
 
+// ExprWithCleanups doesn't crash
+
+int positive_expr_with_cleanups() {
+  class RetT {
+  public:
+RetT(const int _code) : code_(_code) {}
+bool Ok() const { return code_ == 0; }
+static RetT Test(bool &_isSet) { return 0; }
+
+  private:
+int code_;
+  };
+
+  bool isSet = false;
+  if (RetT::Test(isSet).Ok() && isSet) {
+if (RetT::Test(isSet).Ok() && isSet) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' 
[bugprone-redundant-branch-condition]
+  // CHECK-FIXES: {{^\ *$}}
+}
+  }
+  return 0;
+}
+
 //===--- Special Negatives 
===//
 
 // Aliasing
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -82,7 +82,13 @@
 
   // For standalone condition variables and for "or" binary operations we 
simply
   // remove the inner `if`.
-  const auto *BinOpCond = dyn_cast(InnerIf->getCond());
+  const auto *BinOpCond = dyn_cast_or_null(InnerIf->getCond());
+  if (!BinOpCond)
+if (auto *ExprWithCleanupsCond =
+dyn_cast_or_null(InnerIf->getCond()))
+  BinOpCond = dyn_cast_or_null(
+  *ExprWithCleanupsCond->children().begin());
+
   if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) ||
   (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
 SourceLocation IfBegin = InnerIf->getBeginLoc();
@@ -129,7 +135,13 @@
 // For "and" binary operations we remove the "and" operation with the
 // condition variable from the inner if.
   } else {
-const auto *CondOp = cast(InnerIf->getCond());
+const auto *CondOp = dyn_cast_or_null(InnerIf->getCond());
+if (!CondOp)
+  if (auto *ExprWithCleanupsCond =
+  dyn_cast_or_null(InnerIf->getCond()))
+CondOp = dyn_cast_or_null(
+*ExprWithCleanupsCond->children().begin());
+
 const auto *LeftDRE =
 dyn_cast(CondOp->getLHS()->IgnoreParenImpCasts());
 if (LeftDRE && LeftDRE->getDecl() == CondVar) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1073,6 +1073,29 @@
   }
 }
 
+// ExprWithCleanups doesn't crash
+
+int positive_expr_with_cleanups() {
+  class RetT {
+  public:
+RetT(const int _code) : code_(_code) {}
+bool Ok() const { return code_ == 0; }
+static RetT Test(bool &_isSet) { return 0; }
+
+  private:
+int code_;
+  };
+
+  bool isSet = false;
+  if (RetT::Test(isSet).Ok() && isSet) {
+if (RetT::Test(isSet).Ok() && isSet) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' [bugprone-redundant-branch-condition]
+  // CHECK-FIXES: {{^\ *$}}
+}
+  }
+  return 0;
+}
+
 //===--- Special Negatives ===//
 
 // Aliasing
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -82,7 +82,13 @@
 
   // For standalone condition variables and for "or" binary operations we simply
   // remove the inner `if`.
-  const auto *BinOpCond = dyn_cast(InnerIf->getCond());
+  const auto *BinOpCond = dyn_cast_or_null(InnerIf->getCond());
+  if (!BinOpCond)
+if (auto *ExprWithCleanupsCond =
+dyn_cast_or_null(InnerIf->getCond()))
+  BinOpCond = dyn_cast_or_null(
+  *ExprWithCleanupsCond->children().begin());
+
   if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) ||
   (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) 

[PATCH] D91009: Include std::basic_string_view in readability-redundant-string-init.

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

You don't really need to duplicate every single `std::string` test. Just enough 
so that it detects it, kind of like `::out::TestString`. Also can you update 
the docs and release notes to explain this behaviour.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91009/new/

https://reviews.llvm.org/D91009

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


[PATCH] D91037: [clang-tidy][bugprone-use-after-mnove] Warn on std::move for consts

2020-11-08 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Think this has an incorrect name, seems to have something to do with 
`bugprone-redundant-branch-condition`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91037/new/

https://reviews.llvm.org/D91037

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


[PATCH] D71880: [clangd] Implement Decl canonicalization rules for rename

2020-11-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 303733.
kbobyrev added a comment.

Store progress.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71880/new/

https://reviews.llvm.org/D71880

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -91,10 +91,86 @@
 }
 
 TEST(RenameTest, WithinFileRename) {
-  // rename is runnning on all "^" points, and "[[]]" ranges point to the
-  // identifier that is being renamed.
+  // For each "^" this test moves cursor to its location and applies renaming
+  // while checking that all identifiers enclosed in [[]] ranges are handled
+  // correctly.
   llvm::StringRef Tests[] = {
-  // Function.
+  // Templated static method instantiation.
+  R"cpp(
+template
+class Foo {
+public:
+  static T [[f^oo]]() {}
+};
+
+void bar() {
+  Foo::[[f^oo]]();
+}
+  )cpp",
+
+  // Templated method instantiation.
+  R"cpp(
+template
+class Foo {
+public:
+  T [[f^oo]]() {}
+};
+
+void bar() {
+  Foo().[[f^oo]]();
+}
+  )cpp",
+
+  // Class template (partial) specialization forward declarations.
+  R"cpp(
+template
+class [[Foo^]];
+
+template
+class [[Foo^]] {};
+
+template
+class [[Foo^]];
+  )cpp",
+
+  // Class template (full) specialization forward declaration.
+  R"cpp(
+template
+class [[Foo^]];
+
+template
+class [[Foo^]] {};
+  )cpp",
+
+  // Function template specialization forward declaration.
+  R"cpp(
+template
+U [[foo^]]();
+
+template
+U [[foo^]]() {};
+  )cpp",
+
+  // Function template specialization forward declaration.
+  R"cpp(
+template
+U [[foo^]]() {};
+
+template
+U [[foo^]]();
+  )cpp",
+
+  // Function template specialization forward declaration without function
+  // definition.
+  R"cpp(
+template
+U [[foo^]]();
+
+template
+U [[foo^]]();
+  )cpp",
+
+  // Simple recursive function.
   R"cpp(
 void [[foo^]]() {
   [[fo^o]]();
@@ -104,7 +180,7 @@
   // Type.
   R"cpp(
 struct [[foo^]] {};
-[[foo]] test() {
+[[foo^]] test() {
[[f^oo]] x;
return x;
 }
@@ -114,20 +190,21 @@
   R"cpp(
 void bar() {
   if (auto [[^foo]] = 5) {
-[[foo]] = 3;
+[[fo^o]] = 3;
   }
 }
   )cpp",
 
-  // Rename class, including constructor/destructor.
+  // Class, its constructor and destructor.
   R"cpp(
 class [[F^oo]] {
+public:
   [[F^oo]]();
-  ~[[Foo]]();
+  ~[[Fo^o]]();
   void foo(int x);
 };
-[[Foo]]::[[Fo^o]]() {}
-void [[Foo]]::foo(int x) {}
+[[Fo^o]]::[[Fo^o]]() {}
+void [[Fo^o]]::foo(int x) {}
   )cpp",
 
   // Rename template class, including constructor/destructor.
@@ -199,9 +276,9 @@
 class [[F^oo]] {};
 
 void test() {
-  [[Foo]] x;
-  [[Foo]] y;
-  [[Foo]] z;
+  [[F^oo]] x;
+  [[Fo^o]] y;
+  [[Foo^]] z;
 }
   )cpp",
 
@@ -360,8 +437,8 @@
 void boo(int);
 
 void qoo() {
-  [[foo]]();
-  boo([[foo]]());
+  [[f^oo]]();
+  boo([[fo^o]]());
   M1();
   boo(M1());
   M2([[foo]]());
@@ -454,7 +531,7 @@
 }
   )cpp",
 
-  // template class in template argument list.
+  // Template class in template argument list.
   R"cpp(
 template
 class [[Fo^o]] {};
@@ -510,6 +587,206 @@
   }
 }
 
+TEST(RenameTest, Alias) {
+  // For each "^" this test moves cursor to its location and applies renaming
+  // while checking that all identifiers enclosed in [[]] ranges are handled
+  // correctly.
+  llvm::StringRef Tests[] = {
+  R"cpp(
+class X {};
+typedef X [[Fo^o]];
+  )cpp",
+
+  R"cpp(
+class X {};
+using [[U^Old]] = X;
+  )cpp",
+
+  R"cpp(
+template 
+class X { T t; };
+
+template 
+using [[O^ld]] = X;
+  )cpp",
+
+  R"cpp(
+namespace x { class X {}; }
+namespace ns {
+using [[F^oo]] = x::X;
+}
+  )cpp",
+
+  R"cpp(
+namespace x { class Old {}; }
+namespace ns {
+#define REF(alias) alias alias_var;
+
+#define ALIAS(old) \
+  using old##Alias = x::old; \
+ 

[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2020-11-08 Thread Rafal Kupiec via Phabricator via cfe-commits
belliash added a comment.

When do you plan to enable this on x86?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80344/new/

https://reviews.llvm.org/D80344

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


[PATCH] D89158: [NewPM] Provide method to run all pipeline callbacks, used for -O0

2020-11-08 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 303737.
aeubanks added a comment.
Herald added a subscriber: dexonsmith.

check if pass manager is empty before adding


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89158/new/

https://reviews.llvm.org/D89158

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/bpf-O0.c
  llvm/include/llvm/IR/PassManager.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/CodeGen/BPF/optnone-2.ll
  llvm/test/Other/new-pm-O0-ep-callbacks.ll

Index: llvm/test/Other/new-pm-O0-ep-callbacks.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-O0-ep-callbacks.ll
@@ -0,0 +1,24 @@
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-late-loop-optimizations=no-op-loop -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-loop-optimizer-end=no-op-loop -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-scalar-optimizer-late=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-cgscc-optimizer-late=no-op-cgscc -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-vectorizer-start=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-pipeline-start=no-op-module -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-optimizer-last=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+
+; CHECK: Running pass: NoOp
+
+declare void @bar() local_unnamed_addr
+
+define void @foo(i32 %n) local_unnamed_addr {
+entry:
+  br label %loop
+loop:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+  %iv.next = add i32 %iv, 1
+  tail call void @bar()
+  %cmp = icmp eq i32 %iv, %n
+  br i1 %cmp, label %exit, label %loop
+exit:
+  ret void
+}
Index: llvm/test/CodeGen/BPF/optnone-2.ll
===
--- llvm/test/CodeGen/BPF/optnone-2.ll
+++ llvm/test/CodeGen/BPF/optnone-2.ll
@@ -1,5 +1,5 @@
 ; RUN: opt < %s -passes='default' | llc -march=bpfel -filetype=asm -o /dev/null -
-; TODO: add -O0 once that's supported
+; RUN: opt < %s -passes='default' | llc -march=bpfel -filetype=asm -o /dev/null -
 
 ; IR generated by
 ; $ cat /tmp/a.c
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1659,6 +1659,56 @@
   return MPM;
 }
 
+void PassBuilder::runRegisteredEPCallbacks(ModulePassManager &MPM,
+   OptimizationLevel Level,
+   bool DebugLogging) {
+  assert(Level == OptimizationLevel::O0 &&
+ "runRegisteredEPCallbacks should only be used with O0");
+  for (auto &C : PipelineStartEPCallbacks)
+C(MPM, Level);
+  if (!LateLoopOptimizationsEPCallbacks.empty()) {
+LoopPassManager LPM(DebugLogging);
+for (auto &C : LateLoopOptimizationsEPCallbacks)
+  C(LPM, Level);
+if (!LPM.isEmpty()) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+  createFunctionToLoopPassAdaptor(std::move(LPM;
+}
+  }
+  if (!LoopOptimizerEndEPCallbacks.empty()) {
+LoopPassManager LPM(DebugLogging);
+for (auto &C : LoopOptimizerEndEPCallbacks)
+  C(LPM, Level);
+if (!LPM.isEmpty()) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+  createFunctionToLoopPassAdaptor(std::move(LPM;
+}
+  }
+  if (!ScalarOptimizerLateEPCallbacks.empty()) {
+FunctionPassManager FPM(DebugLogging);
+for (auto &C : ScalarOptimizerLateEPCallbacks)
+  C(FPM, Level);
+if (!FPM.isEmpty())
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+  }
+  if (!CGSCCOptimizerLateEPCallbacks.empty()) {
+CGSCCPassManager CGPM(DebugLogging);
+for (auto &C : CGSCCOptimizerLateEPCallbacks)
+  C(CGPM, Level);
+if (!CGPM.isEmpty())
+  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
+  }
+  if (!VectorizerStartEPCallbacks.empty()) {
+FunctionPassManager FPM(DebugLogging);
+for (auto &C : VectorizerStartEPCallbacks)
+  C(FPM, Level);
+if (!FPM.isEmpty())
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+  }
+  for (auto &C : OptimizerLastEPCallbacks)
+C(MPM, Level);
+}
+
 AAManager PassBuilder::buildDefaultAAPipeline() {
   AAManager AA;
 
@@ -2241,6 +2291,8 @@
 MPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
   }
 
+  runRegisteredEPCallbacks(MPM, L, DebugLogging);
+
   // Do nothing else at all!
   return Error::success();
 }
Index: llvm/include/llvm/Passes/PassBuilder.h
=

[PATCH] D91037: [clang-tidy][bugprone-use-after-mnove] Warn on std::move for consts

2020-11-08 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp:87
+  if (!BinOpCond)
+if (auto *ExprWithCleanupsCond =
+dyn_cast_or_null(InnerIf->getCond()))

Please fix warning.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91037/new/

https://reviews.llvm.org/D91037

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


[PATCH] D89296: [clangd] Implement call hierarchy (incoming calls)

2020-11-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: kadircet.
nridge added a comment.

Kadir, would you like to take a look at this, as you're already familiar with 
the index changes? :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89296/new/

https://reviews.llvm.org/D89296

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


[PATCH] D89242: [PowerPC] [Clang] Port SSE4.1-compatible insert intrinsics

2020-11-08 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Ping...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89242/new/

https://reviews.llvm.org/D89242

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


[PATCH] D89242: [PowerPC] [Clang] Port SSE4.1-compatible insert intrinsics

2020-11-08 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision as: jsji.
jsji added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89242/new/

https://reviews.llvm.org/D89242

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


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2020-11-08 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous updated this revision to Diff 303749.
nomanous added a comment.

Some more format fixes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90448/new/

https://reviews.llvm.org/D90448

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_data_member_spec_type)
+  << Prev << R << Prev->getType();
+  Diag(Prev->getLocation(), 
diag::note_template_static_data_member_def_here)
+  << Prev;
+  return true;
+}
+
 // FIXME: Create an ExplicitInstantiation node?
 return (Decl*) nullptr;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5056,6 +5056,8 @@
   "of %select{explicit instantiation|explicit specialization|"
   "partial specialization|redeclaration}0 of %1 does not match"
   " expected type %3">;
+def err_invalid_template_static_data_member_spec_type : Error<"type %1 "
+  "of explicit instantiation of %q0 does not match expected type %2">;
 def err_mismatched_exception_spec_explicit_instantiation : Error<
   "exception specification in explicit instantiation does not match "
   "instantiated one">;
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2343,6 +2343,20 @@
   bool hasSameType(QualType T1, QualType T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }
+
+  /// Determine whether the given types \p T1 and \p T2 are equivalent with
+  /// lifetime qualifiers ignored. We want this because with option -fobjc-arc,
+  /// the compiler automatically adds Objective C lifetime qualifiers for
+  /// static data members. Sometimes, this will make two types not equal while
+  /// they should be.
+  bool hasSameTypeIgnoreLifetime(QualType T1, QualType T2) const {
+SplitQualType ST1 = getCanonicalType(T1).split();
+SplitQualType ST2 = getCanonicalType(T2).split();
+ST1.Quals.removeObjCLifetime();
+ST2.Quals.removeObjCLifetime();
+return ST1 == ST2;
+  }
+
   bool hasSameType(const Type *T1, const Type *T2) const {
 return getCanonicalType(T1) == getCanonicalType(T2);
   }


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10027,6 +10027,7 @@
 
 VarDecl *Prev = Previous.getAsSingle();
 VarTemplateDecl *PrevTemplate = Previous.getAsSingle();
+bool IsStaticDataMemberInstantiation = false;
 
 if (!PrevTemplate) {
   if (!Prev || !Prev->isStaticDataMember()) {
@@ -10048,6 +10049,8 @@
 // FIXME: Can we provide a note showing where this was declared?
 return true;
   }
+
+  IsStaticDataMemberInstantiation = true;
 } else {
   // Explicitly instantiate a variable template.
 
@@ -10140,6 +10143,21 @@
   return true;
 }
 
+// Check the static member's type given in the explicit instantiation
+// definition against the one in the class template. This won't happen in
+// explicit instantiation declaration because the instantiated code won't
+// be generated in that case.
+if (IsStaticDataMemberInstantiation &&
+TSK == TSK_ExplicitInstantiationDefinition && Prev &&
+!Context.hasSameTypeIgnoreLifetime(Prev->getType(), R)) {
+  Diag(T->getTypeLoc().getBeginLoc(),
+   diag::err_invalid_template_static_

[PATCH] D91037: [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups

2020-11-08 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added a comment.

In D91037#2381606 , @njames93 wrote:

> Think this has an incorrect name, seems to have something to do with 
> `bugprone-redundant-branch-condition`

Oops, thanks to autofill. Fixed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91037/new/

https://reviews.llvm.org/D91037

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


[PATCH] D91037: [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups

2020-11-08 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 303750.
zinovy.nis edited the summary of this revision.
zinovy.nis added a comment.

auto -> const auto.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91037/new/

https://reviews.llvm.org/D91037

Files:
  clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1073,6 +1073,29 @@
   }
 }
 
+// ExprWithCleanups doesn't crash
+
+int positive_expr_with_cleanups() {
+  class RetT {
+  public:
+RetT(const int _code) : code_(_code) {}
+bool Ok() const { return code_ == 0; }
+static RetT Test(bool &_isSet) { return 0; }
+
+  private:
+int code_;
+  };
+
+  bool isSet = false;
+  if (RetT::Test(isSet).Ok() && isSet) {
+if (RetT::Test(isSet).Ok() && isSet) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' 
[bugprone-redundant-branch-condition]
+  // CHECK-FIXES: {{^\ *$}}
+}
+  }
+  return 0;
+}
+
 //===--- Special Negatives 
===//
 
 // Aliasing
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -82,7 +82,13 @@
 
   // For standalone condition variables and for "or" binary operations we 
simply
   // remove the inner `if`.
-  const auto *BinOpCond = dyn_cast(InnerIf->getCond());
+  const auto *BinOpCond = dyn_cast_or_null(InnerIf->getCond());
+  if (!BinOpCond)
+if (const auto *ExprWithCleanupsCond =
+dyn_cast_or_null(InnerIf->getCond()))
+  BinOpCond = dyn_cast_or_null(
+  *ExprWithCleanupsCond->children().begin());
+
   if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) ||
   (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
 SourceLocation IfBegin = InnerIf->getBeginLoc();
@@ -129,7 +135,13 @@
 // For "and" binary operations we remove the "and" operation with the
 // condition variable from the inner if.
   } else {
-const auto *CondOp = cast(InnerIf->getCond());
+const auto *CondOp = dyn_cast_or_null(InnerIf->getCond());
+if (!CondOp)
+  if (const auto *ExprWithCleanupsCond =
+  dyn_cast_or_null(InnerIf->getCond()))
+CondOp = dyn_cast_or_null(
+*ExprWithCleanupsCond->children().begin());
+
 const auto *LeftDRE =
 dyn_cast(CondOp->getLHS()->IgnoreParenImpCasts());
 if (LeftDRE && LeftDRE->getDecl() == CondVar) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1073,6 +1073,29 @@
   }
 }
 
+// ExprWithCleanups doesn't crash
+
+int positive_expr_with_cleanups() {
+  class RetT {
+  public:
+RetT(const int _code) : code_(_code) {}
+bool Ok() const { return code_ == 0; }
+static RetT Test(bool &_isSet) { return 0; }
+
+  private:
+int code_;
+  };
+
+  bool isSet = false;
+  if (RetT::Test(isSet).Ok() && isSet) {
+if (RetT::Test(isSet).Ok() && isSet) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' [bugprone-redundant-branch-condition]
+  // CHECK-FIXES: {{^\ *$}}
+}
+  }
+  return 0;
+}
+
 //===--- Special Negatives ===//
 
 // Aliasing
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -82,7 +82,13 @@
 
   // For standalone condition variables and for "or" binary operations we simply
   // remove the inner `if`.
-  const auto *BinOpCond = dyn_cast(InnerIf->getCond());
+  const auto *BinOpCond = dyn_cast_or_null(InnerIf->getCond());
+  if (!BinOpCond)
+if (const auto *ExprWithCleanupsCond =
+dyn_cast_or_null(InnerIf->getCond()))
+  BinOpCond = dyn_cast_or_null(
+  *ExprWithCleanupsCond->children().begin());
+
   if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) ||
   (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
 SourceLocation IfBegin = InnerIf->getBeginLoc();
@@ -129,7 +135,13 @@
 // For "a

[PATCH] D91047: Add a call super attribute plugin example

2020-11-08 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 created this revision.
psionic12 added a reviewer: aaron.ballman.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
psionic12 requested review of this revision.

If a virtual method is marked as call_super, the
override method must call it, simpler feature like @CallSuper
in Android Java.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91047

Files:
  clang/docs/ClangPlugins.rst
  clang/examples/CMakeLists.txt
  clang/examples/CallSuperAttribute/CMakeLists.txt
  clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
  clang/test/CMakeLists.txt
  clang/test/Frontend/plugin-call-super.cpp

Index: clang/test/Frontend/plugin-call-super.cpp
===
--- /dev/null
+++ clang/test/Frontend/plugin-call-super.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang -fplugin=%llvmshlibdir/CallSuperAttr%pluginext -emit-llvm -S %s -o - 2>&1 | FileCheck %s --check-prefix=CALLSUPER
+// RUN: not %clang -fplugin=%llvmshlibdir/CallSuperAttr%pluginext -emit-llvm -DBAD_CALLSUPER -S %s -o - 2>&1 | FileCheck %s --check-prefix=BADCALLSUPER
+// REQUIRES: plugins, examples
+
+struct Base1 { [[call_super]] virtual void Test() {} };
+struct Base2 { [[call_super]] virtual void Test() {} };
+struct Derive : public Base1, public Base2 { void Test() override; };
+void Derive::Test() { Base1::Test(); Base2::Test(); }
+struct Derive2 : public Base1, public Base2 { void Test() override {  Base1::Test();  Base2::Test();}};
+// CALLSUPER: [[STR1_VAR:@.+]] = private unnamed_addr constant [10 x i8] c"example()\00"
+// CALLSUPER: [[STR2_VAR:@.+]] = private unnamed_addr constant [20 x i8] c"example(somestring)\00"
+// CALLSUPER: @llvm.global.annotations = {{.*}}@{{.*}}fn1a{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn1b{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn1c{{.*}}[[STR1_VAR]]{{.*}}@{{.*}}fn2{{.*}}[[STR2_VAR]]
+
+#ifdef BAD_CALLSUPER
+struct Base1 { [[call_super]] virtual void Test() {} };
+struct Base2 { [[call_super]] virtual void Test() {} };
+struct Derive : public Base1, public Base2 { void Test() override; };
+void Derive::Test() { Base1::Test(); /*Base2::Test();*/ }
+struct Derive2 : public Base1, public Base2 { void Test() override {  Base1::Test();  Base2::Test();}};
+// BADCALLSUPER: warning: Base2::Test is marked as call_super but override method Derive::Test does not call it
+// BADCALLSUPER: note: overridden method which is marked as call_super here
+#endif
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -91,6 +91,7 @@
   list(APPEND CLANG_TEST_DEPS
 Attribute
 AnnotateFunctions
+CallSuperAttr
 clang-interpreter
 PrintFunctionNames
 )
Index: clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
===
--- /dev/null
+++ clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
@@ -0,0 +1,153 @@
+//===- AnnotateFunctions.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// clang plugin, checks every overridden virtual function whether called
+// this function or not.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/Sema/ParsedAttr.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaDiagnostic.h"
+#include "llvm/ADT/SmallPtrSet.h"
+using namespace clang;
+
+namespace {
+
+llvm::SmallPtrSet ForcingCalledMethods;
+bool isMarkedAsCallSuper(const CXXMethodDecl *D) {
+  return ForcingCalledMethods.contains(D);
+}
+
+std::string FullName(const CXXMethodDecl *D) {
+  std::string FullName;
+  FullName += D->getParent()->getName();
+  FullName += "::";
+  FullName += D->getName();
+  return FullName;
+}
+
+class MethodUsageVisitor : public RecursiveASTVisitor {
+public:
+  bool IsOvrriddenUsed = false;
+  MethodUsageVisitor(const clang::CXXMethodDecl *MethodDecl)
+  : MethodDecl(MethodDecl) {}
+  bool VisitCallExpr(clang::CallExpr *CallExpr) {
+if (CallExpr->getCalleeDecl() == MethodDecl) {
+  IsOvrriddenUsed = true;
+  return false;
+}
+return true;
+  }
+
+private:
+  const clang::CXXMethodDecl *MethodDecl;
+};
+
+class CallSuperVisitor : public RecursiveASTVisitor {
+public:
+  CallSuperVisitor(DiagnosticsEngine &Diags) : Diags(Diags) {
+WarningSuperNotCalled = Diags.getCustomDiagID(
+DiagnosticsEngine::Warning,
+"%0 is marked as call_super but override method %1 does not call it");
+NotePrevio

[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-11-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 303754.
kbobyrev added a comment.

Rebase on top of master.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90116/new/

https://reviews.llvm.org/D90116

Files:
  llvm/CMakeLists.txt


Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -599,6 +599,9 @@
   if (BUILD_SHARED_LIBS)
 message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on 
Windows.")
   endif()
+  # Force MSVC to read code as UTF-8.
+  add_compile_options("$<$:/utf-8>")
+  add_compile_options("$<$:/utf-8>")
 else()
   option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" 
OFF)
   option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin 
only)" OFF)


Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -599,6 +599,9 @@
   if (BUILD_SHARED_LIBS)
 message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
   endif()
+  # Force MSVC to read code as UTF-8.
+  add_compile_options("$<$:/utf-8>")
+  add_compile_options("$<$:/utf-8>")
 else()
   option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
   option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-11-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 303753.
kbobyrev added a comment.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.

Force MSVC to read code as UTF-8 via CMake options.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90116/new/

https://reviews.llvm.org/D90116

Files:
  llvm/CMakeLists.txt


Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -595,6 +595,9 @@
   if (BUILD_SHARED_LIBS)
 message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on 
Windows.")
   endif()
+  # Force MSVC to read code as UTF-8.
+  add_compile_options("$<$:/utf-8>")
+  add_compile_options("$<$:/utf-8>")
 else()
   option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" 
OFF)
   option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin 
only)" OFF)


Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -595,6 +595,9 @@
   if (BUILD_SHARED_LIBS)
 message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
   endif()
+  # Force MSVC to read code as UTF-8.
+  add_compile_options("$<$:/utf-8>")
+  add_compile_options("$<$:/utf-8>")
 else()
   option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
   option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90116: [llvm] CMake: Force MSVC to read code as UTF-8

2020-11-08 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added inline comments.



Comment at: llvm/CMakeLists.txt:604
+  add_compile_options("$<$:/utf-8>")
+  add_compile_options("$<$:/utf-8>")
 else()

I think we could replace these two lines with the one line
```
add_compile_options(/utf-8)
```
Because we could not get here with non-MSVC compiler


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90116/new/

https://reviews.llvm.org/D90116

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


[PATCH] D90975: [clangd] Don't run clang-tidy AST traversal if there are no checks.

2020-11-08 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG053110b22aa9: [clangd] Don't run clang-tidy AST 
traversal if there are no checks. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90975/new/

https://reviews.llvm.org/D90975

Files:
  clang-tools-extra/clangd/ParsedAST.cpp


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTChecks = CTFactories.createChecks(CTContext.getPointer());
-ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
-   const clang::Diagnostic &Info) {
-  if (CTContext) {
+llvm::erase_if(CTChecks, [&](const auto &Check) {
+  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+});
+Preprocessor *PP = &Clang->getPreprocessor();
+for (const auto &Check : CTChecks) {
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+  Check->registerMatchers(&CTFinder);
+}
+
+if (!CTChecks.empty()) {
+  ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level 
DiagLevel,
+ const clang::Diagnostic &Info) {
 std::string CheckName = CTContext->getCheckName(Info.getID());
 bool IsClangTidyDiag = !CheckName.empty();
 if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@
 return DiagnosticsEngine::Error;
   }
 }
-  }
-  return DiagLevel;
-});
-Preprocessor *PP = &Clang->getPreprocessor();
-for (const auto &Check : CTChecks) {
-  if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
-continue;
-  // 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->getSourceManager(), PP, PP);
-  Check->registerMatchers(&CTFinder);
+return DiagLevel;
+  });
 }
   }
 
@@ -415,7 +415,7 @@
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (!CTChecks.empty()) {
 // Run the AST-dependent part of the clang-tidy checks.
 // (The preprocessor part ran already, via PPCallbacks).
 trace::Span Tracer("ClangTidyMatch");


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTChecks = CTFactories.createChecks(CTContext.getPointer());
-ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
-   const clang::Diagnostic &Info) {
-  if (CTContext) {
+llvm::erase_if(CTChecks, [&](const auto &Check) {
+  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+});
+Preprocessor *PP = &Clang->getPreprocessor();
+for (const auto &Check : CTChecks) {
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+  Check->registerMatchers(&CTFinder);
+}
+
+if (!CTChecks.empty()) {
+  ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic &Info) {
 std::string CheckName = CTContext->getCheckName(Info.getID());
 bool IsClangTidyDiag = !CheckName.empty();
 if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@
 return DiagnosticsEngine::Error;
   }
 }
-  }
-  return DiagLevel;
-});
-Preprocessor *PP = &Clang->getPreprocessor();
-for (const auto &Check : CTChecks) {
-  if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
-continue;
-  // 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->getSourceManager(), PP, PP);
-  Check->registerMatchers(&CTFinder);
+return DiagLevel;
+  });
 }
   }
 
@@ -415,7 +415,7 @@
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (!CTChecks.empty()) {
 // Run the AST-dependent part of the clang-tidy checks.
 // (The preprocessor part ran already, via PPCallbacks).
 trace::Span Tracer("ClangTidyMatch")

[clang-tools-extra] 053110b - [clangd] Don't run clang-tidy AST traversal if there are no checks.

2020-11-08 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-11-09T08:44:06+01:00
New Revision: 053110b22aa93b1f7bccdb0dae9dea7f755b045c

URL: 
https://github.com/llvm/llvm-project/commit/053110b22aa93b1f7bccdb0dae9dea7f755b045c
DIFF: 
https://github.com/llvm/llvm-project/commit/053110b22aa93b1f7bccdb0dae9dea7f755b045c.diff

LOG: [clangd] Don't run clang-tidy AST traversal if there are no checks.

While here, clean up ParsedAST::build a bit:
 - remove FIXMEs that were fixed long ago by ReplayPreamble
 - remove redundant if, ClangTidyContext is not actually optional

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

Added: 


Modified: 
clang-tools-extra/clangd/ParsedAST.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 6ca9c4f93d16..d3c14e6f3c87 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -303,9 +303,18 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTChecks = CTFactories.createChecks(CTContext.getPointer());
-ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
-   const clang::Diagnostic &Info) {
-  if (CTContext) {
+llvm::erase_if(CTChecks, [&](const auto &Check) {
+  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
+});
+Preprocessor *PP = &Clang->getPreprocessor();
+for (const auto &Check : CTChecks) {
+  Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
+  Check->registerMatchers(&CTFinder);
+}
+
+if (!CTChecks.empty()) {
+  ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level 
DiagLevel,
+ const clang::Diagnostic &Info) {
 std::string CheckName = CTContext->getCheckName(Info.getID());
 bool IsClangTidyDiag = !CheckName.empty();
 if (IsClangTidyDiag) {
@@ -330,17 +339,8 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 return DiagnosticsEngine::Error;
   }
 }
-  }
-  return DiagLevel;
-});
-Preprocessor *PP = &Clang->getPreprocessor();
-for (const auto &Check : CTChecks) {
-  if (!Check->isLanguageVersionSupported(CTContext->getLangOpts()))
-continue;
-  // 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->getSourceManager(), PP, PP);
-  Check->registerMatchers(&CTFinder);
+return DiagLevel;
+  });
 }
   }
 
@@ -415,7 +415,7 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
-  {
+  if (!CTChecks.empty()) {
 // Run the AST-dependent part of the clang-tidy checks.
 // (The preprocessor part ran already, via PPCallbacks).
 trace::Span Tracer("ClangTidyMatch");



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