[llvm] 3278948 - Fix `sed -e s at FOO@%/S@` and similar when there's @'s in the working directory

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 15:44:14 PST 2019


Author: Daniel Sanders
Date: 2019-12-03T15:44:01-08:00
New Revision: 327894859cc41c1730807f8a179aa880203262f5

URL: https://github.com/llvm/llvm-project/commit/327894859cc41c1730807f8a179aa880203262f5
DIFF: https://github.com/llvm/llvm-project/commit/327894859cc41c1730807f8a179aa880203262f5.diff

LOG: Fix `sed -e s at FOO@%/S@` and similar when there's @'s in the working directory

Jenkins sometimes starts a new working directory by appending @2 (or
incrementing the number if the @n suffix is already there). This causes
several clang tests to fail as:
  s at INPUT_DIR@%/S/Inputs at g
gets expanded to the invalid:
  s at INPUT_DIR@/path/to/workdir at 2/Inputs at g
                               ~~~~~~~~~~
where the part marked with ~'s is interpreted as the flags. These are
invalid and the test fails.

Previous fixes simply exchanged the @ character for another like | but
that's just moving the problem. Address it by adding an expansion that
escapes the @ character we're using as a delimiter as well as other magic
characters in the replacement of sed's s@@@.

There's still room for expansions to cause trouble though. One I ran into
while testing this was that having a directory called foo at bar causes lots
of `CHECK-NOT: foo` directives to match. There's also things like
directories containing `\1`

Added: 
    

Modified: 
    clang/test/Index/index-module-with-vfs.m
    clang/test/Modules/crash-vfs-ivfsoverlay.m
    clang/test/Modules/double-quotes.m
    clang/test/Modules/framework-public-includes-private.m
    clang/test/VFS/external-names.c
    clang/test/VFS/framework-import.m
    clang/test/VFS/implicit-include.c
    clang/test/VFS/include-mixed-real-and-virtual.c
    clang/test/VFS/include-real-from-virtual.c
    clang/test/VFS/include-virtual-from-real.c
    clang/test/VFS/include.c
    clang/test/VFS/incomplete-umbrella.m
    clang/test/VFS/module-import.m
    clang/test/VFS/module_missing_vfs.m
    clang/test/VFS/real-path-found-first.m
    clang/test/VFS/relative-path.c
    clang/test/VFS/test_nonmodular.c
    clang/test/VFS/umbrella-framework-import-skipnonexist.m
    clang/test/VFS/vfsroot-include.c
    clang/test/VFS/vfsroot-module.m
    clang/test/VFS/vfsroot-with-overlay.c
    llvm/utils/lit/lit/TestRunner.py

Removed: 
    


################################################################################
diff  --git a/clang/test/Index/index-module-with-vfs.m b/clang/test/Index/index-module-with-vfs.m
index 46fa68dfa130..06944d372d49 100644
--- a/clang/test/Index/index-module-with-vfs.m
+++ b/clang/test/Index/index-module-with-vfs.m
@@ -6,7 +6,7 @@ void foo() {
 }
 
 // RUN: rm -rf %t.cache
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: c-index-test -index-file %s -fmodules-cache-path=%t.cache -fmodules -F %t -I %t \
 // RUN:              -ivfsoverlay %t.yaml -Xclang -fdisable-module-hash | FileCheck %s
 

diff  --git a/clang/test/Modules/crash-vfs-ivfsoverlay.m b/clang/test/Modules/crash-vfs-ivfsoverlay.m
index 00992aa19fad..d2d2ccbd2546 100644
--- a/clang/test/Modules/crash-vfs-ivfsoverlay.m
+++ b/clang/test/Modules/crash-vfs-ivfsoverlay.m
@@ -3,7 +3,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/m
 // RUN: cp %S/../VFS/Inputs/actual_module2.map %t/actual_module2.map
