diff options
author | Antonio Frighetto <me@antoniofrighetto.com> | 2023-11-06 23:20:31 +0100 |
---|---|---|
committer | Antonio Frighetto <me@antoniofrighetto.com> | 2023-11-11 09:43:03 +0100 |
commit | 970bf07d0b184c7ec356ae8f47b193a5e3ff0309 (patch) | |
tree | b3ab44571a5c64b2bea71830673aae90266f8c12 /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | bafd35ca04bd97fd1bbf9bb49051bd8fd0983697 (diff) | |
download | llvm-970bf07d0b184c7ec356ae8f47b193a5e3ff0309.zip llvm-970bf07d0b184c7ec356ae8f47b193a5e3ff0309.tar.gz llvm-970bf07d0b184c7ec356ae8f47b193a5e3ff0309.tar.bz2 |
[clang][CodeGen] Ensure consistent `mustprogress` attribute emission
Emission of `mustprogress` attribute previously occurred only within
`EmitFunctionBody`, after generating the function body. Other routines
for function body creation may lack the attribute, potentially leading
to suboptimal optimizations later in the pipeline. Attribute emission
is now anticipated prior to generating the function body.
Fixes: https://github.com/llvm/llvm-project/issues/69833.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 6a910ab..b91e5da 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 @@ -1445,6 +1440,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, if (Body && isa_and_nonnull<CoroutineBodyStmt>(Body)) llvm::append_range(FnArgs, FD->parameters()); + // Ensure that the function adheres to the forward progress guarantee, which + // is required by certain optimizations. + if (checkIfFunctionMustProgress()) + CurFn->addFnAttr(llvm::Attribute::MustProgress); + // Generate the body of the function. PGO.assignRegionCounters(GD, CurFn); if (isa<CXXDestructorDecl>(FD)) |