[clang] [Clang] Ensure that .fini_array is available with -fno-use-cxa-atexit (PR #211963)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 25 22:55:56 PDT 2026


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 origin/main HEAD --extensions cpp -- clang/lib/CodeGen/ItaniumCXXABI.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 59374b13a..2b3b04c90 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3136,16 +3136,16 @@ void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
   if (!CGM.getLangOpts().hasAtExit() && !D.isStaticLocal())
     return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
 
-  // If '-fno-use-cxa-atexit' and '-fno-register-global-dtors-with-atexit' are also sepcified,
-  // this means the user does not want any invocation to __cxa_atexit or atexit,
-  // but we still have to check if the declaration is static-local or thread-local,
-  // which should not be supported by this case.
-  // As we investigated, ELF has its .fini_array section to support the global destructors.
-  // So we can safely apply this to ELF.
+  // If '-fno-use-cxa-atexit' and '-fno-register-global-dtors-with-atexit' are
+  // also sepcified, this means the user does not want any invocation to
+  // __cxa_atexit or atexit, but we still have to check if the declaration is
+  // static-local or thread-local, which should not be supported by this case.
+  // As we investigated, ELF has its .fini_array section to support the global
+  // destructors. So we can safely apply this to ELF.
   if (CGM.getTarget().getTriple().isOSBinFormatELF() &&
-    !CGM.getCodeGenOpts().CXAAtExit &&
-    !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
-    !D.isStaticLocal() && !D.getTLSKind())
+      !CGM.getCodeGenOpts().CXAAtExit &&
+      !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
+      !D.isStaticLocal() && !D.getTLSKind())
     return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
 
   // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit

``````````

</details>


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


More information about the cfe-commits mailing list