[Mlir-commits] [mlir] [mlir][cmake] Enable -Wundef. (PR #84011)

Ingo Müller llvmlistbot at llvm.org
Tue Mar 5 05:10:06 PST 2024


https://github.com/ingomueller-net created https://github.com/llvm/llvm-project/pull/84011

This is another follow-up of #83004, which fixed a bug due to some macros not being defined in some situations. By raising warnings on undefined macros, this kind of bug is less likely to be introduced. Similar to #83004, the fix is probably adding an include to `mlir-config.h` (and potentially defining the macro there).

>From 14ef6c5202e8e3b8c91d3525c39cf460b41d74c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ingo=20M=C3=BCller?= <ingomueller at google.com>
Date: Tue, 5 Mar 2024 13:06:28 +0000
Subject: [PATCH] [mlir][cmake] Enable -Wundef.

This is another follow-up of #83004, which fixed a bug due to some
macros not being defined in some situations. By raising warnings on
undefined macros, this kind of bug is less likely to be introduced.
Similar to #83004, the fix is probably adding an include to
`mlir-config.h` (and potentially defining the macro there).
---
 mlir/CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 070609c94a3b38..9637e9cbb0ef35 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -70,6 +70,12 @@ endif()
 check_c_compiler_flag("-Werror=implicit-function-declaration" C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION)
 append_if(C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION "-Werror=implicit-function-declaration" CMAKE_C_FLAGS)
 
+# Warn on undefined macros. This is often an indication that an include to
+# `mlir-config.h` or similar is missing.
+check_c_compiler_flag("-Wundef" C_SUPPORTS_WUNDEF)
+append_if(C_SUPPORTS_WUNDEF "-Wundef" CMAKE_C_FLAGS)
+append_if(C_SUPPORTS_WUNDEF "-Wundef" CMAKE_CXX_FLAGS)
+
 # Forbid mismatch between declaration and definition for class vs struct. This is
 # harmless on Unix systems, but it'll be a ticking bomb for MSVC/Windows systems
 # where it creeps into the ABI.



More information about the Mlir-commits mailing list