[PATCH] D107263: [llvm-rc] Allow specifying language with a leading 0x prefix

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 04:14:37 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: amccarth, mati865.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

This option is always interpreted strictly as a hexadecimal string,
even if it has no prefix that indicates the number format, hence
the existing call to StringRef::getAsInteger(16, ...).

StringRef::getAsInteger(0, ...) consumes a leading "0x" prefix is
present, but when the radix is specified, the radix shouldn't
be included.

Both MS rc.exe and GNU windres accept the language with that
prefix.

Also allow specifying the codepage to llvm-windres with a different
radix, as GNU windres allows that (but MS rc.exe doesn't).

This fixes https://llvm.org/PR51295.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107263

Files:
  llvm/test/tools/llvm-rc/codepage.test
  llvm/test/tools/llvm-rc/language.test
  llvm/tools/llvm-rc/llvm-rc.cpp


Index: llvm/tools/llvm-rc/llvm-rc.cpp
===================================================================
--- llvm/tools/llvm-rc/llvm-rc.cpp
+++ llvm/tools/llvm-rc/llvm-rc.cpp
@@ -476,13 +476,14 @@
   Opts.Params.CodePage = CpWin1252; // Different default
   if (InputArgs.hasArg(WINDRES_codepage)) {
     if (InputArgs.getLastArgValue(WINDRES_codepage)
-            .getAsInteger(10, Opts.Params.CodePage))
+            .getAsInteger(0, Opts.Params.CodePage))
       fatalError("Invalid code page: " +
                  InputArgs.getLastArgValue(WINDRES_codepage));
   }
   if (InputArgs.hasArg(WINDRES_language)) {
-    if (InputArgs.getLastArgValue(WINDRES_language)
-            .getAsInteger(16, Opts.LangId))
+    StringRef Val = InputArgs.getLastArgValue(WINDRES_language);
+    Val.consume_front_insensitive("0x");
+    if (Val.getAsInteger(16, Opts.LangId))
       fatalError("Invalid language id: " +
                  InputArgs.getLastArgValue(WINDRES_language));
   }
@@ -565,7 +566,9 @@
   }
   Opts.AppendNull = InputArgs.hasArg(OPT_add_null);
   if (InputArgs.hasArg(OPT_lang_id)) {
-    if (InputArgs.getLastArgValue(OPT_lang_id).getAsInteger(16, Opts.LangId))
+    StringRef Val = InputArgs.getLastArgValue(OPT_lang_id);
+    Val.consume_front_insensitive("0x");
+    if (Val.getAsInteger(16, Opts.LangId))
       fatalError("Invalid language id: " +
                  InputArgs.getLastArgValue(OPT_lang_id));
   }
Index: llvm/test/tools/llvm-rc/language.test
===================================================================
--- llvm/test/tools/llvm-rc/language.test
+++ llvm/test/tools/llvm-rc/language.test
@@ -6,6 +6,8 @@
 ; RUN: llvm-readobj %t.res | FileCheck %s
 ; RUN: llvm-windres --no-preprocess --language 40A %p/Inputs/language.rc %t.res
 ; RUN: llvm-readobj %t.res | FileCheck %s
+; RUN: llvm-windres --no-preprocess -l 0x40A %p/Inputs/language.rc %t.res
+; RUN: llvm-readobj %t.res | FileCheck %s
 
 ; CHECK:      Resource name (int): 1
 ; CHECK-NEXT: Data version:
Index: llvm/test/tools/llvm-rc/codepage.test
===================================================================
--- llvm/test/tools/llvm-rc/codepage.test
+++ llvm/test/tools/llvm-rc/codepage.test
@@ -4,6 +4,8 @@
 ; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
 ; RUN: llvm-windres --no-preprocess --codepage 65001 %p/Inputs/utf8.rc %t.utf8.res
 ; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
+; RUN: llvm-windres --no-preprocess --codepage 0xfde9 %p/Inputs/utf8.rc %t.utf8.res
+; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
 
 ; UTF8:      Resource type (int): STRINGTABLE (ID 6)
 ; UTF8-NEXT: Resource name (int): 1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107263.363434.patch
Type: text/x-patch
Size: 2678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/06ccd129/attachment.bin>


More information about the llvm-commits mailing list