[Openmp-commits] [openmp] [OpenMP] Fix set-but-unused-var warning in omptest (PR #196069)

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Wed May 6 06:29:21 PDT 2026


https://github.com/jplehr created https://github.com/llvm/llvm-project/pull/196069

This fixes a warning in omptest about a set but unused variable. The var was intended to control whether colored logging output is created.

>From 0c4c3414cd788f6438f3a2a2fb2b583516cad81c Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Wed, 6 May 2026 07:29:44 -0500
Subject: [PATCH] [OpenMP] Fix set-but-unused-var warning in omptest

This fixes a warning in omptest about a set but unused variable. The var
was intended to control whether colored logging output is created.
---
 openmp/tools/omptest/include/EnvHelper.h | 38 ++++++++++++++++++++++++
 openmp/tools/omptest/src/Logging.cpp     |  4 +++
 openmp/tools/omptest/src/OmptTester.cpp  | 31 ++++++++-----------
 3 files changed, 54 insertions(+), 19 deletions(-)
 create mode 100644 openmp/tools/omptest/include/EnvHelper.h

diff --git a/openmp/tools/omptest/include/EnvHelper.h b/openmp/tools/omptest/include/EnvHelper.h
new file mode 100644
index 0000000000000..2f061c904ddd0
--- /dev/null
+++ b/openmp/tools/omptest/include/EnvHelper.h
@@ -0,0 +1,38 @@
+//===- EnvHelper.h - General logging class ----------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Provides environment helpers shared between a couple of places.
+///
+//===----------------------------------------------------------------------===//
+
+#include <optional>
+
+#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
+#define OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
+
+namespace omptest {
+/// Load the value of a given boolean environmental variable. Return
+/// std::nullopt if not specified in the environment.
+inline std::optional<bool>
+getBoolEnvironmentVariable(const char *VariableName) {
+  if (VariableName == nullptr)
+    return std::nullopt;
+  if (const char *EnvValue = std::getenv(VariableName)) {
+    std::string S{EnvValue};
+    for (auto &C : S)
+      C = (char)std::tolower(C);
+    if (S == "1" || S == "on" || S == "true" || S == "yes")
+      return true;
+    if (S == "0" || S == "off" || S == "false" || S == "no")
+      return false;
+  }
+  return std::nullopt;
+}
+} // namespace omptest
+#endif // OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
diff --git a/openmp/tools/omptest/src/Logging.cpp b/openmp/tools/omptest/src/Logging.cpp
index c609b6ee83aec..2132cf8c62efe 100644
--- a/openmp/tools/omptest/src/Logging.cpp
+++ b/openmp/tools/omptest/src/Logging.cpp
@@ -12,12 +12,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "Logging.h"
+#include "EnvHelper.h"
 
 using namespace omptest;
 using namespace logging;
 
 Logger::Logger(Level LogLevel, std::ostream &OutStream, bool FormatOutput)
     : LoggingLevel(LogLevel), OutStream(OutStream), FormatOutput(FormatOutput) {
+  if (auto EnvVal = getBoolEnvironmentVariable("OMPTEST_LOG_COLORED");
+      EnvVal.has_value())
+    FormatOutput = EnvVal.value();
   // Flush any buffered output
   OutStream << std::flush;
 }
diff --git a/openmp/tools/omptest/src/OmptTester.cpp b/openmp/tools/omptest/src/OmptTester.cpp
index 1a83f621173ad..601f7c6089e8d 100644
--- a/openmp/tools/omptest/src/OmptTester.cpp
+++ b/openmp/tools/omptest/src/OmptTester.cpp
@@ -15,6 +15,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "OmptTester.h"
+#include "EnvHelper.h"
 
 #include <atomic>
 #include <cassert>
@@ -49,7 +50,6 @@ static std::atomic<ompt_id_t> NextOpId{0x8000000000000001};
 static bool UseEMICallbacks = false;
 static bool UseTracing = false;
 static bool RunAsTestSuite = false;
-static bool ColoredLog = false;
 
 // OMPT entry point handles
 static ompt_set_trace_ompt_t ompt_set_trace_ompt = 0;
@@ -358,20 +358,6 @@ static void on_ompt_callback_target_map_emi(ompt_data_t *target_data,
   assert(0 && "Target map emi callback is unimplemented");
 }
 
-/// Load the value of a given boolean environmental variable.
-bool getBoolEnvironmentVariable(const char *VariableName) {
-  if (VariableName == nullptr)
-    return false;
-  if (const char *EnvValue = std::getenv(VariableName)) {
-    std::string S{EnvValue};
-    for (auto &C : S)
-      C = (char)std::tolower(C);
-    if (S == "1" || S == "on" || S == "true" || S == "yes")
-      return true;
-  }
-  return false;
-}
-
 /// Called by the OMP runtime to initialize the OMPT
 int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
                     ompt_data_t *tool_data) {
@@ -380,10 +366,17 @@ int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
   if (!ompt_set_callback)
     return 0; // failure
 
-  UseEMICallbacks = getBoolEnvironmentVariable("OMPTEST_USE_OMPT_EMI");
-  UseTracing = getBoolEnvironmentVariable("OMPTEST_USE_OMPT_TRACING");
-  RunAsTestSuite = getBoolEnvironmentVariable("OMPTEST_RUN_AS_TESTSUITE");
-  ColoredLog = getBoolEnvironmentVariable("OMPTEST_LOG_COLORED");
+  if (auto EmiCallbacksEnvVal =
+          getBoolEnvironmentVariable("OMPTEST_USE_OMPT_EMI"))
+    UseEMICallbacks = EmiCallbacksEnvVal.value();
+
+  if (auto TracingEnvVal =
+          getBoolEnvironmentVariable("OMPTEST_USE_OMPT_TRACING"))
+    UseTracing = TracingEnvVal.value();
+
+  if (auto RunAsTestSuiteEnvVal =
+          getBoolEnvironmentVariable("OMPTEST_RUN_AS_TESTSUITE"))
+    RunAsTestSuite = RunAsTestSuiteEnvVal.value();
 
   register_ompt_callback(ompt_callback_thread_begin);
   register_ompt_callback(ompt_callback_thread_end);



More information about the Openmp-commits mailing list