Skip to content

Commit 46020f6

Browse files
committed
[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
1 parent 39fa96a commit 46020f6

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

llvm/test/tools/llvm-rc/codepage.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
55
; RUN: llvm-windres --no-preprocess --codepage 65001 %p/Inputs/utf8.rc %t.utf8.res
66
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
7+
; RUN: llvm-windres --no-preprocess --codepage 0xfde9 %p/Inputs/utf8.rc %t.utf8.res
8+
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
79

810
; UTF8: Resource type (int): STRINGTABLE (ID 6)
911
; UTF8-NEXT: Resource name (int): 1

llvm/test/tools/llvm-rc/language.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
; RUN: llvm-readobj %t.res | FileCheck %s
77
; RUN: llvm-windres --no-preprocess --language 40A %p/Inputs/language.rc %t.res
88
; RUN: llvm-readobj %t.res | FileCheck %s
9+
; RUN: llvm-windres --no-preprocess -l 0x40A %p/Inputs/language.rc %t.res
10+
; RUN: llvm-readobj %t.res | FileCheck %s
911

1012
; CHECK: Resource name (int): 1
1113
; CHECK-NEXT: Data version:

llvm/tools/llvm-rc/llvm-rc.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,14 @@ RcOptions parseWindresOptions(ArrayRef<const char *> ArgsArr,
476476
Opts.Params.CodePage = CpWin1252; // Different default
477477
if (InputArgs.hasArg(WINDRES_codepage)) {
478478
if (InputArgs.getLastArgValue(WINDRES_codepage)
479-
.getAsInteger(10, Opts.Params.CodePage))
479+
.getAsInteger(0, Opts.Params.CodePage))
480480
fatalError("Invalid code page: " +
481481
InputArgs.getLastArgValue(WINDRES_codepage));
482482
}
483483
if (InputArgs.hasArg(WINDRES_language)) {
484-
if (InputArgs.getLastArgValue(WINDRES_language)
485-
.getAsInteger(16, Opts.LangId))
484+
StringRef Val = InputArgs.getLastArgValue(WINDRES_language);
485+
Val.consume_front_insensitive("0x");
486+
if (Val.getAsInteger(16, Opts.LangId))
486487
fatalError("Invalid language id: " +
487488
InputArgs.getLastArgValue(WINDRES_language));
488489
}
@@ -565,7 +566,9 @@ RcOptions parseRcOptions(ArrayRef<const char *> ArgsArr,
565566
}
566567
Opts.AppendNull = InputArgs.hasArg(OPT_add_null);
567568
if (InputArgs.hasArg(OPT_lang_id)) {
568-
if (InputArgs.getLastArgValue(OPT_lang_id).getAsInteger(16, Opts.LangId))
569+
StringRef Val = InputArgs.getLastArgValue(OPT_lang_id);
570+
Val.consume_front_insensitive("0x");
571+
if (Val.getAsInteger(16, Opts.LangId))
569572
fatalError("Invalid language id: " +
570573
InputArgs.getLastArgValue(OPT_lang_id));
571574
}

0 commit comments

Comments
 (0)