[llvm] [orc-rt] Move ORC_RT_LOG_ENABLED out of config.h; catch typos. (PR #226751)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 26 21:38:01 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/226751
Move ORC_RT_LOG_ENABLED to orc-rt-c/support/LogLevel.h so that config.h is kept for build options only.
Switch to using function-like macros so that typos in level-names become compilation errors.
>From 1dc62125b4ca78cd757f1cc166f8a9afdf5ad375 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sun, 27 Sep 2026 13:00:34 +1000
Subject: [PATCH] [orc-rt] Move ORC_RT_LOG_ENABLED out of config.h; catch
typos.
Move ORC_RT_LOG_ENABLED to orc-rt-c/support/LogLevel.h so that config.h
is kept for build options only.
Switch to using function-like macros so that typos in level-names become
compilation errors.
---
orc-rt/include/CMakeLists.txt | 1 +
orc-rt/include/orc-rt-c/config.h.in | 32 -------------------
orc-rt/include/orc-rt-c/support/LogLevel.h | 37 ++++++++++++++++++++++
orc-rt/include/orc-rt-c/support/Logging.h | 3 +-
orc-rt/include/orc-rt/bedrock/Session.h | 1 +
5 files changed, 41 insertions(+), 33 deletions(-)
create mode 100644 orc-rt/include/orc-rt-c/support/LogLevel.h
diff --git a/orc-rt/include/CMakeLists.txt b/orc-rt/include/CMakeLists.txt
index 72069456c5e3b8..016f9b9cfc9328 100644
--- a/orc-rt/include/CMakeLists.txt
+++ b/orc-rt/include/CMakeLists.txt
@@ -8,6 +8,7 @@ set(ORC_RT_HEADERS
orc-rt-c/support/Compiler.h
orc-rt-c/support/CoreTypes.h
orc-rt-c/support/Error.h
+ orc-rt-c/support/LogLevel.h
orc-rt-c/support/Logging.h
orc-rt-c/support/WrapperFunction.h
orc-rt/bedrock/BootstrapInfo.h
diff --git a/orc-rt/include/orc-rt-c/config.h.in b/orc-rt/include/orc-rt-c/config.h.in
index 7af7b4b2bc5654..c4ff9a0fb4cd29 100644
--- a/orc-rt/include/orc-rt-c/config.h.in
+++ b/orc-rt/include/orc-rt-c/config.h.in
@@ -38,36 +38,4 @@
#endif
#define ORC_RT_LOG_BACKEND @ORC_RT_LOG_BACKEND_VALUE@
-/*
- * ORC_RT_LOG_ENABLED(Level) is true (1) if log sites at the given level are
- * compiled in, and false (0) if they're compiled out, either because the
- * backend is none or because the level is below the ORC_RT_LOG_LEVEL floor. It
- * takes the same level token as ORC_RT_LOG (see orc-rt-c/support/Logging.h),
- * and can be used in preprocessor conditionals:
- *
- * #if ORC_RT_LOG_ENABLED(Error)
- * ...
- * #endif
- *
- * It's defined here, rather than in Logging.h, so that it can be used without
- * pulling in the logging backend's headers (e.g. <os/log.h>).
- *
- * Code that relies on logging to surface something important (e.g. an error
- * reporter that logs) can use this to pick an alternative when logging is
- * compiled out. Note that a compiled-in level may still be suppressed at
- * runtime (e.g. by the printf backend's runtime threshold).
- *
- * The ORC_RT_LOG_LEVEL_VALUE_<Level> aliases map ORC_RT_LOG's level tokens to
- * the ORC_RT_LOG_LEVEL_<LEVEL> values above. An unrecognized level token
- * pastes to an undefined identifier, which evaluates to 0 in #if.
- */
-#define ORC_RT_LOG_LEVEL_VALUE_Debug ORC_RT_LOG_LEVEL_DEBUG
-#define ORC_RT_LOG_LEVEL_VALUE_Info ORC_RT_LOG_LEVEL_INFO
-#define ORC_RT_LOG_LEVEL_VALUE_Warning ORC_RT_LOG_LEVEL_WARNING
-#define ORC_RT_LOG_LEVEL_VALUE_Error ORC_RT_LOG_LEVEL_ERROR
-
-#define ORC_RT_LOG_ENABLED(Level) \
- (ORC_RT_LOG_BACKEND != ORC_RT_LOG_BACKEND_NONE && \
- ORC_RT_LOG_LEVEL_VALUE_##Level >= ORC_RT_LOG_LEVEL)
-
#endif /* ORC_RT_C_CONFIG_H */
diff --git a/orc-rt/include/orc-rt-c/support/LogLevel.h b/orc-rt/include/orc-rt-c/support/LogLevel.h
new file mode 100644
index 00000000000000..d88c74019973c9
--- /dev/null
+++ b/orc-rt/include/orc-rt-c/support/LogLevel.h
@@ -0,0 +1,37 @@
+/*===------ LogLevel.h - ORC Runtime compiled-in log levels -------*- 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 *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* ORC_RT_LOG_ENABLED, kept apart from Logging.h so that it can be used *|
+|* without pulling in the logging backend's headers (e.g. <os/log.h>). *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef ORC_RT_C_SUPPORT_LOGLEVEL_H
+#define ORC_RT_C_SUPPORT_LOGLEVEL_H
+
+#include "orc-rt-c/config.h"
+
+/**
+ * ORC_RT_LOG_ENABLED(Level) is 1 if log sites at Level (Error, Warning, Info or
+ * Debug, as for ORC_RT_LOG) are compiled in, and 0 otherwise. Usable in #if.
+ */
+#define ORC_RT_LOG_ENABLED(Level) \
+ (ORC_RT_LOG_BACKEND != ORC_RT_LOG_BACKEND_NONE && \
+ ORC_RT_LOG_ENABLED_##Level() >= ORC_RT_LOG_LEVEL)
+
+/*
+ * Per-level macros are function-like so that a mistyped level is a hard error
+ * rather than silently evaluating to 0.
+ */
+#define ORC_RT_LOG_ENABLED_Debug() ORC_RT_LOG_LEVEL_DEBUG
+#define ORC_RT_LOG_ENABLED_Info() ORC_RT_LOG_LEVEL_INFO
+#define ORC_RT_LOG_ENABLED_Warning() ORC_RT_LOG_LEVEL_WARNING
+#define ORC_RT_LOG_ENABLED_Error() ORC_RT_LOG_LEVEL_ERROR
+
+#endif /* ORC_RT_C_SUPPORT_LOGLEVEL_H */
diff --git a/orc-rt/include/orc-rt-c/support/Logging.h b/orc-rt/include/orc-rt-c/support/Logging.h
index 9b7413766b3303..a10ad8449eb89a 100644
--- a/orc-rt/include/orc-rt-c/support/Logging.h
+++ b/orc-rt/include/orc-rt-c/support/Logging.h
@@ -43,6 +43,7 @@
#include "orc-rt-c/config.h"
#include "orc-rt-c/support/Compiler.h"
+#include "orc-rt-c/support/LogLevel.h"
#if ORC_RT_LOG_BACKEND == ORC_RT_LOG_BACKEND_OS_LOG
#include <os/log.h>
@@ -136,7 +137,7 @@ int orc_rt_log_formatCheck(const char *Fmt, ...) ORC_RT_FORMAT_PRINTF(1, 2);
/*
* To check whether a level is compiled in, use ORC_RT_LOG_ENABLED(Level),
- * defined in orc-rt-c/config.h.
+ * defined in orc-rt-c/support/LogLevel.h.
*/
/**
diff --git a/orc-rt/include/orc-rt/bedrock/Session.h b/orc-rt/include/orc-rt/bedrock/Session.h
index 49542ca14df3c1..fbcd2da13f90e8 100644
--- a/orc-rt/include/orc-rt/bedrock/Session.h
+++ b/orc-rt/include/orc-rt/bedrock/Session.h
@@ -25,6 +25,7 @@
#include "orc-rt-c/config.h"
#include "orc-rt-c/support/CoreTypes.h"
+#include "orc-rt-c/support/LogLevel.h"
#include "orc-rt-c/support/WrapperFunction.h"
#include <cassert>
More information about the llvm-commits
mailing list