[llvm] [llvm-strings] Add --encoding={s,S,utf8} option (PR #221794)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 06:10:37 PDT 2026


================
@@ -0,0 +1,28 @@
+## Show that llvm-strings uses the specified encoding.
+
+RUN: echo a > %t
+RUN: echo ab >> %t
+RUN: echo abc >> %t
+RUN: echo abcd >> %t
+RUN: echo abcd€ >> %t
----------------
hvdijk wrote:

> Not if the file is created/saved on Windows in the first place. To be more precise, it'll depend on the text editor used when last saving the file. I wouldn't be surprised if there are editors that might read a UTF-8 file but then save in a different encoding. Certainly, I can change the encoding manually in e.g. Sublime Text.

Sorry, but this sounds a bit like "but if I change the test so that it is no longer valid, it will no longer pass". Which is true, but which I'm having trouble understanding as an argument against this. If any editor silently changes the encoding of an UTF-8 file to no longer be UTF-8, that sounds like a major bug of such an editor?

An argument that I do see against this is that users using non-UTF-8-capable editors (whether on Windows or Linux or anything else) would have trouble viewing and understanding the test, they would see different character sequences that don't appear to make sense, but saving the file should at least preserve that.

> Quite possibly there isn't explicitly a method (I suggested \u in regexes, but I also wouldn't be surprised if it's not available).

Neither `\x` nor `\u` works in FileCheck regexes, in a very quick test doing `printf '\u00A1\n' | FileCheck test.test`, where `test.test` tries to match it using `{{\xC2\xA1}}` or `{{\u00A1}}`.

> One option would be to use printf to build up the check pattern in a file on disk, then specify this file rather than `%s` in the FileCheck command-line.

This is possible but would make the test harder to maintain and also makes it almost impossible to spot when `printf` does not work as expected and the test passes for the wrong reason (which has been a real issue in past LLVM releases, as `printf` was not implemented as a `llvm-lit` builtin and different systems used different implementations of `printf` with different features, and could well become a problem again when future `llvm-lit` updates further change what exactly is supported).

> Finally, there's always the option of enhancing FileCheck somehow.

If FileCheck could get extended to support `\x` and/or `\u`, I would fully support using that. But as you say, a lot more work.

Based on not understanding the first argument, I think using UTF-8 files is the best, or at least the least bad, of the options for now, but I can have a quick look at whether FileCheck is easy to extend.

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


More information about the llvm-commits mailing list