[clang] [clang] Fix self-capturing `__block` variables (PR #89475)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 14:23:22 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff b6628c24ef017138b8d6eb288e94c141e7c846b0 9c61a1d684a15153ea73e2036cdf978ff187c44d -- clang/include/clang/AST/Decl.h clang/lib/AST/Decl.cpp clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGBlocks.h clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.h clang/lib/Sema/Sema.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/test/CodeGenCXX/block-capture.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 4bea057a15..2fdfee8e4f 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -2257,7 +2257,7 @@ class CXXByrefHelpers final : public BlockByrefHelpers {
 public:
   CXXByrefHelpers(const BlockByrefInfo &info, QualType type,
                   const Expr *copyExpr)
-    : BlockByrefHelpers(info), VarType(type), CopyExpr(copyExpr) {}
+      : BlockByrefHelpers(info), VarType(type), CopyExpr(copyExpr) {}
 
   bool needsCopy() const override { return CopyExpr != nullptr; }
   void emitCopy(CodeGenFunction &CGF, Address destField,
@@ -2470,16 +2470,16 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType,
         CGM.getContext().getBlockVarCopyInit(&var).getCopyExpr();
     if (!copyExpr && record->hasTrivialDestructor()) return nullptr;
 
-    return ::buildByrefHelpers(
-        CGM, byrefInfo, CXXByrefHelpers(byrefInfo, type, copyExpr));
+    return ::buildByrefHelpers(CGM, byrefInfo,
+                               CXXByrefHelpers(byrefInfo, type, copyExpr));
   }
 
   // If type is a non-trivial C struct type that is non-trivial to
   // destructly move or destroy, build the copy and dispose helpers.
   if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct ||
       type.isDestructedType() == QualType::DK_nontrivial_c_struct)
-    return ::buildByrefHelpers(
-        CGM, byrefInfo, NonTrivialCStructByrefHelpers(byrefInfo, type));
+    return ::buildByrefHelpers(CGM, byrefInfo,
+                               NonTrivialCStructByrefHelpers(byrefInfo, type));
 
   // Otherwise, if we don't have a retainable type, there's nothing to do.
   // that the runtime does extra copies.
@@ -2511,8 +2511,8 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType,
         return ::buildByrefHelpers(CGM, byrefInfo,
                                    ARCStrongBlockByrefHelpers(byrefInfo));
 
-      // Otherwise, we transfer ownership of the retain from the stack
-      // to the heap.
+        // Otherwise, we transfer ownership of the retain from the stack
+        // to the heap.
       } else {
         return ::buildByrefHelpers(CGM, byrefInfo,
                                    ARCStrongByrefHelpers(byrefInfo));
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 954dd10792..65366c65fc 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2088,8 +2088,10 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) {
       llvm::Constant *F = CGM.GetAddrOfFunction(FD);
       assert(F && "Could not find function!");
 
-      const CGFunctionInfo &Info = CGM.getTypes().arrangeFunctionDeclaration(FD);
-      EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D);
+      const CGFunctionInfo &Info =
+          CGM.getTypes().arrangeFunctionDeclaration(FD);
+      EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info,
+                                               &D);
     }
   }
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 0ac81bfc82..e7b3020556 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2210,6 +2210,7 @@ class CapturedByOwnInitVisitor
     : public EvaluatedExprVisitor<CapturedByOwnInitVisitor> {
   typedef EvaluatedExprVisitor<CapturedByOwnInitVisitor> Inherited;
   VarDecl *const VD;
+
 public:
   const BlockExpr *FoundBE;
   CapturedByOwnInitVisitor(Sema &S, VarDecl *VD)
@@ -2226,7 +2227,7 @@ public:
     }
   }
 };
-}
+} // namespace
 
 static void checkCapturedByOwnInit(VarDecl *VD, Sema &S) {
   Expr *I = VD->getInit();

``````````

</details>


https://github.com/llvm/llvm-project/pull/89475


More information about the cfe-commits mailing list