[llvm] 8330dca - [llvm-rc] Allow -1 for menu item IDs

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 05:57:23 PDT 2020


Author: Martin Storsjö
Date: 2020-03-28T14:32:08+02:00
New Revision: 8330dcadb841cddcbe1318f2cd663b2787407f58

URL: https://github.com/llvm/llvm-project/commit/8330dcadb841cddcbe1318f2cd663b2787407f58
DIFF: https://github.com/llvm/llvm-project/commit/8330dcadb841cddcbe1318f2cd663b2787407f58.diff

LOG: [llvm-rc] Allow -1 for menu item IDs

This seems to be used in some resource files, e.g.
https://github.com/wxWidgets/wxWidgets/blob/f3217573d7240411e7817c9d76d965b2452987a2/include/wx/msw/wx.rc#L28.

MSVC rc.exe and GNU windres both allow any value here, and silently
just truncate to uint16_t range. This just explicitly allows the
-1 value and errors out on others - the same was done for control
IDs in dialogs in c1a67857ba0a6ba558818b589fe7c0fcc8f238ae.

Differential Revision: https://reviews.llvm.org/D76951

Added: 
    

Modified: 
    llvm/test/tools/llvm-rc/Inputs/tag-menu.rc
    llvm/test/tools/llvm-rc/tag-menu.test
    llvm/tools/llvm-rc/ResourceFileWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-rc/Inputs/tag-menu.rc b/llvm/test/tools/llvm-rc/Inputs/tag-menu.rc
index 33ba0d502689..cce9bc297031 100644
--- a/llvm/test/tools/llvm-rc/Inputs/tag-menu.rc
+++ b/llvm/test/tools/llvm-rc/Inputs/tag-menu.rc
@@ -54,7 +54,7 @@ BEGIN
     MENUITEM "a&bcde", 2
     MENUITEM "ab&cde", 3
     MENUITEM "abc&de", 4
-    MENUITEM "abcd&e", 5
+    MENUITEM "abcd&e", -1
   }
 END
 

diff  --git a/llvm/test/tools/llvm-rc/tag-menu.test b/llvm/test/tools/llvm-rc/tag-menu.test
index 5c73d0ea198b..58c856b700f8 100644
--- a/llvm/test/tools/llvm-rc/tag-menu.test
+++ b/llvm/test/tools/llvm-rc/tag-menu.test
@@ -69,7 +69,7 @@
 ; MENU-NEXT:   0060: 61002600 62006300 64006500 00000000  |a.&.b.c.d.e.....|
 ; MENU-NEXT:   0070: 03006100 62002600 63006400 65000000  |..a.b.&.c.d.e...|
 ; MENU-NEXT:   0080: 00000400 61006200 63002600 64006500  |....a.b.c.&.d.e.|
-; MENU-NEXT:   0090: 00008000 05006100 62006300 64002600  |......a.b.c.d.&.|
+; MENU-NEXT:   0090: 00008000 FFFF6100 62006300 64002600  |......a.b.c.d.&.|
 ; MENU-NEXT:   00A0: 65000000                             |e...|
 ; MENU-NEXT: )
 

diff  --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
index 44b3fe143ce8..615474b4a864 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
@@ -1180,8 +1180,10 @@ Error ResourceFileWriter::writeMenuDefinition(
 
   if (auto *MenuItemPtr = dyn_cast<MenuItem>(DefPtr)) {
     writeInt<uint16_t>(Flags);
-    RETURN_IF_ERROR(
-        checkNumberFits<uint16_t>(MenuItemPtr->Id, "MENUITEM action ID"));
+    // Some resource files use -1, i.e. UINT32_MAX, for empty menu items.
+    if (MenuItemPtr->Id != static_cast<uint32_t>(-1))
+      RETURN_IF_ERROR(
+          checkNumberFits<uint16_t>(MenuItemPtr->Id, "MENUITEM action ID"));
     writeInt<uint16_t>(MenuItemPtr->Id);
     RETURN_IF_ERROR(writeCString(MenuItemPtr->Name));
     return Error::success();


        


More information about the llvm-commits mailing list