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

Luke Drummond via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 22 06:20:32 PDT 2025


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

There's been a variation of the following in the code since 2005:

    if (unoptimizable_true)
      return;
    use_this_symbol_to_force_linking(); // unreachable but never removed

Way back in 00d5508496c it was the win32 call `GetCurrentProcess` but switched to `getenv("bar")` fairly soon after in 63e504ff43. While that pulled in fewer dependencies and made the code portable, it's a bit of a weird construct. The environment variable used for the `getenv` call is "bar", which is particularly weird to see fly past when you run `ltrace` on a binary linked against LLVM.

In this patch I don't try to replace this construct wholesale - it's still required for architectural reasons I'm not able to tackle right now, but I did try and make it slightly less weird and opaque:

- It gives the construct a name
- The environment variable hints where this comes from and that its value is ignored

Combined, this should be a bit of improvement for the next person who wonders what LLVM is up to when they trace their process or see smatterings of `getenv("bar")` dotted around the source.

>From e5440464e7921bd6f6db3df2454c0ced9e1a6442 Mon Sep 17 00:00:00 2001
From: Luke Drummond <luke.drummond at codeplay.com>
Date: Thu, 13 Oct 2022 16:57:43 +0100
Subject: [PATCH] Slightly improve the getenv("bar") linking problem

There's been a variation of the following in the code since 2005:

    if (unoptimizable_true)
      return;
    use_this_symbol_to_force_linking(); // unreachable but never removed

Way back in 00d5508496c it was the win32 call `GetCurrentProcess`
but switched to `getenv("bar")` fairly soon after in 63e504ff43. While
that pulled in fewer dependencies and made the code portable, it's a
bit of a weird construct. The environment variable used for the `getenv`
call is "bar", which is particularly weird to see fly past when you run
`ltrace` on a binary linked against LLVM.

In this patch I don't try to replace this construct wholesale - it's
still required for architectural reasons I'm not able to tackle right
now, but I did try and make it slightly less weird and opaque:

- It gives the construct a name
- The environment variable hints where this comes from and that its
  value is ignored

Combined, this should be a bit of improvement for the next person who
wonders what LLVM is up to when they trace their process or see
smatterings of `getenv("bar")` dotted around the source.
---
 .../llvm/CodeGen/LinkAllAsmWriterComponents.h |   2 +-
 .../llvm/CodeGen/LinkAllCodegenComponents.h   |   2 +-
 llvm/include/llvm/ExecutionEngine/MCJIT.h     |   2 +-
 llvm/include/llvm/LinkAllIR.h                 |   6 +-
 llvm/include/llvm/LinkAllPasses.h             | 314 +++++++++++-------
 llvm/tools/bugpoint/bugpoint.cpp              |   2 +-
 polly/include/polly/LinkAllPasses.h           |   2 +-
 7 files changed, 209 insertions(+), 121 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/LinkAllAsmWriterComponents.h b/llvm/include/llvm/CodeGen/LinkAllAsmWriterComponents.h
