Skip to content

Commit 0a1683f

Browse files
committed
[llvm-rc] Allow dashes as part of resource name strings
This matches what MS rc.exe allows in practice. I'm not aware of any legal syntax case that are broken by allowing dashes as part of what the tokenizer considers an Identifier - but I'm not very well versed in the RC syntax either, can @amccarth think of any case that would be broken by this? This fixes downstream bug msys2/MINGW-packages#9180. Additionally, rc.exe allows such resource name strings to be surrounded by quotes, ending up with e.g. Resource name (string): "QUOTEDNAME" (i.e., the quotes end up as part of the string), which llvm-rc doesn't support yet either. (I'm not aware of such cases in the wild though, but resource string names with dashes do exist.) This also allows including files with unquoted paths, with filenames containing dashes (which fixes msys2/MINGW-packages#9130, which has been worked around differently so far). Differential Revision: https://reviews.llvm.org/D106598
1 parent 04e8d0b commit 0a1683f

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
stringname RCDATA { "foo" }
2+
name-with-dashes/and/slashes RCDATA { "foo" }

llvm/test/tools/llvm-rc/Inputs/tokens.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1 + 2 - 3214L & 0x120894 032173 2|&~+(-7){0xabcdef 0xABCDEFl} Begin End
22
He11o LLVM
3+
identifier-with-dashes
34

45
"RC string test.",L"Another RC string test.'&{",42,100
56

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; RUN: llvm-rc -no-preprocess /FO %t.res -- %p/Inputs/resname-string.rc
2+
; RUN: llvm-readobj %t.res | FileCheck %s
3+
4+
; CHECK: Resource name (string): STRINGNAME
5+
; CHECK: Resource name (string): NAME-WITH-DASHES/AND/SLASHES

llvm/test/tools/llvm-rc/tokenizer.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
; CHECK-NEXT: BlockEnd: End
2828
; CHECK-NEXT: Identifier: He11o
2929
; CHECK-NEXT: Identifier: LLVM
30+
; CHECK-NEXT: Identifier: identifier-with-dashes
3031
; CHECK-NEXT: String: "RC string test."
3132
; CHECK-NEXT: Comma: ,
3233
; CHECK-NEXT: String: L"Another RC string test.'&{"

llvm/tools/llvm-rc/ResourceScriptToken.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ bool Tokenizer::canContinueIdentifier() const {
288288
assert(!streamEof());
289289
const char CurChar = Data[Pos];
290290
return std::isalnum(CurChar) || CurChar == '_' || CurChar == '.' ||
291-
CurChar == '/' || CurChar == '\\';
291+
CurChar == '/' || CurChar == '\\' || CurChar == '-';
292292
}
293293

294294
bool Tokenizer::canStartInt() const {

0 commit comments

Comments
 (0)