llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: Mattéo Rizza Murgier (matteo-rm)

<details>
<summary>Changes</summary>

Add support for lit's mid-line %if conditions, and %else.

NOTE: We don't validate syntax, or handle escaped `%`.

Fixes #<!-- -->243730 

---
Full diff: https://github.com/llvm/llvm-project/pull/244151.diff


3 Files Affected:

- (modified) clang/test/utils/update_cc_test_checks/Inputs/lit-if.c (+4-1) 
- (modified) clang/test/utils/update_cc_test_checks/Inputs/lit-if.c.expected 
(+4-1) 
- (modified) llvm/utils/UpdateTestChecks/common.py (+33-7) 


``````````diff
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c 
b/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c
index c277a98d66f028..98373570b2a8a5 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c
+++ b/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c
@@ -1,4 +1,7 @@
-// Check that the commands of a '%if' RUN line are run.
+// Check that '%if's are unconditionally unwrapped, discarding %else branches.
 // RUN: %if x86-registered-target %{ %clang_cc1 -triple 
x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s %}
+// RUN: %clang_cc1 %if x86-registered-target %{ -triple 
x86_64-unknown-linux-gnu %} -emit-llvm %s -o - | FileCheck %s
+// RUN: %if x86-registered-target %{ %clang_cc1 %if x86-registered-target %{ 
-triple x86_64-unknown-linux-gnu %} -emit-llvm %s -o - | FileCheck %s %}
+// RUN: %if x86-registered-target %{ %clang_cc1 -triple 
x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s %} %else %{ 
%clang_cc1 -emit-llvm %s -o - | FileCheck %s --check-prefix=ELSE %}
 
 void f(void) {}
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c.expected 
b/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c.expected
index 8b4eea71a5bc55..bd35dada36f154 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/lit-if.c.expected
@@ -1,6 +1,9 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// Check that the commands of a '%if' RUN line are run.
+// Check that '%if's are unconditionally unwrapped, discarding %else branches.
 // RUN: %if x86-registered-target %{ %clang_cc1 -triple 
x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s %}
+// RUN: %clang_cc1 %if x86-registered-target %{ -triple 
x86_64-unknown-linux-gnu %} -emit-llvm %s -o - | FileCheck %s
+// RUN: %if x86-registered-target %{ %clang_cc1 %if x86-registered-target %{ 
-triple x86_64-unknown-linux-gnu %} -emit-llvm %s -o - | FileCheck %s %}
+// RUN: %if x86-registered-target %{ %clang_cc1 -triple 
x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s %} %else %{ 
%clang_cc1 -emit-llvm %s -o - | FileCheck %s --check-prefix=ELSE %}
 
 // CHECK-LABEL: @f(
 // CHECK-NEXT:  entry:
diff --git a/llvm/utils/UpdateTestChecks/common.py 
b/llvm/utils/UpdateTestChecks/common.py
index ca99009f232c96..290035c68f12fb 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -507,14 +507,40 @@ def getSubstitutions(sourcepath):
     ]
 
 
+ELSE_RE = re.compile(r"\s*%else\s*%{")
+
+
+def _unwrap(line, nested):
+    """Return the unwrapped text up to the end of the scope (the end of the
+    line, or the closing '%}' if nested), and the rest of the line."""
+    result = ""
+    while line:
+        if nested and line.startswith("%}"):
+            break
+        if line.startswith("%if "):
+            line = line[line.index("%{") + 2 :]
+            branch_if, line = _unwrap(line, nested=True)
+            line = line[2:]  # Eat '%}'.
+            match = ELSE_RE.match(line)
+            if match:
+                _, line = _unwrap(line[match.end() :], nested=True)
+                line = line[2:]
+            result += branch_if
+        else:
+            # Copy text up to the next '%if ', or '%}' if nested.
+            match = re.search(r"%if |%}" if nested else r"%if ", line)
+            end = match.start() if match else len(line)
+            result += line[:end]
+            line = line[end:]
+    return result, line
+
+
 def unwrap_lit_if(run_line):
-    """Return the commands of a `%if <condition> %{ <commands> %}` RUN line, 
without
-    evaluating the condition."""
-    if "%if" in run_line:
-        match = re.search(r"%{\s*(.*?)\s*%}", run_line)
-        if match:
-            run_line = match.group(1)
-    return run_line
+    """Replace each `%if <condition> %{ <a> %} [%else %{ <b> %}]` in a RUN line
+    with <a>, without evaluating the condition."""
+    if ELSE_RE.search(run_line):
+        warn("Ignoring the %else branches of RUN line: " + run_line)
+    return _unwrap(run_line, nested=False)[0]
 
 
 def split_run_line(run_line):

``````````

</details>


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

Reply via email to