Author: Andy Kaylor
Date: 2026-11-12T09:50:56-08:00
New Revision: 2c7c89d94b4598b1daddecbf0c4c451ce72c3bf4

URL: 
https://github.com/llvm/llvm-project/commit/2c7c89d94b4598b1daddecbf0c4c451ce72c3bf4
DIFF: 
https://github.com/llvm/llvm-project/commit/2c7c89d94b4598b1daddecbf0c4c451ce72c3bf4.diff

LOG: [CIR] Add CIR unit tests to check-clang-cir (#238102)

This change updates the CMake handling of the check-clang-cir and adds
lit config files to include CIR unit tests with the check-clang-cir
build target. This will ensure that these tests are run as part of the
mlir CI testing, which uses on check-clang-cir and not the full
check-clang target.

Assisted-by: Cursor / Grok 4.7

Added: 
    clang/test/Unit/CIR/lit.cfg.py
    clang/test/Unit/CIR/lit.site.cfg.py.in

Modified: 
    clang/test/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 3cbc8354900fa..f829570fce375 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -235,24 +235,42 @@ configure_file(AST/gen_ast_dump_json_test.py
 add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
 set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang/Tests")
 
-add_lit_testsuite(check-clang "Running the Clang regression tests"
+add_lit_testsuite(check-clang "Running the Clang regression and unit tests"
   ${CMAKE_CURRENT_BINARY_DIR}
   #LIT ${LLVM_LIT}
   DEPENDS ${CLANG_TEST_DEPS}
   ARGS ${CLANG_TEST_EXTRA_ARGS}
   )
 
-# Skip CIR here. check-clang above still discovers these tests, but they do
-# nothing unless CIR is enabled. When CIR is enabled, the check-clang-cir
-# targets below depend only on the tools those tests invoke and the tools
-# required to load clang/test/lit.cfg.py.
+# Skip CIR and Unit/CIR so that check-clang-cir and check-clang-cir-unit can
+# be independently added as build targets with a subset of dependencies. This
+# allows CIR testing to be run, for example, as part of MLIR CI testing without
+# building the complete set of dependencies needed by check-clang.
+#
+# check-clang still discovers the CIR regression tests, and the Clang-Unit 
suite
+# runs CIRUnitTests with the other unit tests. check-clang-cir runs both, and
+# its dependencies are limited to the tools those tests invoke.
 add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
   DEPENDS ${CLANG_TEST_DEPS}
   FOLDER "Clang tests/Suites"
-  SKIP "^CIR"
+  SKIP "^CIR" "^Unit/CIR"
 )
 
 if(CLANG_ENABLE_CIR)
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/CIR/lit.site.cfg.py.in
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit/CIR/lit.site.cfg.py
+    MAIN_CONFIG
+    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/CIR/lit.cfg.py
+    PATHS
+    "LLVM_SOURCE_DIR"
+    "LLVM_BINARY_DIR"
+    "LLVM_TOOLS_DIR"
+    "LLVM_LIBS_DIR"
+    "CLANG_BINARY_DIR"
+    "SHLIBDIR"
+    )
+
   # These tools are resolved while loading clang/test/lit.cfg.py, or invoked
   # directly by tests under clang/test/CIR.
   set(CLANG_CIR_TEST_DEPS
@@ -277,7 +295,8 @@ if(CLANG_ENABLE_CIR)
 
   add_lit_target(check-clang-cir "Running the CIR regression tests"
     ${CMAKE_CURRENT_SOURCE_DIR}/CIR
-    DEPENDS ${CLANG_CIR_TEST_DEPS}
+    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/CIR
+    DEPENDS ${CLANG_CIR_TEST_DEPS} CIRUnitTests
     )
   set_target_properties(check-clang-cir PROPERTIES FOLDER "Clang tests/Suites")
 

diff  --git a/clang/test/Unit/CIR/lit.cfg.py b/clang/test/Unit/CIR/lit.cfg.py
new file mode 100644
index 0000000000000..5e0cf362e526e
--- /dev/null
+++ b/clang/test/Unit/CIR/lit.cfg.py
@@ -0,0 +1,12 @@
+# -*- Python -*-
+
+import os
+
+# Load the Clang unit-test suite, then limit discovery to CIRUnitTests.
+lit_config.load_config(
+    config, os.path.join(os.path.dirname(__file__), "..", "lit.cfg.py")
+)
+
+config.name = "Clang-CIR-Unit"
+config.test_exec_root = os.path.join(config.clang_obj_root, "unittests", "CIR")
+config.test_source_root = config.test_exec_root

diff  --git a/clang/test/Unit/CIR/lit.site.cfg.py.in 
b/clang/test/Unit/CIR/lit.site.cfg.py.in
new file mode 100644
index 0000000000000..932a8354ed2d9
--- /dev/null
+++ b/clang/test/Unit/CIR/lit.site.cfg.py.in
@@ -0,0 +1,18 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+import sys
+
+config.llvm_src_root = path(r"@LLVM_SOURCE_DIR@")
+config.llvm_obj_root = path(r"@LLVM_BINARY_DIR@")
+config.llvm_tools_dir = lit_config.substitute(path(r"@LLVM_TOOLS_DIR@"))
+config.llvm_libs_dir = lit_config.substitute(path(r"@LLVM_LIBS_DIR@"))
+config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
+config.clang_obj_root = path(r"@CLANG_BINARY_DIR@")
+config.shlibdir = lit_config.substitute(path(r"@SHLIBDIR@"))
+config.target_triple = "@LLVM_TARGET_TRIPLE@"
+
+# Let the main config do the real work.
+lit_config.load_config(
+    config,
+    os.path.join(path(r"@CLANG_SOURCE_DIR@"), "test/Unit/CIR/lit.cfg.py"),
+)


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to