[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 02:10:16 PST 2023


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

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.

>From af82000b8fcfff2dda63235edc77ece44d4fec01 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.
---
 llvm/utils/UpdateTestChecks/common.py | 5 +++++
 1 file changed, 5 insertions(+)

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