[llvm] [UTC] Escape multiple {{ or }} in input for check lines. (PR #71790)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 07:01:56 PST 2023


https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/71790

>From 2e3bf91a8f117744fe7e01d54aa2084c212f81a2 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Thu, 9 Nov 2023 10:03:13 +0000
Subject: [PATCH] [UTC] Escape multiple {{ or }} in input for check lines.

SCEV expressions may contain multiple {{ or }} in the debug output,
which needs escaping.

See llvm/test/Analysis/LoopAccessAnalysis/loops-with-indirect-reads-and-writes.ll
for a test that needs escaping.
---
 .../Inputs/loop-access-analysis.ll.expected                  | 2 +-
 llvm/utils/UpdateTestChecks/common.py                        | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/loop-access-analysis.ll.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/loop-access-analysis.ll.expected
index 113f03d091b1b25..ac032990d8c2d86 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/loop-access-analysis.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/loop-access-analysis.ll.expected
@@ -81,7 +81,7 @@ define void @test_brace_escapes(ptr noundef %arr) {
 ; CHECK-NEXT:      Grouped accesses:
 ; CHECK-NEXT:        Group [[GRP4]]:
 ; CHECK-NEXT:          (Low: {(64 + %arr),+,64}<%loop.1> High: {(8064 + %arr),+,64}<%loop.1>)
-; CHECK-NEXT:            Member: {{(64 + %arr),+,64}<%loop.1>,+,8}<%loop.2>
+; CHECK-NEXT:            Member: {{\{{}}(64 + %arr),+,64}<%loop.1>,+,8}<%loop.2>
 ; CHECK-NEXT:        Group [[GRP5]]:
 ; CHECK-NEXT:          (Low: %arr High: (8000 + %arr))
 ; CHECK-NEXT:            Member: {%arr,+,8}<nuw><%loop.2>
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 74044f925aadde4..e8d8d99257e81d0 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1171,6 +1171,7 @@ def transform_line_vars(match):
         return match.group(1) + rv + match.group(match.lastindex)
 
     lines_with_def = []
+    multiple_braces_re = re.compile(r"(({{+)|(}}+))")
 
     for i, line in enumerate(lines):
         if not is_asm and not is_analyze:
@@ -1200,6 +1201,10 @@ def transform_line_vars(match):
                 (lines[i], changed) = nameless_value_regex.subn(
                     transform_line_vars, lines[i], count=1
                 )
+        if is_analyze:
+            # Escape multiple {{ or }} as {{}} denotes a FileCheck regex.
+            scrubbed_line = multiple_braces_re.sub(r"{{\\\1}}", lines[i])
+            lines[i] = scrubbed_line
     return lines
 
 



More information about the llvm-commits mailing list