[libcxx-commits] [libcxx] [libc++][utils] Fix LIT `%if` substitution support (PR #209358)

Hubert Tong via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 14 07:31:09 PDT 2026


https://github.com/hubert-reinterpretcast updated https://github.com/llvm/llvm-project/pull/209358

>From a3ceea18d8a3d756c8b6ba795dcdface9552b074 Mon Sep 17 00:00:00 2001
From: Hubert Tong <hubert.reinterpretcast at gmail.com>
Date: Mon, 13 Jul 2026 22:40:37 -0400
Subject: [PATCH 1/4] [libcxx][utils] Fix `%if` substitution

---
 libcxx/utils/libcxx/test/format.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index 49cbe8a8db618..b2471cb36ed61 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -205,8 +205,9 @@ def parseScript(test, preamble):
         )
 
     # Perform substitutions in the script itself.
+    conditions = {feature: True for feature in test.config.available_features}
     script = lit.TestRunner.applySubstitutions(
-        script, substitutions, recursion_limit=test.config.recursiveExpansionLimit
+        script, substitutions, conditions, recursion_limit=test.config.recursiveExpansionLimit
     )
 
     return script

>From d6bf3d942b1f9fc328a14ee482836a3b6a6f1b9b Mon Sep 17 00:00:00 2001
From: Hubert Tong <hubert.reinterpretcast at gmail.com>
Date: Mon, 13 Jul 2026 23:11:36 -0400
Subject: [PATCH 2/4] Add LIT test

---
 libcxx/test/selftest/if-else.sh.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 libcxx/test/selftest/if-else.sh.cpp

diff --git a/libcxx/test/selftest/if-else.sh.cpp b/libcxx/test/selftest/if-else.sh.cpp
new file mode 100644
index 0000000000000..11812d949a058
--- /dev/null
+++ b/libcxx/test/selftest/if-else.sh.cpp
@@ -0,0 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure that LIT `%if` substitutions are aware of the available features.
+
+// RUN: not %if libcpp-abi-version={{[0-9]+}} %{ not %} echo "hello world"

>From 38cf7241a04f9158341830e1a878f66455fa0a9c Mon Sep 17 00:00:00 2001
From: Hubert Tong <hubert.reinterpretcast at gmail.com>
Date: Mon, 13 Jul 2026 23:36:31 -0400
Subject: [PATCH 3/4] Apply diff from `darker`

---
 libcxx/utils/libcxx/test/format.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index b2471cb36ed61..e3e81fd1cf36f 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -207,7 +207,10 @@ def parseScript(test, preamble):
     # Perform substitutions in the script itself.
     conditions = {feature: True for feature in test.config.available_features}
     script = lit.TestRunner.applySubstitutions(
-        script, substitutions, conditions, recursion_limit=test.config.recursiveExpansionLimit
+        script,
+        substitutions,
+        conditions,
+        recursion_limit=test.config.recursiveExpansionLimit,
     )
 
     return script

>From 4a06d1d145b95624356fc376b0daf7f00943cb0e Mon Sep 17 00:00:00 2001
From: Hubert Tong <hubert.reinterpretcast at gmail.com>
Date: Tue, 14 Jul 2026 10:30:59 -0400
Subject: [PATCH 4/4] Use `target={{.+}}` feature instead for the test

---
 libcxx/test/selftest/if-else.sh.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/selftest/if-else.sh.cpp b/libcxx/test/selftest/if-else.sh.cpp
index 11812d949a058..06b09ac9067a5 100644
--- a/libcxx/test/selftest/if-else.sh.cpp
+++ b/libcxx/test/selftest/if-else.sh.cpp
@@ -8,4 +8,4 @@
 
 // Make sure that LIT `%if` substitutions are aware of the available features.
 
-// RUN: not %if libcpp-abi-version={{[0-9]+}} %{ not %} echo "hello world"
+// RUN: not %if target={{.+}} %{ not %} echo "hello world"



More information about the libcxx-commits mailing list