[PATCH] D106598: [llvm-rc] Allow dashes as part of resource name strings

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 14:42:17 PDT 2021


mstorsjo created this revision.
mstorsjo added a reviewer: amccarth.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

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
https://github.com/msys2/MINGW-packages/issues/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
https://github.com/msys2/MINGW-packages/issues/9130, which has been
worked around differently so far).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106598

Files:
  llvm/test/tools/llvm-rc/Inputs/resname-string.rc
  llvm/test/tools/llvm-rc/Inputs/tokens.rc
  llvm/test/tools/llvm-rc/resname-string.test
  llvm/test/tools/llvm-rc/tokenizer.test
  llvm/tools/llvm-rc/ResourceScriptToken.cpp


Index: llvm/tools/llvm-rc/ResourceScriptToken.cpp
===================================================================
--- llvm/tools/llvm-rc/ResourceScriptToken.cpp
+++ llvm/tools/llvm-rc/ResourceScriptToken.cpp
@@ -288,7 +288,7 @@
   assert(!streamEof());
   const char CurChar = Data[Pos];
   return std::isalnum(CurChar) || CurChar == '_' || CurChar == '.' ||
-         CurChar == '/' || CurChar == '\\';
+         CurChar == '/' || CurChar == '\\' || CurChar == '-';
 }
 
 bool Tokenizer::canStartInt() const {
Index: llvm/test/tools/llvm-rc/tokenizer.test
===================================================================
--- llvm/test/tools/llvm-rc/tokenizer.test
+++ llvm/test/tools/llvm-rc/tokenizer.test
@@ -27,6 +27,7 @@
 ; CHECK-NEXT:  BlockEnd: End
 ; CHECK-NEXT:  Identifier: He11o
 ; CHECK-NEXT:  Identifier: LLVM
+; CHECK-NEXT:  Identifier: identifier-with-dashes
 ; CHECK-NEXT:  String: "RC string test."
 ; CHECK-NEXT:  Comma: ,
 ; CHECK-NEXT:  String: L"Another RC string test.'&{"
Index: llvm/test/tools/llvm-rc/resname-string.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-rc/resname-string.test
@@ -0,0 +1,5 @@
+; RUN: llvm-rc -no-preprocess /FO %t.res -- %p/Inputs/resname-string.rc
+; RUN: llvm-readobj %t.res | FileCheck %s
+
+; CHECK: Resource name (string): STRINGNAME
+; CHECK: Resource name (string): NAME-WITH-DASHES/AND/SLASHES
Index: llvm/test/tools/llvm-rc/Inputs/tokens.rc
===================================================================
--- llvm/test/tools/llvm-rc/Inputs/tokens.rc
+++ llvm/test/tools/llvm-rc/Inputs/tokens.rc
@@ -1,5 +1,6 @@
 1 + 2 - 3214L & 0x120894 032173 2|&~+(-7){0xabcdef 0xABCDEFl} Begin End
 He11o LLVM
+identifier-with-dashes
 
 "RC string test.",L"Another RC string test.'&{",42,100
 
Index: llvm/test/tools/llvm-rc/Inputs/resname-string.rc
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-rc/Inputs/resname-string.rc
@@ -0,0 +1,2 @@
+stringname RCDATA { "foo" }
+name-with-dashes/and/slashes RCDATA { "foo" }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106598.360982.patch
Type: text/x-patch
Size: 2102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210722/254e7ea7/attachment.bin>


More information about the llvm-commits mailing list