[Lldb-commits] [PATCH] D112379: [lldb][NFC] Modernize for-loops in ModuleList

2021-10-24 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added a reviewer: LLDB.
teemperor added a project: LLDB.
Herald added a subscriber: JDevlieghere.
teemperor requested review of this revision.

https://reviews.llvm.org/D112379

Files:
  lldb/include/lldb/Core/ModuleList.h
  lldb/source/Core/ModuleList.cpp

Index: lldb/source/Core/ModuleList.cpp
===
--- lldb/source/Core/ModuleList.cpp
+++ lldb/source/Core/ModuleList.cpp
@@ -200,16 +200,15 @@
   }
 }
 
-bool ModuleList::AppendIfNeeded(const ModuleSP &module_sp, bool notify) {
-  if (module_sp) {
+bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
+  if (new_module) {
 std::lock_guard guard(m_modules_mutex);
-collection::iterator pos, end = m_modules.end();
-for (pos = m_modules.begin(); pos != end; ++pos) {
-  if (pos->get() == module_sp.get())
+for (const ModuleSP &module_sp : m_modules) {
+  if (module_sp.get() == new_module.get())
 return false; // Already in the list
 }
 // Only push module_sp on the list if it wasn't already in there.
-Append(module_sp, notify);
+Append(new_module, notify);
 return true;
   }
   return false;
@@ -372,10 +371,10 @@
 Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
 
 std::lock_guard guard(m_modules_mutex);
-collection::const_iterator pos, end = m_modules.end();
-for (pos = m_modules.begin(); pos != end; ++pos) {
-  (*pos)->FindFunctions(lookup_info.GetLookupName(), CompilerDeclContext(),
-lookup_info.GetNameTypeMask(), options, sc_list);
+for (const ModuleSP &module_sp : m_modules) {
+  module_sp->FindFunctions(lookup_info.GetLookupName(),
+   CompilerDeclContext(),
+   lookup_info.GetNameTypeMask(), options, sc_list);
 }
 
 const size_t new_size = sc_list.GetSize();
@@ -384,10 +383,9 @@
   lookup_info.Prune(sc_list, old_size);
   } else {
 std::lock_guard guard(m_modules_mutex);
-collection::const_iterator pos, end = m_modules.end();
-for (pos = m_modules.begin(); pos != end; ++pos) {
-  (*pos)->FindFunctions(name, CompilerDeclContext(), name_type_mask,
-options, sc_list);
+for (const ModuleSP &module_sp : m_modules) {
+  module_sp->FindFunctions(name, CompilerDeclContext(), name_type_mask,
+   options, sc_list);
 }
   }
 }
@@ -401,10 +399,9 @@
 Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
 
 std::lock_guard guard(m_modules_mutex);
-collection::const_iterator pos, end = m_modules.end();
-for (pos = m_modules.begin(); pos != end; ++pos) {
-  (*pos)->FindFunctionSymbols(lookup_info.GetLookupName(),
-  lookup_info.GetNameTypeMask(), sc_list);
+for (const ModuleSP &module_sp : m_modules) {
+  module_sp->FindFunctionSymbols(lookup_info.GetLookupName(),
+ lookup_info.GetNameTypeMask(), sc_list);
 }
 
 const size_t new_size = sc_list.GetSize();
@@ -413,9 +410,8 @@
   lookup_info.Prune(sc_list, old_size);
   } else {
 std::lock_guard guard(m_modules_mutex);
-collection::const_iterator pos, end = m_modules.end();
-for (pos = m_modules.begin(); pos != end; ++pos) {
-  (*pos)->FindFunctionSymbols(name, name_type_mask, sc_list);
+for (const ModuleSP &module_sp : m_modules) {
+  module_sp->FindFunctionSymbols(name, name_type_mask, sc_list);
 }
   }
 }
@@ -424,28 +420,23 @@
const ModuleFunctionSearchOptions &options,
SymbolContextList &sc_list) {
   std::lock_guard guard(m_modules_mutex);
-  collection::const_iterator pos, end = m_modules.end();
-  for (pos = m_modules.begin(); pos != end; ++pos) {
-(*pos)->FindFunctions(name, options, sc_list);
-  }
+  for (const ModuleSP &module_sp : m_modules)
+module_sp->FindFunctions(name, options, sc_list);
 }
 
 void ModuleList::FindCompileUnits(const FileSpec &path,
   SymbolContextList &sc_list) const {
   std::lock_guard guard(m_modules_mutex);
-  collection::const_iterator pos, end = m_modules.end();
-  for (pos = m_modules.begin(); pos != end; ++pos) {
-(*pos)->FindCompileUnits(path, sc_list);
-  }
+  for (const ModuleSP &module_sp : m_modules)
+module_sp->FindCompileUnits(path, sc_list);
 }
 
 void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
  VariableList &variable_list) const {
   std::lock_guard guard(m_modules_mutex);
-  collection::const_iterator pos, end = m_modules.end();
-  for (pos = m_modules.begin(); pos != end; ++pos) {
-(*pos)->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
-variable_list);
+  for (const ModuleSP &module_sp : m_m

[Lldb-commits] [PATCH] D112379: [lldb][NFC] Modernize for-loops in ModuleList

2021-10-24 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

Straightforward but looking for a second set of eyes




Comment at: lldb/source/Core/ModuleList.cpp:204
+bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
+  if (new_module) {
 std::lock_guard guard(m_modules_mutex);

I'll make this early-exit as a follow-up (along with some other functions that 
could do the same).


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

https://reviews.llvm.org/D112379

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


[Lldb-commits] [PATCH] D112379: [lldb][NFC] Modernize for-loops in ModuleList

2021-10-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision as: mib.
mib added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D112379

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


[Lldb-commits] [lldb] 7cc8fa2 - Use llvm::is_contained (NFC)

2021-10-24 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2021-10-24T09:32:57-07:00
New Revision: 7cc8fa2dd2d8167d427cadb4fc6f4254b53a8359

URL: 
https://github.com/llvm/llvm-project/commit/7cc8fa2dd2d8167d427cadb4fc6f4254b53a8359
DIFF: 
https://github.com/llvm/llvm-project/commit/7cc8fa2dd2d8167d427cadb4fc6f4254b53a8359.diff

LOG: Use llvm::is_contained (NFC)

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/lib/Analysis/ObjCNoReturn.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaOpenMP.cpp
lldb/source/Breakpoint/BreakpointID.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1afc1e13d25a7..4e74355f2639a 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -300,11 +300,8 @@ namespace clang {
   auto *ToNamed = cast(ToD);
   DeclContextLookupResult FromLookup =
   FromDC->lookup(FromNamed->getDeclName());
-  for (NamedDecl *ND : FromLookup)
-if (ND == FromNamed) {
-  ToDC->makeDeclVisibleInContext(ToNamed);
-  break;
-}
+  if (llvm::is_contained(FromLookup, FromNamed))
+ToDC->makeDeclVisibleInContext(ToNamed);
 }
   }
 }

diff  --git a/clang/lib/Analysis/ObjCNoReturn.cpp 
b/clang/lib/Analysis/ObjCNoReturn.cpp
index fe1edb496859e..9d7c365c3b992 100644
--- a/clang/lib/Analysis/ObjCNoReturn.cpp
+++ b/clang/lib/Analysis/ObjCNoReturn.cpp
@@ -54,12 +54,9 @@ bool ObjCNoReturn::isImplicitNoReturn(const ObjCMessageExpr 
*ME) {
   }
 
   if (const ObjCInterfaceDecl *ID = ME->getReceiverInterface()) {
-if (isSubclass(ID, NSExceptionII)) {
-  for (unsigned i = 0; i < NUM_RAISE_SELECTORS; ++i) {
-if (S == NSExceptionInstanceRaiseSelectors[i])
-  return true;
-  }
-}
+if (isSubclass(ID, NSExceptionII) &&
+llvm::is_contained(NSExceptionInstanceRaiseSelectors, S))
+  return true;
   }
 
   return false;

diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 0ad1ffb079b31..09418aa2390f2 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -822,17 +822,9 @@ CudaToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
   // flags are not duplicated.
   // Also append the compute capability.
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
-for (Arg *A : Args) {
-  bool IsDuplicate = false;
-  for (Arg *DALArg : *DAL) {
-if (A == DALArg) {
-  IsDuplicate = true;
-  break;
-}
-  }
-  if (!IsDuplicate)
+for (Arg *A : Args)
+  if (!llvm::is_contained(*DAL, A))
 DAL->append(A);
-}
 
 StringRef Arch = DAL->getLastArgValue(options::OPT_march_EQ);
 if (Arch.empty())

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 08381d0422058..6324cdc5a6b0a 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1217,9 +1217,8 @@ void ModuleMap::addHeader(Module *Mod, Module::Header 
Header,
   // FIXME: Should we diagnose if a header is listed twice in the
   // same module definition?
   auto &HeaderList = Headers[Header.Entry];
-  for (auto H : HeaderList)
-if (H == KH)
-  return;
+  if (llvm::is_contained(HeaderList, KH))
+return;
 
   HeaderList.push_back(KH);
   Mod->Headers[headerRoleToKind(Role)].push_back(Header);

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a7a48016fe1e2..63c2d9fff8816 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2688,12 +2688,7 @@ static bool isValidBPFPreserveEnumValueArg(Expr *Arg) {
 return false;
 
   // The enum value must be supported.
-  for (auto *EDI : ET->getDecl()->enumerators()) {
-if (EDI == Enumerator)
-  return true;
-  }
-
-  return false;
+  return llvm::is_contained(ET->getDecl()->enumerators(), Enumerator);
 }
 
 bool Sema::CheckBPFBuiltinFunctionCall(unsigned BuiltinID,

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 2e8f208866803..ccd17fc5102d1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4963,14 +4963,7 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind 
Kind,
   // directive.
   // At most one if clause with the particular directive-name-modifier can
   // appear on the directive.
-  bool MatchFound = false;
-  for (auto NM : AllowedNameModifiers) {
-if (CurNM == NM) {
-  MatchFound = true;
-  break;
-}
-  }
-  if (!MatchFound) {
+  if (!llvm::is_contained(AllowedNameModifiers, CurNM)) {
 S.Diag(IC->getNameModifierLoc(),
diag::err_omp_wrong_if_directive_name_modifier)
 << getOpenMPDire

[Lldb-commits] [PATCH] D112212: [lldb/test] Print build commands in trace mode

2021-10-24 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added a comment.

In D112212#3082352 , @JDevlieghere 
wrote:

> In D112212#3081935 , @dblaikie 
> wrote:
>
>> In D112212#3081828 , @JDevlieghere 
>> wrote:
>>
>>> In D112212#3080491 , @teemperor 
>>> wrote:
>>>
 This LGTM, but `shlex.join` is actually Py3 exclusive and I don't think 
 there is a good Py2 replacement. I think we're just in time for the Py2->3 
 migration according to the timeline Jonas posted last year 
 , so 
 let's use this patch to actually do that? Then we can also get rid of all 
 the `six` stuff etc.

 Let's see if Jonas has any objections against dropping Py2 with this, 
 otherwise this is good to go.
>>>
>>> We're planning to branch from open source on October 26th. If there's no 
>>> urgency, it would really be great if we can hold off breaking Py2 until 
>>> then.
>>>
>>> I'm all in favor for getting rid of Python 2 support, but sweeping changes 
>>> like dropping the `six` stuff will introduce a lot of headaches (merge 
>>> conflicts) for us. If we could postpone that for another release that would 
>>> save us a bunch of engineering time.
>>
>> No judgment (I think it's a reasonable request to punt a patch like this a 
>> few days if it helps out major contributors) - but I'm curious/just not 
>> quite wrapping my head around: Why would it be easier if this sort of patch 
>> went in after you branch? I'd have thought it'd be easier if it goes in 
>> before the branch. That way when you're backporting patches from upstream 
>> after the branch there will be fewer unrelated changes/merge conflicts, yeah?
>
> The patch introduces a dependency on Python 3 and unfortunately we still have 
> a small (but important) group of users that haven't fully migrated yet. If 
> the patch were to land before the branch, I'd have to revert it (same result) 
> or find a way to do what `shlex.join` does in Python 2. I did a quick search 
> yesterday and didn't immediately find a good alternative and with the 
> timeline I've given in the past, I also don't think the burden should be on 
> the patch author (Pavel). So that's why I suggested holding off on landing 
> it. If it does turn out to cause a lot of conflicts, I can always reconsider.
>
> But yes, backporting is a real concern, which is the main reason I'm asking 
> not to start making big mechanical changes like replacing all the `six` stuff 
> unless there's a pressing reason to do so.

Ah, fair enough - thanks for the context! (given that it'd be a matter of 
reverting the patch on your release branch - doesn't seem like a huge 
difference, but also easy to wait a few days) - *nod* cleanup's hopefully not 
too expensive to defer for a little while longer, if it's not getting in the 
way of some feature work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112212

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


[Lldb-commits] [lldb] 4bd4650 - Use llvm::any_of and llvm::none_of (NFC)

2021-10-24 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2021-10-24T17:35:33-07:00
New Revision: 4bd46501c394ce221d34b60155f48ebbf6b6897d

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

LOG: Use llvm::any_of and llvm::none_of (NFC)

Added: 


Modified: 
clang/include/clang/AST/DeclContextInternals.h
clang/lib/Analysis/CFG.cpp
clang/lib/Analysis/ThreadSafety.cpp
clang/lib/Basic/Targets/AVR.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/NeonEmitter.cpp
lld/ELF/SyntheticSections.cpp
lld/wasm/Writer.cpp
lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
lldb/source/Utility/VMRange.cpp
llvm/lib/Analysis/AssumptionCache.cpp
llvm/lib/Analysis/LoopCacheAnalysis.cpp
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/Support/TimeProfiler.cpp
llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index 2eef2343b7500..9899fc29b82d6 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -78,8 +78,7 @@ class StoredDeclsList {
 }
 Data.setPointer(NewHead);
 
-assert(llvm::find_if(getLookupResult(), ShouldErase) ==
-   getLookupResult().end() && "Still exists!");
+assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");
   }
 
   void erase(NamedDecl *ND) {

diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 69b745c8b4518..8a3051a2f9eed 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -5912,7 +5912,7 @@ static bool isImmediateSinkBlock(const CFGBlock *Blk) {
   // at least for now, but once we have better support for exceptions,
   // we'd need to carefully handle the case when the throw is being
   // immediately caught.
-  if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+  if (llvm::any_of(*Blk, [](const CFGElement &Elm) {
 if (Optional StmtElm = Elm.getAs())
   if (isa(StmtElm->getStmt()))
 return true;

diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index d6bb8cf673f75..b196ffa73cbfb 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -86,11 +86,9 @@ class CapExprSet : public SmallVector {
 public:
   /// Push M onto list, but discard duplicates.
   void push_back_nodup(const CapabilityExpr &CapE) {
-iterator It = std::find_if(begin(), end(),
-   [=](const CapabilityExpr &CapE2) {
-  return CapE.equals(CapE2);
-});
-if (It == end())
+if (llvm::none_of(*this, [=](const CapabilityExpr &CapE2) {
+  return CapE.equals(CapE2);
+}))
   push_back(CapE);
   }
 };

diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 38ce61386bb4c..50b0fc07b3118 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -313,10 +313,8 @@ static constexpr llvm::StringLiteral ValidFamilyNames[] = {
 bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
   bool IsFamily = llvm::is_contained(ValidFamilyNames, Name);
 
-  bool IsMCU =
-  llvm::find_if(AVRMcus, [&](const MCUInfo &Info) {
-return Info.Name == Name;
-  }) != std::end(AVRMcus);
+  bool IsMCU = llvm::any_of(
+  AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
   return IsFamily || IsMCU;
 }
 

diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index f860623e2bc37..afbebd070c054 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -83,7 +83,7 @@ CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr 
*E,
/* ParamsToSkip = */ 0);
 
   // We don't know how to emit non-scalar varargs.
-  if (std::any_of(Args.begin() + 1, Args.end(), [&](const CallArg &A) {
+  if (llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) {
 return !A.getRValue(*this).isScalar();
   })) {
 CGM.ErrorUnsupported(E, "non-scalar arg to printf");

diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 8a11da600e4a1..2d11495b4ff0a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -751,13 +751,11 @@ struct CounterCoverageMappin

[Lldb-commits] [PATCH] D112212: [lldb/test] Print build commands in trace mode

2021-10-24 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

Given that `shlex.join` is only used for making the diagnostics copy-pastable 
into the terminal, we could probably get away by just making it use the normal 
string conversion of list or something like `" ".join(...)`. I don't think we 
have anyone that really debugs tests in Python2 builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112212

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