From: Martin Storsjö Date: Mon, 2 Aug 2021 11:10:22 +0000 (+0300) Subject: [llvm-rc] Allow specifying language with a leading 0x prefix X-Git-Tag: upstream/15.0.7~34629 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46020f6f0c8aa134002208b2ecf0593b04c46d08;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/test/tools/llvm-rc/codepage.test b/llvm/test/tools/llvm-rc/codepage.test index 20639d4..a55764c 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 9960ae1..5393710 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 c7c93ae..6965b7f 100644 --- a/llvm/tools/llvm-rc/llvm-rc.cpp +++ b/llvm/tools/llvm-rc/llvm-rc.cpp @@ -476,13 +476,14 @@ RcOptions parseWindresOptions(ArrayRef 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 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)); }