[PATCH] D79616: [NFC][DwarfDebug] Avoid default capturing when using lambdas

Djordje Todorovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 00:29:40 PDT 2020


djtodoro created this revision.
djtodoro added reviewers: vsk, dstenb, aprantl.
djtodoro added projects: LLVM, debug-info.
Herald added subscribers: llvm-commits, hiraditya.

It is bad practice to capture by default (via `[&]` in this case) when using lambdas, so we should avoid that as much as possible.
This patch fixes that in the `getForwardingRegsDefinedByMI` from `DwarfDebug` module.


https://reviews.llvm.org/D79616

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -706,20 +706,21 @@
 
   // If the MI is an instruction defining one or more parameters' forwarding
   // registers, add those defines.
-  auto getForwardingRegsDefinedByMI = [&](const MachineInstr &MI,
-                                          SmallSetVector<unsigned, 4> &Defs) {
-    if (MI.isDebugInstr())
-      return;
-
-    for (const MachineOperand &MO : MI.operands()) {
-      if (MO.isReg() && MO.isDef() &&
-          Register::isPhysicalRegister(MO.getReg())) {
-        for (auto FwdReg : ForwardedRegWorklist)
-          if (TRI->regsOverlap(FwdReg.first, MO.getReg()))
-            Defs.insert(FwdReg.first);
-      }
-    }
-  };
+  auto getForwardingRegsDefinedByMI =
+      [&ForwardedRegWorklist, &TRI](const MachineInstr &MI,
+                                    SmallSetVector<unsigned, 4> &Defs) {
+        if (MI.isDebugInstr())
+          return;
+
+        for (const MachineOperand &MO : MI.operands()) {
+          if (MO.isReg() && MO.isDef() &&
+              Register::isPhysicalRegister(MO.getReg())) {
+            for (auto FwdReg : ForwardedRegWorklist)
+              if (TRI->regsOverlap(FwdReg.first, MO.getReg()))
+                Defs.insert(FwdReg.first);
+          }
+        }
+      };
 
   // Search for a loading value in forwarding registers.
   for (; I != MBB->rend(); ++I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79616.262821.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200508/de9d2211/attachment.bin>


More information about the llvm-commits mailing list