https://github.com/antoniofrighetto created 
https://github.com/llvm/llvm-project/pull/71452

Emission of `mustprogress` attribute was previously occuring only when entering 
`EmitFunctionBody`. Other paths for function body generation may lack the 
attribute, potentially leading to suboptimal optimizations later in the 
pipeline. This has been addressed by deferring the attribute emission after the 
function body has been generated across all the paths.

>From f4a92a64c38c726ea091fc21328ee244ac437be0 Mon Sep 17 00:00:00 2001
From: Antonio Frighetto <m...@antoniofrighetto.com>
Date: Mon, 6 Nov 2023 23:20:31 +0100
Subject: [PATCH] [clang][CodeGen] Ensure consistent `mustprogress` attribute
 emission

Emission of `mustprogress` attribute was previously occuring only when
entering `EmitFunctionBody`. Other paths for function body generation
may lack the attribute, potentially leading to suboptimal optimizations
later in the pipeline. This has been addressed by deferring the attribute
emission after the function body has been generated across all the paths.
---
 clang/lib/CodeGen/CodeGenFunction.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 6a910abcfe21d2f..f4e2dc373be7f24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1262,11 +1262,6 @@ void CodeGenFunction::EmitFunctionBody(const Stmt *Body) 
{
     EmitCompoundStmtWithoutScope(*S);
   else
     EmitStmt(Body);
-
-  // This is checked after emitting the function body so we know if there
-  // are any permitted infinite loops.
-  if (checkIfFunctionMustProgress())
-    CurFn->addFnAttr(llvm::Attribute::MustProgress);
 }
 
 /// When instrumenting to collect profile data, the counts for some blocks
@@ -1482,6 +1477,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
   } else
     llvm_unreachable("no definition for emitted function");
 
+  // This is checked after emitting the function body so we know if there
+  // are any permitted infinite loops.
+  if (checkIfFunctionMustProgress())
+    CurFn->addFnAttr(llvm::Attribute::MustProgress);
+
   // C++11 [stmt.return]p2:
   //   Flowing off the end of a function [...] results in undefined behavior in
   //   a value-returning function.

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

Reply via email to