[libcxx-commits] [libcxx] [libcxx][test] Fingerprint the compiler when memoizing results (PR #208311)

Jon Roelofs via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 11 09:25:15 PDT 2026


https://github.com/jroelofs updated https://github.com/llvm/llvm-project/pull/208311

>From cf2f5d2b9402ae14c6a9764f4e26f8e179c09758 Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Wed, 8 Jul 2026 13:06:09 -0700
Subject: [PATCH] [libcxx][test] Fingerprint the compiler when memoizing
 results

This fixes a cache invalidation problem with flag support checks when rebasing &
re-building the just-built clang.
---
 libcxx/utils/libcxx/test/dsl.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index ec2e3a2b0b165..c7db35fd629b6 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -32,6 +32,21 @@ class ConfigurationRuntimeError(ConfigurationError):
     pass
 
 
+def _compilerFingerprint(config):
+    """
+    Returns an opaque value that changes whenever the compiler being tested is
+    rebuilt, even if it keeps the same path.
+    """
+    try:
+        cxx = _getSubstitution("%{cxx}", config.substitutions)
+        path = shutil.which(cxx) or cxx
+        path = os.path.realpath(path)
+        st = os.stat(path)
+        return (path, st.st_mtime_ns, st.st_size)
+    except OSError:
+        return None
+
+
 def _memoizeExpensiveOperation(extractCacheKey):
     """
     Allows memoizing a very expensive operation.
@@ -62,7 +77,12 @@ def f(config, *args, **kwargs):
                 with open(persistentCache, "rb") as cacheFile:
                     cache = pickle.load(cacheFile)
 
-            cacheKey = pickle.dumps(extractCacheKey(config, *args, **kwargs))
+            # Mix in the compiler fingerprint so that rebuilding clang
+            # in-place invalidates any cached verdicts obtained against the
+            # previous build, instead of silently reusing them.
+            cacheKey = pickle.dumps(
+                (_compilerFingerprint(config), extractCacheKey(config, *args, **kwargs))
+            )
             if cacheKey not in cache:
                 cache[cacheKey] = function(config, *args, **kwargs)
                 # Update the persistent cache so it knows about the new key



More information about the libcxx-commits mailing list