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

Luke Drummond via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 03:19:59 PDT 2025


================
@@ -0,0 +1,29 @@
+//===--- AlwaysTrue.h - Helper for oqaque truthy values        --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the getNonFoldableAlwaysTrue helper funtion
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_ALWAYS_TRUE_H
+#define LLVM_SUPPORT_ALWAYS_TRUE_H
+
+#include <cstdlib>
+
+namespace llvm {
+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 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;
----------------
ldrumm wrote:

I did, but decided to keep it as-is.
- MSVC for x86-64 doesn't support inline assembly
- getenv is already a dependency

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


More information about the llvm-commits mailing list