https://github.com/E00N777 created 
https://github.com/llvm/llvm-project/pull/226877

Follow-up to PR : https://github.com/llvm/llvm-project/pull/223418. 
Move emit Lifetime marker helper function to FunctionUtils.

Assisted by : Codex gpt-6-Sol

>From 55a6cb8d17da05d7247e13a9384c589f111114ca Mon Sep 17 00:00:00 2001
From: E00N777 <[email protected]>
Date: Mon, 28 Sep 2026 11:43:58 +0800
Subject: [PATCH] [CIR][CodeGen][NFC] Move ast helper function to FunctionUtils

---
 clang/include/clang/CodeGenUtils/FunctionUtils.h |  8 ++++++++
 clang/lib/CIR/CodeGen/CIRGenFunction.cpp         | 16 +---------------
 clang/lib/CodeGenUtils/FunctionUtils.cpp         | 13 +++++++++++++
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/CodeGenUtils/FunctionUtils.h 
b/clang/include/clang/CodeGenUtils/FunctionUtils.h
index f924874d829e0..faec209105521 100644
--- a/clang/include/clang/CodeGenUtils/FunctionUtils.h
+++ b/clang/include/clang/CodeGenUtils/FunctionUtils.h
@@ -17,12 +17,20 @@
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/LangOptions.h"
 
+namespace clang {
+class Stmt;
+}
+
 namespace clang::CodeGenUtils {
 
 /// Decide whether we need to emit the lifetime markers.
 bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
                                const LangOptions &LangOpts);
 
+/// Whether the statement tree contains a construct that may bypass a local's
+/// initialization. Used to conservatively suppress lifetime markers.
+bool functionMightHaveBypass(const Stmt *S);
+
 } // namespace clang::CodeGenUtils
 
 #endif // LLVM_CLANG_CODEGENUTILS_FUNCTIONUTILS_H
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp 
b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 333610196c796..30caa2a455a07 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -30,20 +30,6 @@
 
 namespace clang::CIRGen {
 
-/// Does the statement tree rooted at \p s contain a label, switch, or indirect
-/// goto that could bypass a local's initialization? A coarse stand-in for
-/// classic CodeGen's per-decl bypass analysis (PR28267).
-static bool functionMightHaveBypass(const Stmt *s) {
-  if (!s)
-    return false;
-  if (isa<LabelStmt, SwitchStmt, IndirectGotoStmt>(s))
-    return true;
-  for (const Stmt *child : s->children())
-    if (functionMightHaveBypass(child))
-      return true;
-  return false;
-}
-
 CIRGenFunction::CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder,
                                bool suppressNewContext)
     : CIRGenTypeCache(cgm), cgm{cgm}, builder(builder),
@@ -780,7 +766,7 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl 
gd, cir::FuncOp fn,
       llvm::append_range(fnArgs, funcDecl->parameters());
 
     if (shouldEmitLifetimeMarkers)
-      fnHasBypassStmt = functionMightHaveBypass(body);
+      fnHasBypassStmt = CodeGenUtils::functionMightHaveBypass(body);
 
     if (isa<CXXDestructorDecl>(funcDecl)) {
       emitDestructorBody(args);
diff --git a/clang/lib/CodeGenUtils/FunctionUtils.cpp 
b/clang/lib/CodeGenUtils/FunctionUtils.cpp
index 9f01745abbf82..1d78576e44512 100644
--- a/clang/lib/CodeGenUtils/FunctionUtils.cpp
+++ b/clang/lib/CodeGenUtils/FunctionUtils.cpp
@@ -7,6 +7,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang/CodeGenUtils/FunctionUtils.h"
+#include "clang/AST/Stmt.h"
+#include "llvm/Support/Casting.h"
 
 namespace clang::CodeGenUtils {
 
@@ -26,4 +28,15 @@ bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
   return CGOpts.OptimizationLevel != 0;
 }
 
+bool functionMightHaveBypass(const Stmt *S) {
+  if (!S)
+    return false;
+  if (llvm::isa<LabelStmt, SwitchStmt, IndirectGotoStmt>(S))
+    return true;
+  for (const Stmt *Child : S->children())
+    if (functionMightHaveBypass(Child))
+      return true;
+  return false;
+}
+
 } // namespace clang::CodeGenUtils

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to