[llvm] [polly] Slightly improve the getenv("bar") linking problem (PR #150020)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 22 07:07:08 PDT 2025


================
@@ -22,12 +22,10 @@ namespace {
     ForceAsmWriterLinking() {
       // We must reference the plug-ins in such a way that compilers will not
       // delete it all as dead code, even with whole program optimization,
-      // yet is effectively a NO-OP. As the compiler isn't smart enough
-      // to know that getenv() never returns -1, this will do the job.
-      // This is so that globals in the translation units where these functions
-      // are defined are forced to be initialized, populating various
-      // registries.
-      if (std::getenv("bar") != (char*) -1)
+      // yet is effectively a NO-OP. This is so that globals in the translation
+      // units where these functions are defined are forced to be initialized,
+      // populating various registries.
+      if (llvm::getNonFoldableAlwaysTrue())
----------------
nikic wrote:

I don't think we can include LinkAllPasses.h here. Something that wants to link AsmWriter shouldn't be forced to also link all optimization passes.

This function needs to be declared in some other header that all of these linking headers can use. Probably somewhere in Support.

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


More information about the llvm-commits mailing list