index c22f9d49f374b..e9ba44d298e38 100644
--- a/llvm/include/llvm/CodeGen/LinkAllAsmWriterComponents.h
+++ b/llvm/include/llvm/CodeGen/LinkAllAsmWriterComponents.h
@@ -27,7 +27,7 @@ namespace {
       // 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)
+      if (llvm::getNonFoldableAlwaysTrue())
         return;
 
       llvm::linkOcamlGCPrinter();
diff --git a/llvm/include/llvm/CodeGen/LinkAllCodegenComponents.h b/llvm/include/llvm/CodeGen/LinkAllCodegenComponents.h
index 6f56682dce5fa..5448f5be83974 100644
--- a/llvm/include/llvm/CodeGen/LinkAllCodegenComponents.h
+++ b/llvm/include/llvm/CodeGen/LinkAllCodegenComponents.h
@@ -29,7 +29,7 @@ namespace {
       // 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)
+      if (llvm::getNonFoldableAlwaysTrue())
         return;
 
       (void) llvm::createFastRegisterAllocator();
diff --git a/llvm/include/llvm/ExecutionEngine/MCJIT.h b/llvm/include/llvm/ExecutionEngine/MCJIT.h
index c836c06813fc6..9b4bf24753f24 100644
--- a/llvm/include/llvm/ExecutionEngine/MCJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/MCJIT.h
@@ -30,7 +30,7 @@ namespace {
       // 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)
+      if (llvm::getNonFoldableAlwaysTrue())
         return;
 
       LLVMLinkInMCJIT();
diff --git a/llvm/include/llvm/LinkAllIR.h b/llvm/include/llvm/LinkAllIR.h
index ceed784d557de..8ea346f567ee9 100644
--- a/llvm/include/llvm/LinkAllIR.h
+++ b/llvm/include/llvm/LinkAllIR.h
@@ -35,13 +35,11 @@ namespace {
   struct ForceVMCoreLinking {
     ForceVMCoreLinking() {
       // We must reference VMCore 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.
+      // delete it all as dead code, even with whole program optimization.
       // 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)
+      if (llvm::getNonFoldableAlwaysTrue())
         return;
       llvm::LLVMContext Context;
       (void)new llvm::Module("", Context);
diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h
index bae7f0da7022c..200b2ae2c9e4a 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -18,10 +18,13 @@
 #include "llvm/Analysis/AliasAnalysisEvaluator.h"
 #include "llvm/Analysis/AliasSetTracker.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
+#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
+#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
 #include "llvm/Analysis/CallPrinter.h"
-#include "llvm/Analysis/DXILResource.h"
 #include "llvm/Analysis/DomPrinter.h"
 #include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/IntervalPartition.h"
+#include "llvm/Analysis/Lint.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/RegionPass.h"
@@ -35,132 +38,219 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/Support/Valgrind.h"
+#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
+#include "llvm/Transforms/IPO/Attributor.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
+#include "llvm/Transforms/Instrumentation.h"
+#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
 #include "llvm/Transforms/Scalar/Scalarizer.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
-#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
+#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
+#include "llvm/Transforms/Vectorize.h"
 #include <cstdlib>
 
 namespace llvm {
-class Triple;
+  inline bool getNonFoldableAlwaysTrue() {
+    // Some parts of the codebase require a "constant true value" used as a
+    // predicate. These cases require that even with LTO and static linking,
+    // it's not possible to for the compiler to fold the value. As compilers
+    // aren't smart enough to know that getenv() never returns -1, this will do
+    // the job.
+    return std::getenv("LLVM_IGNORED_ENV_VAR") != (char *)-1;
+  }
 }
-
 namespace {
-struct ForcePassLinking {
-  ForcePassLinking() {
-    // We must reference the passes 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)
-      return;
+  struct ForcePassLinking {
+    ForcePassLinking() {
+      // We must reference the passes 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 (llvm::getNonFoldableAlwaysTrue())
+        return;
 
-    (void)llvm::createAtomicExpandLegacyPass();
-    (void)llvm::createBasicAAWrapperPass();
-    (void)llvm::createSCEVAAWrapperPass();
-    (void)llvm::createTypeBasedAAWrapperPass();
-    (void)llvm::createScopedNoAliasAAWrapperPass();
-    (void)llvm::createBreakCriticalEdgesPass();
-    (void)llvm::createCallGraphDOTPrinterPass();
-    (void)llvm::createCallGraphViewerPass();
-    (void)llvm::createCFGSimplificationPass();
-    (void)llvm::createStructurizeCFGPass();
-    (void)llvm::createDXILResourceWrapperPassPass();
-    (void)llvm::createDXILResourceTypeWrapperPassPass();
-    (void)llvm::createDeadArgEliminationPass();
-    (void)llvm::createDeadCodeEliminationPass();
-    (void)llvm::createDependenceAnalysisWrapperPass();
-    (void)llvm::createDomOnlyPrinterWrapperPassPass();
-    (void)llvm::createDomPrinterWrapperPassPass();
-    (void)llvm::createDomOnlyViewerWrapperPassPass();
-    (void)llvm::createDomViewerWrapperPassPass();
-    (void)llvm::createAlwaysInlinerLegacyPass();
-    (void)llvm::createGlobalMergeFuncPass();
-    (void)llvm::createGlobalsAAWrapperPass();
-    (void)llvm::createInstSimplifyLegacyPass();
-    (void)llvm::createInstructionCombiningPass();
-    (void)llvm::createJMCInstrumenterPass();
-    (void)llvm::createKCFIPass();
-    (void)llvm::createLCSSAPass();
-    (void)llvm::createLICMPass();
-    (void)llvm::createLazyValueInfoPass();
-    (void)llvm::createLoopExtractorPass();
-    (void)llvm::createLoopSimplifyPass();
-    (void)llvm::createLoopStrengthReducePass();
-    (void)llvm::createLoopTermFoldPass();
-    (void)llvm::createLoopUnrollPass();
-    (void)llvm::createLowerGlobalDtorsLegacyPass();
-    (void)llvm::createLowerInvokePass();
-    (void)llvm::createLowerSwitchPass();
-    (void)llvm::createNaryReassociatePass();
-    (void)llvm::createObjCARCContractPass();
-    (void)llvm::createPromoteMemoryToRegisterPass();
-    (void)llvm::createRegToMemWrapperPass();
-    (void)llvm::createPostDomOnlyPrinterWrapperPassPass();
-    (void)llvm::createPostDomPrinterWrapperPassPass();
-    (void)llvm::createPostDomOnlyViewerWrapperPassPass();
-    (void)llvm::createPostDomViewerWrapperPassPass();
-    (void)llvm::createReassociatePass();
-    (void)llvm::createRegionInfoPass();
-    (void)llvm::createRegionOnlyPrinterPass();
-    (void)llvm::createRegionOnlyViewerPass();
-    (void)llvm::createRegionPrinterPass();
-    (void)llvm::createRegionViewerPass();
-    (void)llvm::createSafeStackPass();
-    (void)llvm::createSROAPass();
-    (void)llvm::createSingleLoopExtractorPass();
-    (void)llvm::createTailCallEliminationPass();
-    (void)llvm::createConstantHoistingPass();
-    (void)llvm::createCodeGenPrepareLegacyPass();
-    (void)llvm::createPostInlineEntryExitInstrumenterPass();
-    (void)llvm::createEarlyCSEPass();
-    (void)llvm::createGVNPass();
-    (void)llvm::createPostDomTree();
-    (void)llvm::createMergeICmpsLegacyPass();
-    (void)llvm::createExpandLargeDivRemPass();
-    (void)llvm::createExpandMemCmpLegacyPass();
-    std::string buf;
-    llvm::raw_string_ostream os(buf);
-    (void)llvm::createPrintModulePass(os);
-    (void)llvm::createPrintFunctionPass(os);
-    (void)llvm::createSinkingPass();
-    (void)llvm::createLowerAtomicPass();
-    (void)llvm::createLoadStoreVectorizerPass();
-    (void)llvm::createPartiallyInlineLibCallsPass();
-    (void)llvm::createScalarizerPass();
-    (void)llvm::createSeparateConstOffsetFromGEPPass();
-    (void)llvm::createSpeculativeExecutionPass();
-    (void)llvm::createSpeculativeExecutionIfHasBranchDivergencePass();
-    (void)llvm::createStraightLineStrengthReducePass();
-    (void)llvm::createScalarizeMaskedMemIntrinLegacyPass();
-    (void)llvm::createHardwareLoopsLegacyPass();
-    (void)llvm::createUnifyLoopExitsPass();
-    (void)llvm::createFixIrreduciblePass();
-    (void)llvm::createSelectOptimizePass();
+      (void) llvm::createAAEvalPass();
+      (void) llvm::createAggressiveDCEPass();
+      (void) llvm::createAggressiveInstCombinerPass();
+      (void) llvm::createBitTrackingDCEPass();
+      (void)llvm::createOpenMPOptCGSCCLegacyPass();
+      (void) llvm::createAlignmentFromAssumptionsPass();
+      (void) llvm::createBasicAAWrapperPass();
+      (void) llvm::createSCEVAAWrapperPass();
+      (void) llvm::createTypeBasedAAWrapperPass();
+      (void) llvm::createScopedNoAliasAAWrapperPass();
+      (void) llvm::createBoundsCheckingLegacyPass();
+      (void) llvm::createBreakCriticalEdgesPass();
+      (void) llvm::createCallGraphDOTPrinterPass();
+      (void) llvm::createCallGraphViewerPass();
+      (void) llvm::createCFGSimplificationPass();
+      (void) llvm::createCFLAndersAAWrapperPass();
+      (void) llvm::createCFLSteensAAWrapperPass();
+      (void) llvm::createStructurizeCFGPass();
+      (void) llvm::createLibCallsShrinkWrapPass();
+      (void) llvm::createCalledValuePropagationPass();
+      (void) llvm::createConstantMergePass();
+      (void) llvm::createCostModelAnalysisPass();
+      (void) llvm::createDeadArgEliminationPass();
+      (void) llvm::createDeadCodeEliminationPass();
+      (void) llvm::createDeadStoreEliminationPass();
+      (void) llvm::createDependenceAnalysisWrapperPass();
+      (void) llvm::createDomOnlyPrinterWrapperPassPass();
+      (void) llvm::createDomPrinterWrapperPassPass();
+      (void) llvm::createDomOnlyViewerWrapperPassPass();
+      (void) llvm::createDomViewerWrapperPassPass();
+      (void) llvm::createFunctionInliningPass();
+      (void) llvm::createAlwaysInlinerLegacyPass();
+      (void) llvm::createGlobalDCEPass();
+      (void) llvm::createGlobalOptimizerPass();
+      (void) llvm::createGlobalsAAWrapperPass();
+      (void) llvm::createGuardWideningPass();
+      (void) llvm::createLoopGuardWideningPass();
+      (void) llvm::createIPSCCPPass();
+      (void) llvm::createInductiveRangeCheckEliminationPass();
+      (void) llvm::createIndVarSimplifyPass();
+      (void) llvm::createInstSimplifyLegacyPass();
+      (void) llvm::createInstructionCombiningPass();
+      (void) llvm::createInternalizePass();
+      (void) llvm::createJMCInstrumenterPass();
+      (void) llvm::createLCSSAPass();
+      (void) llvm::createLegacyDivergenceAnalysisPass();
+      (void) llvm::createLICMPass();
+      (void) llvm::createLoopSinkPass();
+      (void) llvm::createLazyValueInfoPass();
+      (void) llvm::createLoopExtractorPass();
+      (void) llvm::createLoopInterchangePass();
+      (void) llvm::createLoopFlattenPass();
+      (void) llvm::createLoopPredicationPass();
+      (void) llvm::createLoopSimplifyPass();
+      (void) llvm::createLoopSimplifyCFGPass();
+      (void) llvm::createLoopStrengthReducePass();
+      (void) llvm::createLoopRerollPass();
+      (void) llvm::createLoopUnrollPass();
+      (void) llvm::createLoopUnrollAndJamPass();
+      (void) llvm::createLoopVersioningLICMPass();
+      (void) llvm::createLoopIdiomPass();
+      (void) llvm::createLoopRotatePass();
+      (void) llvm::createLowerConstantIntrinsicsPass();
+      (void) llvm::createLowerExpectIntrinsicPass();
+      (void) llvm::createLowerGlobalDtorsLegacyPass();
+      (void) llvm::createLowerInvokePass();
+      (void) llvm::createLowerSwitchPass();
+      (void) llvm::createNaryReassociatePass();
+      (void) llvm::createObjCARCAAWrapperPass();
+      (void) llvm::createObjCARCAPElimPass();
+      (void) llvm::createObjCARCExpandPass();
+      (void) llvm::createObjCARCContractPass();
+      (void) llvm::createObjCARCOptPass();
+      (void) llvm::createPromoteMemoryToRegisterPass();
+      (void) llvm::createDemoteRegisterToMemoryPass();
+      (void)llvm::createPostDomOnlyPrinterWrapperPassPass();
+      (void)llvm::createPostDomPrinterWrapperPassPass();
+      (void)llvm::createPostDomOnlyViewerWrapperPassPass();
+      (void)llvm::createPostDomViewerWrapperPassPass();
+      (void) llvm::createReassociatePass();
+      (void) llvm::createRedundantDbgInstEliminationPass();
+      (void) llvm::createRegionInfoPass();
+      (void) llvm::createRegionOnlyPrinterPass();
+      (void) llvm::createRegionOnlyViewerPass();
+      (void) llvm::createRegionPrinterPass();
+      (void) llvm::createRegionViewerPass();
+      (void) llvm::createSCCPPass();
+      (void) llvm::createSafeStackPass();
+      (void) llvm::createSROAPass();
+      (void) llvm::createSingleLoopExtractorPass();
+      (void) llvm::createStripSymbolsPass();
+      (void) llvm::createStripNonDebugSymbolsPass();
+      (void) llvm::createStripDeadDebugInfoPass();
+      (void) llvm::createStripDeadPrototypesPass();
+      (void) llvm::createTailCallEliminationPass();
+      (void)llvm::createTLSVariableHoistPass();
+      (void) llvm::createJumpThreadingPass();
+      (void) llvm::createDFAJumpThreadingPass();
+      (void) llvm::createUnifyFunctionExitNodesPass();
+      (void) llvm::createInstCountPass();
+      (void) llvm::createConstantHoistingPass();
+      (void) llvm::createCodeGenPreparePass();
+      (void) llvm::createEarlyCSEPass();
+      (void) llvm::createGVNHoistPass();
+      (void) llvm::createMergedLoadStoreMotionPass();
+      (void) llvm::createGVNPass();
+      (void) llvm::createNewGVNPass();
+      (void) llvm::createMemCpyOptPass();
+      (void) llvm::createLoopDeletionPass();
+      (void) llvm::createPostDomTree();
+      (void) llvm::createInstructionNamerPass();
+      (void) llvm::createMetaRenamerPass();
+      (void) llvm::createAttributorLegacyPass();
+      (void) llvm::createAttributorCGSCCLegacyPass();
+      (void) llvm::createPostOrderFunctionAttrsLegacyPass();
+      (void) llvm::createReversePostOrderFunctionAttrsPass();
+      (void) llvm::createMergeFunctionsPass();
+      (void) llvm::createMergeICmpsLegacyPass();
+      (void) llvm::createExpandLargeDivRemPass();
+      (void) llvm::createExpandMemCmpPass();
+      (void) llvm::createExpandVectorPredicationPass();
+      std::string buf;
+      llvm::raw_string_ostream os(buf);
+      (void) llvm::createPrintModulePass(os);
+      (void) llvm::createPrintFunctionPass(os);
+      (void) llvm::createModuleDebugInfoPrinterPass();
+      (void) llvm::createPartialInliningPass();
+      (void) llvm::createLintLegacyPassPass();
+      (void) llvm::createSinkingPass();
+      (void) llvm::createLowerAtomicPass();
+      (void) llvm::createCorrelatedValuePropagationPass();
+      (void) llvm::createMemDepPrinter();
+      (void) llvm::createLoopVectorizePass();
+      (void) llvm::createSLPVectorizerPass();
+      (void) llvm::createLoadStoreVectorizerPass();
+      (void) llvm::createVectorCombinePass();
+      (void) llvm::createPartiallyInlineLibCallsPass();
+      (void) llvm::createScalarizerPass();
+      (void) llvm::createSeparateConstOffsetFromGEPPass();
+      (void) llvm::createSpeculativeExecutionPass();
+      (void) llvm::createSpeculativeExecutionIfHasBranchDivergencePass();
+      (void) llvm::createRewriteSymbolsPass();
+      (void) llvm::createStraightLineStrengthReducePass();
+      (void) llvm::createMemDerefPrinter();
+      (void) llvm::createMustExecutePrinter();
+      (void) llvm::createMustBeExecutedContextPrinter();
+      (void) llvm::createFloat2IntPass();
+      (void) llvm::createEliminateAvailableExternallyPass();
+      (void)llvm::createScalarizeMaskedMemIntrinLegacyPass();
+      (void) llvm::createWarnMissedTransformationsPass();
+      (void) llvm::createHardwareLoopsPass();
+      (void) llvm::createInjectTLIMappingsLegacyPass();
+      (void) llvm::createUnifyLoopExitsPass();
+      (void) llvm::createFixIrreduciblePass();
+      (void)llvm::createFunctionSpecializationPass();
+      (void)llvm::createSelectOptimizePass();
 
-    (void)new llvm::ScalarEvolutionWrapperPass();
-    llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)
-        ->viewCFGOnly();
-    llvm::RGPassManager RGM;
-    llvm::TargetLibraryInfoImpl TLII((llvm::Triple()));
-    llvm::TargetLibraryInfo TLI(TLII);
-    llvm::AliasAnalysis AA(TLI);
-    llvm::BatchAAResults BAA(AA);
-    llvm::AliasSetTracker X(BAA);
-    X.add(llvm::MemoryLocation()); // for -print-alias-sets
-    (void)llvm::AreStatisticsEnabled();
-    (void)llvm::sys::RunningOnValgrind();
-  }
-} ForcePassLinking; // Force link by creating a global definition.
-} // namespace
+      (void)new llvm::IntervalPartition();
+      (void)new llvm::ScalarEvolutionWrapperPass();
+      llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)->viewCFGOnly();
+      llvm::RGPassManager RGM;
+      llvm::TargetLibraryInfoImpl TLII;
+      llvm::TargetLibraryInfo TLI(TLII);
+      llvm::AliasAnalysis AA(TLI);
+      llvm::AliasSetTracker X(AA);
+      X.add(nullptr, llvm::LocationSize::beforeOrAfterPointer(),
+            llvm::AAMDNodes()); // for -print-alias-sets
+      (void) llvm::AreStatisticsEnabled();
+      (void) llvm::sys::RunningOnValgrind();
+    }
+  } ForcePassLinking; // Force link by creating a global definition.
+}
 
 #endif
diff --git a/llvm/tools/bugpoint/bugpoint.cpp b/llvm/tools/bugpoint/bugpoint.cpp
index e49efdfe7c8e0..b046e5802e0ad 100644
--- a/llvm/tools/bugpoint/bugpoint.cpp
+++ b/llvm/tools/bugpoint/bugpoint.cpp
@@ -111,7 +111,7 @@ int main(int argc, char **argv) {
   initializeInstCombine(Registry);
   initializeTarget(Registry);
 
-  if (std::getenv("bar") == (char*) -1) {
+  if (!llvm::getNonFoldableAlwaysTrue())
     InitializeAllTargets();
     InitializeAllTargetMCs();
     InitializeAllAsmPrinters();
diff --git a/polly/include/polly/LinkAllPasses.h b/polly/include/polly/LinkAllPasses.h
index a2f8f33299918..6552e1bfc6acd 100644
--- a/polly/include/polly/LinkAllPasses.h
+++ b/polly/include/polly/LinkAllPasses.h
@@ -76,7 +76,7 @@ struct PollyForcePassLinking {
     // 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.
-    if (std::getenv("bar") != (char *)-1)
+    if (llvm::getNonFoldableAlwaysTrue())
       return;
 
     polly::createCodePreparationPass();



More information about the llvm-commits mailing list