[llvm] [lit] Fix substitutions containing backslashes (PR #103042)

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 08:46:58 PDT 2024


jdenny-ornl wrote:

> Script provided substitutions containing backslashes did not work on Unix, but they did work on Windows.

That depends on the definition of "work".  In downstream test suites (in lit config scripts but obviously not (RE)DEFINE), I have made use of replacement string backslashes (e.g., `\g`) as defined by `re.sub`.  I doubt that specific work will ever go upstream, but it makes me wonder if we should advertise this change in behavior more broadly.

> This lead to a Windows specific escaping of backslashes before doing Python re substitutions - since [7c9eab8](https://github.com/llvm/llvm-project/commit/7c9eab8fef0ed79a5911d21eb97b6b0fa9d39f82).

I think that means my usage above cannot behave correctly in Windows, where I never tested it.  With that in mind, my estimation is that backslash escaping is the desired and safest behavior in the vast majority of cases (probably all upstream cases).  
We could surely find some per-substitution switch to opt-in to full `re.sub` behavior.

Please update
[
https://llvm.org/docs/TestingGuide.html#substitutions

  I also tried to convey this usage, perhaps not as clearly .  See the first bullet under "Test-specific substitutions" in <https://llvm.org/docs/TestingGuide.html#substitutions>:


https://github.com/llvm/llvm-project/pull/103042


More information about the llvm-commits mailing list