-// RUN: sed -e "s at INPUT_DIR@%/t at g" -e "s at OUT_DIR@%/t/example at g" \
+// RUN: sed -e "s at INPUT_DIR@%{/t:regex_replacement}@g" -e "s at OUT_DIR@%{/t:regex_replacement}/example at g" \
 // RUN:   %S/../VFS/Inputs/vfsoverlay2.yaml > %t/srcvfs.yaml
 
 // RUN: env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \

diff  --git a/clang/test/Modules/double-quotes.m b/clang/test/Modules/double-quotes.m
index 4ce712ccc6c5..99187fc26654 100644
--- a/clang/test/Modules/double-quotes.m
+++ b/clang/test/Modules/double-quotes.m
@@ -4,7 +4,7 @@
 // RUN: %hmaptool write %S/Inputs/double-quotes/a.hmap.json %t/a.hmap
 // RUN: %hmaptool write %S/Inputs/double-quotes/x.hmap.json %t/x.hmap
 
-// RUN: sed -e "s at TEST_DIR@%/S/Inputs/double-quotes at g" \
+// RUN: sed -e "s at TEST_DIR@%{/S:regex_replacement}/Inputs/double-quotes at g" \
 // RUN:   %S/Inputs/double-quotes/z.yaml > %t/z.yaml
 
 // The output with and without modules should be the same

diff  --git a/clang/test/Modules/framework-public-includes-private.m b/clang/test/Modules/framework-public-includes-private.m
index 0f1e3a242a15..37c43e9a6390 100644
--- a/clang/test/Modules/framework-public-includes-private.m
+++ b/clang/test/Modules/framework-public-includes-private.m
@@ -4,7 +4,7 @@
 // RUN: %hmaptool write %S/Inputs/framework-public-includes-private/a.hmap.json %t/a.hmap
 // RUN: %hmaptool write %S/Inputs/framework-public-includes-private/z.hmap.json %t/z.hmap
 
-// RUN: sed -e "s at TEST_DIR@%/S/Inputs/framework-public-includes-private at g" \
+// RUN: sed -e "s at TEST_DIR@%{/S:regex_replacement}/Inputs/framework-public-includes-private at g" \
 // RUN:   %S/Inputs/framework-public-includes-private/z.yaml > %t/z.yaml
 
 // The output with and without modules should be the same, without modules first.

diff  --git a/clang/test/VFS/external-names.c b/clang/test/VFS/external-names.c
index 1e12c930c35e..0500611c3e40 100644
--- a/clang/test/VFS/external-names.c
+++ b/clang/test/VFS/external-names.c
@@ -1,5 +1,5 @@
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" -e "s at EXTERNAL_NAMES@true@" %S/Inputs/use-external-names.yaml > %t.external.yaml
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" -e "s at EXTERNAL_NAMES@false@" %S/Inputs/use-external-names.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" -e "s at EXTERNAL_NAMES@true@" %S/Inputs/use-external-names.yaml > %t.external.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" -e "s at EXTERNAL_NAMES@false@" %S/Inputs/use-external-names.yaml > %t.yaml
 
 #include "external-names.h"
 #ifdef REINCLUDE

diff  --git a/clang/test/VFS/framework-import.m b/clang/test/VFS/framework-import.m
index 858f1f57fbd1..cd923c1dbe0f 100644
--- a/clang/test/VFS/framework-import.m
+++ b/clang/test/VFS/framework-import.m
@@ -1,4 +1,4 @@
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -F %t -ivfsoverlay %t.yaml -fsyntax-only %s
 
 #import <SomeFramework/public_header.h>

