Make implicit `this` captures explicit

When declaring a lambda with a value-capture default `[=, ...]`, the `this` pointer is implicitly captured by value as well. This results in potentially-unintuitive behavior (https://reviews.llvm.org/D142639) and is deprecated in C++20. It produces a warning in newer versions of clang.

Unfortunately, several compilers disallow explicitly capturing `this` with a value-capture default, so to get around this we capture necessary variable directly, with no capture default.

Since it's just removing syntactic sugar, there are no changes to the compiled code. In conjunction with a patch to marl (https://github.com/google/marl/pull/266), this should remove all the instances of the warning from swiftshader.

Bug: 351004963
Change-Id: I0c6641ca1ba1f5995472ba036f994ca94e6f2b4a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/73808
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/src/Pipeline/ComputeProgram.cpp b/src/Pipeline/ComputeProgram.cpp
index 415f2a0..a26f3f4 100644
--- a/src/Pipeline/ComputeProgram.cpp
+++ b/src/Pipeline/ComputeProgram.cpp
@@ -218,14 +218,18 @@
 	data.pushConstants = pushConstants;
 
 	marl::WaitGroup wg;
-	const uint32_t batchCount = 16;
+	constexpr uint32_t batchCount = 16;
 
 	auto groupCount = groupCountX * groupCountY * groupCountZ;
 
 	for(uint32_t batchID = 0; batchID < batchCount && batchID < groupCount; batchID++)
 	{
 		wg.add(1);
-		marl::schedule([=, &data] {
+		marl::schedule([this, batchID, groupCount, groupCountX, groupCountY,
+		                baseGroupZ, baseGroupY, baseGroupX, wg, subgroupsPerWorkgroup,
+		                &data] {
+			// Workaround for the fact that some compilers don't allow batchCount to be captured.
+			constexpr uint32_t batchCount = 16;
 			defer(wg.done());
 			std::vector<uint8_t> workgroupMemory(shader->workgroupMemory.size());
 
diff --git a/src/Reactor/Coroutine.hpp b/src/Reactor/Coroutine.hpp
index 8c9e15f..63f9408 100644
--- a/src/Reactor/Coroutine.hpp
+++ b/src/Reactor/Coroutine.hpp
@@ -185,7 +185,7 @@
 	finalize();
 
 	// TODO(b/148400732): Go back to just calling the CoroutineEntryBegin function directly.
-	std::function<Nucleus::CoroutineHandle()> coroutineBegin = [=] {
+	std::function<Nucleus::CoroutineHandle()> coroutineBegin = [this, args...] {
 		using Sig = Nucleus::CoroutineBegin<Arguments...>;
 		auto pfn = (Sig *)routine->getEntry(Nucleus::CoroutineEntryBegin);
 		auto handle = pfn(args...);
diff --git a/third_party/llvm-10.0/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/third_party/llvm-10.0/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 667e1a0..fefce4b 100644
--- a/third_party/llvm-10.0/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/third_party/llvm-10.0/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -2938,7 +2938,7 @@
   // is a load, return the new registers in ValRegs. For a store, each elements
   // of ValRegs should be PartTy. Returns the next offset that needs to be
   // handled.
-  auto splitTypePieces = [=](LLT PartTy, SmallVectorImpl<Register> &ValRegs,
+  auto splitTypePieces = [this, IsLoad, MMO, OffsetTy, NumParts, TotalSize, AddrReg](LLT PartTy, SmallVectorImpl<Register> &ValRegs,
                              unsigned Offset) -> unsigned {
     MachineFunction &MF = MIRBuilder.getMF();
     unsigned PartSize = PartTy.getSizeInBits();
diff --git a/third_party/llvm-10.0/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/third_party/llvm-10.0/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index 7bb0194..5afff13 100644
--- a/third_party/llvm-10.0/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/third_party/llvm-10.0/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -65,7 +65,7 @@
   DWARFDataExtractor Data(Obj, Section, LE, 0);
   // Lazy initialization of Parser, now that we have all section info.
   if (!Parser) {
-    Parser = [=, &Context, &Obj, &Section, &SOS,
+    Parser = [this, DA, RS, LocSection, SS, AOS, LE, IsDWO, &Context, &Obj, &Section, &SOS,
               &LS](uint64_t Offset, DWARFSectionKind SectionKind,
                    const DWARFSection *CurSection,
                    const DWARFUnitIndex::Entry *IndexEntry)
diff --git a/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index 30906a3..878161d 100644
--- a/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -2445,7 +2445,7 @@
 
   bool IsKillSet = false;
 
-  auto clearOperandKillInfo = [=] (MachineInstr &MI, unsigned Index) {
+  auto clearOperandKillInfo = [this, RegNo] (MachineInstr &MI, unsigned Index) {
     MachineOperand &MO = MI.getOperand(Index);
     if (MO.isReg() && MO.isUse() && MO.isKill() &&
         getRegisterInfo().regsOverlap(MO.getReg(), RegNo))
diff --git a/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
index 74192cb..4531dd6 100644
--- a/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ b/third_party/llvm-10.0/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -361,7 +361,7 @@
         // redundant. Replace with a copy. This doesn't happen directly due
         // to code in PPCDAGToDAGISel.cpp, but it can happen when converting
         // a load of a double to a vector of 64-bit integers.
-        auto isConversionOfLoadAndSplat = [=]() -> bool {
+        auto isConversionOfLoadAndSplat = [this, DefOpc, TRI, DefMI]() -> bool {
           if (DefOpc != PPC::XVCVDPSXDS && DefOpc != PPC::XVCVDPUXDS)
             return false;
           unsigned FeedReg1 =
@@ -464,7 +464,7 @@
         if (!DefMI)
           break;
         unsigned DefOpcode = DefMI->getOpcode();
-        auto isConvertOfSplat = [=]() -> bool {
+        auto isConvertOfSplat = [this, DefOpcode, DefMI]() -> bool {
           if (DefOpcode != PPC::XVCVSPSXWS && DefOpcode != PPC::XVCVSPUXWS)
             return false;
           Register ConvReg = DefMI->getOperand(1).getReg();
diff --git a/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 04c7e85..e2c9e6f 100644
--- a/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -769,7 +769,7 @@
       Visibility = GlobalValue::HiddenVisibility;
     }
   }
-  auto MaybeSetComdat = [=](GlobalVariable *GV) {
+  auto MaybeSetComdat = [this, NeedComdat](GlobalVariable *GV) {
     if (NeedComdat)
       GV->setComdat(M->getOrInsertComdat(GV->getName()));
   };
diff --git a/third_party/llvm-10.0/llvm/lib/Transforms/Scalar/GVNSink.cpp b/third_party/llvm-10.0/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 6d0a497..7891c03 100644
--- a/third_party/llvm-10.0/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/third_party/llvm-10.0/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -494,7 +494,7 @@
 
     uint32_t e = ExpressionNumbering[exp];
     if (!e) {
-      hash_code H = exp->getHashValue([=](Value *V) { return lookupOrAdd(V); });
+      hash_code H = exp->getHashValue([this](Value *V) { return lookupOrAdd(V); });
       auto I = HashNumbering.find(H);
       if (I != HashNumbering.end()) {
         e = I->second;
diff --git a/third_party/llvm-10.0/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/third_party/llvm-10.0/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index ebfd5fe..e7fd775 100644
--- a/third_party/llvm-10.0/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/third_party/llvm-10.0/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6827,7 +6827,7 @@
   auto isOptimizableIVTruncate =
       [&](Instruction *K) -> std::function<bool(unsigned)> {
     return
-        [=](unsigned VF) -> bool { return CM.isOptimizableIVTruncate(K, VF); };
+        [this, K](unsigned VF) -> bool { return CM.isOptimizableIVTruncate(K, VF); };
   };
 
   if (isa<TruncInst>(I) && LoopVectorizationPlanner::getDecisionAndClampRange(