Author: Martin Storsjö Date: 2021-08-06T12:39:15-07:00 New Revision: 37e964d8a623f6ae6a9e3e95bfc2d6503b9586eb
URL: https://github.com/llvm/llvm-project/commit/37e964d8a623f6ae6a9e3e95bfc2d6503b9586eb DIFF: https://github.com/llvm/llvm-project/commit/37e964d8a623f6ae6a9e3e95bfc2d6503b9586eb.diff LOG: [llvm-rc] Allow specifying language with a leading 0x prefix 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. Differential Revision: https://reviews.llvm.org/D107263 (cherry picked from commit 46020f6f0c8aa134002208b2ecf0593b04c46d08) Added: Modified: llvm/test/tools/llvm-rc/codepage.test llvm/test/tools/llvm-rc/language.test llvm/tools/llvm-rc/llvm-rc.cpp Removed: ################################################################################ diff --git a/llvm/test/tools/llvm-rc/codepage.test b/llvm/test/tools/llvm-rc/codepage.test index 20639d42ecb82..a55764cd4f76a 100644 --- a/llvm/test/tools/llvm-rc/codepage.test +++ b/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 diff --git a/llvm/test/tools/llvm-rc/language.test b/llvm/test/tools/llvm-rc/language.test index 9960ae108dfef..539371057414d 100644 --- a/llvm/test/tools/llvm-rc/language.test +++ b/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: diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp index 0f70e30b2b38f..83925c2ce7725 100644 --- a/llvm/tools/llvm-rc/llvm-rc.cpp +++ b/llvm/tools/llvm-rc/llvm-rc.cpp @@ -476,13 +476,14 @@ RcOptions parseWindresOptions(ArrayRef<const char *> ArgsArr, 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 @@ RcOptions parseRcOptions(ArrayRef<const char *> ArgsArr, } 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)); } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits