[llvm] [Test][CAS] Fix PluginCASTest DLL discovery on Windows multi-config generators (PR #215099)

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 14:03:54 PDT 2026


https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/215099

>From 2ce43a4019e573c1413522b9bc982125e05b136c Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 8 Aug 2026 21:32:15 +0200
Subject: [PATCH 1/2] [Test][CAS] Fix PluginCASTest DLL discovery on Windows
 multi-config generators

The test was computing the plugin path by walking up 3 directory levels
from the test executable to reach the build root, then appending
bin/CASPluginTest.dll. This fails on MSVC multi-config builds where an
extra Release/ subdirectory exists. Place the plugin library next to
the test executable instead, matching the pattern used by the Passes
plugin tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply at anthropic.com>
---
 llvm/unittests/CAS/CASTestConfig.cpp | 9 +++------
 llvm/unittests/CAS/CMakeLists.txt    | 7 +++++++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/llvm/unittests/CAS/CASTestConfig.cpp b/llvm/unittests/CAS/CASTestConfig.cpp
index 742da02ae7e13..7a948028dc207 100644
--- a/llvm/unittests/CAS/CASTestConfig.cpp
+++ b/llvm/unittests/CAS/CASTestConfig.cpp
@@ -30,14 +30,11 @@ static std::string TestStringArg1("castest-string-arg1");
 std::string unittest::cas::getCASPluginPath() {
   std::string Executable =
       sys::fs::getMainExecutable(TestMainArgv0, &TestStringArg1);
-  llvm::SmallString<256> PathBuf(sys::path::parent_path(
-      sys::path::parent_path(sys::path::parent_path(Executable))));
+  llvm::SmallString<256> PathBuf(sys::path::parent_path(Executable));
 #ifndef _WIN32
-  std::string LibName = "libCASPluginTest";
-  sys::path::append(PathBuf, "lib", LibName + LLVM_PLUGIN_EXT);
+  sys::path::append(PathBuf, "libCASPluginTest" LLVM_PLUGIN_EXT);
 #else
-  std::string LibName = "CASPluginTest";
-  sys::path::append(PathBuf, "bin", LibName + LLVM_PLUGIN_EXT);
+  sys::path::append(PathBuf, "CASPluginTest" LLVM_PLUGIN_EXT);
 #endif
   return std::string(PathBuf);
 }
diff --git a/llvm/unittests/CAS/CMakeLists.txt b/llvm/unittests/CAS/CMakeLists.txt
index 7f8b57ac3953a..9053233b86a65 100644
--- a/llvm/unittests/CAS/CMakeLists.txt
+++ b/llvm/unittests/CAS/CMakeLists.txt
@@ -38,5 +38,12 @@ add_llvm_unittest(CASTests
 target_link_libraries(CASTests PRIVATE LLVMTestingSupport)
 
 if (LLVM_ENABLE_ONDISK_CAS)
+  # Place the plugin library next to the test executable so getCASPluginPath()
+  # can locate it with a single parent_path regardless of the generator type.
+  set(CAS_UNITTEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
+  set_output_directory(CASPluginTest
+      BINARY_DIR ${CAS_UNITTEST_DIR}
+      LIBRARY_DIR ${CAS_UNITTEST_DIR}
+  )
   add_dependencies(CASTests CASPluginTest)
 endif()

>From 05cd0ccbf541896267ff7a76d546350b1e90f8df Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Mon, 10 Aug 2026 16:40:17 -0400
Subject: [PATCH 2/2] Update llvm/unittests/CAS/CASTestConfig.cpp

---
 llvm/unittests/CAS/CASTestConfig.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/unittests/CAS/CASTestConfig.cpp b/llvm/unittests/CAS/CASTestConfig.cpp
index 7a948028dc207..ed4229eb1b779 100644
--- a/llvm/unittests/CAS/CASTestConfig.cpp
+++ b/llvm/unittests/CAS/CASTestConfig.cpp
@@ -31,7 +31,7 @@ std::string unittest::cas::getCASPluginPath() {
   std::string Executable =
       sys::fs::getMainExecutable(TestMainArgv0, &TestStringArg1);
   llvm::SmallString<256> PathBuf(sys::path::parent_path(Executable));
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__MINGW32__)
   sys::path::append(PathBuf, "libCASPluginTest" LLVM_PLUGIN_EXT);
 #else
   sys::path::append(PathBuf, "CASPluginTest" LLVM_PLUGIN_EXT);



More information about the llvm-commits mailing list