diff  --git a/clang/test/VFS/implicit-include.c b/clang/test/VFS/implicit-include.c
index 654e0a87de0e..06bff4b962db 100644
--- a/clang/test/VFS/implicit-include.c
+++ b/clang/test/VFS/implicit-include.c
@@ -1,4 +1,4 @@
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -include "not_real.h" -fsyntax-only %s
 
 void foo() {

diff  --git a/clang/test/VFS/include-mixed-real-and-virtual.c b/clang/test/VFS/include-mixed-real-and-virtual.c
index e4297c5737d9..b46ee9af9990 100644
--- a/clang/test/VFS/include-mixed-real-and-virtual.c
+++ b/clang/test/VFS/include-mixed-real-and-virtual.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
 // RUN: echo "void baz(void);" > %t/real.h
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
 
 #include "not_real.h"

diff  --git a/clang/test/VFS/include-real-from-virtual.c b/clang/test/VFS/include-real-from-virtual.c
index 3a41c4ea2c76..7398be735c5f 100644
--- a/clang/test/VFS/include-real-from-virtual.c
+++ b/clang/test/VFS/include-real-from-virtual.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
 // RUN: echo "void baz(void);" > %t/real.h
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
 
 #include "include_real.h"

diff  --git a/clang/test/VFS/include-virtual-from-real.c b/clang/test/VFS/include-virtual-from-real.c
index 0b0d4cd0025a..b50d5b729253 100644
--- a/clang/test/VFS/include-virtual-from-real.c
+++ b/clang/test/VFS/include-virtual-from-real.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
 // RUN: echo '#include "not_real.h"' > %t/include_not_real.h
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
 
 #include "include_not_real.h"

diff  --git a/clang/test/VFS/include.c b/clang/test/VFS/include.c
index 16a1bca71a72..a55e73a38178 100644
--- a/clang/test/VFS/include.c
+++ b/clang/test/VFS/include.c
@@ -1,4 +1,4 @@
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -I %t -ivfsoverlay %t.yaml -fsyntax-only %s
 
 #include "not_real.h"

diff  --git a/clang/test/VFS/incomplete-umbrella.m b/clang/test/VFS/incomplete-umbrella.m
index 5b2a1e0b4e1b..196313927bc0 100644
--- a/clang/test/VFS/incomplete-umbrella.m
+++ b/clang/test/VFS/incomplete-umbrella.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/Incomplete.framework/Headers
 // RUN: echo '// IncompleteReal.h' > %t/Incomplete.framework/Headers/IncompleteReal.h
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: not %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
 // RUN:     -ivfsoverlay %t.yaml -F %t -fsyntax-only %s 2>&1 | FileCheck %s
 

diff  --git a/clang/test/VFS/module-import.m b/clang/test/VFS/module-import.m
index 336a72d31cfa..25d37bbf0a77 100644
--- a/clang/test/VFS/module-import.m
+++ b/clang/test/VFS/module-import.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
 
 @import not_real;
@@ -16,7 +16,7 @@ void foo() {
 #endif
 
 // Override the module map (vfsoverlay2 on top)
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay2.yaml > %t2.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay2.yaml > %t2.yaml
 // RUN: %clang_cc1 -Werror -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ivfsoverlay %t.yaml -ivfsoverlay %t2.yaml -I %t -fsyntax-only %s
 
 // vfsoverlay2 not present

diff  --git a/clang/test/VFS/module_missing_vfs.m b/clang/test/VFS/module_missing_vfs.m
index 6285ac064927..3cd8fc2c9eed 100644
--- a/clang/test/VFS/module_missing_vfs.m
+++ b/clang/test/VFS/module_missing_vfs.m
@@ -5,7 +5,7 @@
 // ERROR: virtual filesystem overlay file '{{.*}}' not found
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/MissingVFS/vfsoverlay.yaml > %t/vfs.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/MissingVFS/vfsoverlay.yaml > %t/vfs.yaml
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 

diff  --git a/clang/test/VFS/real-path-found-first.m b/clang/test/VFS/real-path-found-first.m
index 8d7d21bf7832..0d9a6de589fd 100644
--- a/clang/test/VFS/real-path-found-first.m
+++ b/clang/test/VFS/real-path-found-first.m
@@ -7,7 +7,7 @@
 // RUN: rm -rf %t %t-cache %t.pch
 // RUN: mkdir -p %t/SomeFramework.framework/Modules
 // RUN: cat %S/Inputs/some_frame_module.map > %t/SomeFramework.framework/Modules/module.modulemap
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 
 // Build
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t-cache -F %t \

diff  --git a/clang/test/VFS/relative-path.c b/clang/test/VFS/relative-path.c
index fc4ae151d87f..24313affc69d 100644
--- a/clang/test/VFS/relative-path.c
+++ b/clang/test/VFS/relative-path.c
@@ -1,6 +1,6 @@
 // RUN: mkdir -p %t
 // RUN: cd %t
-// RUN: sed -e "s at INPUT_DIR@%/S/Inputs at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: sed -e "s at INPUT_DIR@%{/S:regex_replacement}/Inputs at g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsoverlay.yaml > %t.yaml
 // RUN: %clang_cc1 -Werror -I . -ivfsoverlay %t.yaml -fsyntax-only %s
 
 #include "not_real.h"

diff  --git a/clang/test/VFS/test_nonmodular.c b/clang/test/VFS/test_nonmodular.c
index dbc1f622f203..faec0e3a5162 100644
--- a/clang/test/VFS/test_nonmodular.c
+++ b/clang/test/VFS/test_nonmodular.c
@@ -3,7 +3,7 @@
 // We can't have module.map inside Inputs/Nonmodular.
 // RUN: cp %S/Inputs/Nonmodular/Nonmodular.modulemap %t/outdir/module.modulemap
 //
-// RUN: sed -e "s at VDIR@%/t/vdir at g" -e "s at IN_DIR@%/S at g" -e "s at OUT_DIR@%/t/outdir at g" %S/Inputs/Nonmodular/nonmodular-headers.yaml > %t/vdir/nonmodular-headers.yaml
+// RUN: sed -e "s at VDIR@%{/t:regex_replacement}/vdir at g" -e "s at IN_DIR@%{/S:regex_replacement}@g" -e "s at OUT_DIR@%{/t:regex_replacement}/outdir at g" %S/Inputs/Nonmodular/nonmodular-headers.yaml > %t/vdir/nonmodular-headers.yaml
 // RUN: %clang_cc1 -fmodule-name=Nonmodular -fmodules -Wnon-modular-include-in-framework-module -verify -fimplicit-module-maps -fmodules-cache-path=%t/cache -ivfsoverlay %t/vdir/nonmodular-headers.yaml -I %S/Inputs -F %t/vdir -fsyntax-only %S/Inputs/Nonmodular/test.c
 
 // expected-no-diagnostics

diff  --git a/clang/test/VFS/umbrella-framework-import-skipnonexist.m b/clang/test/VFS/umbrella-framework-import-skipnonexist.m
index 6f536b40a911..a778e26af162 100644
--- a/clang/test/VFS/umbrella-framework-import-skipnonexist.m
+++ b/clang/test/VFS/umbrella-framework-import-skipnonexist.m
@@ -4,7 +4,7 @@
 // RUN: mkdir -p %t/vdir %t/outdir %t/cache
 // RUN: cp -R %S/Inputs/Bar.framework %t/outdir/
 //
-// RUN: sed -e "s at VDIR@%/t/vdir at g" -e "s at OUT_DIR@%/t/outdir at g" %S/Inputs/bar-headers.yaml > %t/vdir/bar-headers.yaml
+// RUN: sed -e "s at VDIR@%{/t:regex_replacement}/vdir at g" -e "s at OUT_DIR@%{/t:regex_replacement}/outdir at g" %S/Inputs/bar-headers.yaml > %t/vdir/bar-headers.yaml
 // RUN: rm -f %t/outdir/Bar.framework/Headers/B.h
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -ivfsoverlay %t/vdir/bar-headers.yaml -F %t/vdir -fsyntax-only %s
 

diff  --git a/clang/test/VFS/vfsroot-include.c b/clang/test/VFS/vfsroot-include.c
index 2f3ff78bd6e9..2564004ea4b1 100644
--- a/clang/test/VFS/vfsroot-include.c
+++ b/clang/test/VFS/vfsroot-include.c
@@ -3,7 +3,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
-// RUN: sed -e "s at TEST_DIR@%/S at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsroot.yaml > %t.yaml
+// RUN: sed -e "s at TEST_DIR@%{/S:regex_replacement}@g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsroot.yaml > %t.yaml
 // RUN: not %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %S/Inputs -I /direct-vfs-root-files -fsyntax-only /tests/vfsroot-include.c 2>&1 | FileCheck %s
 // The line above tests that the compiler input file is looked up through VFS.
 

diff  --git a/clang/test/VFS/vfsroot-module.m b/clang/test/VFS/vfsroot-module.m
index 979c5c281977..3ad3e19d4b37 100644
--- a/clang/test/VFS/vfsroot-module.m
+++ b/clang/test/VFS/vfsroot-module.m
@@ -3,7 +3,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
-// RUN: sed -e "s at TEST_DIR@%/S at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsroot.yaml > %t.yaml
+// RUN: sed -e "s at TEST_DIR@%{/S:regex_replacement}@g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsroot.yaml > %t.yaml
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t/cache -ivfsoverlay %t.yaml -F %S/Inputs -fsyntax-only /tests/vfsroot-module.m
 
 // Test that a file missing from the VFS root is not found, even if it is

diff  --git a/clang/test/VFS/vfsroot-with-overlay.c b/clang/test/VFS/vfsroot-with-overlay.c
index 04a275ed1580..4a2c64cb8734 100644
--- a/clang/test/VFS/vfsroot-with-overlay.c
+++ b/clang/test/VFS/vfsroot-with-overlay.c
@@ -3,7 +3,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
-// RUN: sed -e "s at TEST_DIR@%/S at g" -e "s at OUT_DIR@%/t at g" %S/Inputs/vfsroot.yaml > %t.yaml
+// RUN: sed -e "s at TEST_DIR@%{/S:regex_replacement}@g" -e "s at OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/vfsroot.yaml > %t.yaml
 // RUN: sed -e "s at INPUT_DIR@/indirect-vfs-root-files at g" -e "s at OUT_DIR@/overlay-dir at g" %S/Inputs/vfsoverlay.yaml > %t/vfsoverlay.yaml
 // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -ivfsoverlay /direct-vfs-root-files/vfsoverlay.yaml -I /overlay-dir -fsyntax-only /tests/vfsroot-with-overlay.c
 

diff  --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 9f310a82d3b2..eec61f4b731c 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1105,6 +1105,20 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
             ('%/T', tmpDir.replace('\\', '/')),
             ])
 
+    # "%{/[STpst]:regex_replacement}" should be normalized like "%/[STpst]" but we're
+    # also in a regex replacement context of a s@@@ regex.
+    def regex_escape(s):
+        s = s.replace('@', '\@')
+        s = s.replace('&', '\&')
+        return s
+    substitutions.extend([
+            ('%{/s:regex_replacement}', regex_escape(sourcepath.replace('\\', '/'))),
+            ('%{/S:regex_replacement}', regex_escape(sourcedir.replace('\\', '/'))),
+            ('%{/p:regex_replacement}', regex_escape(sourcedir.replace('\\', '/'))),
+            ('%{/t:regex_replacement}', regex_escape(tmpBase.replace('\\', '/')) + '.tmp'),
+            ('%{/T:regex_replacement}', regex_escape(tmpDir.replace('\\', '/'))),
+            ])
+
     # "%:[STpst]" are normalized paths without colons and without a leading
     # slash.
     substitutions.extend([


        


More information about the llvm-commits mailing list