[llvm-rc] Allow ALT on non-virtkey accelerators (#143374)

While
https://learn.microsoft.com/en-us/windows/win32/menurc/accelerators-resource
specifies that ALT only applies to virtkeys, this doesn't seem to be the
case in reality.

https://learn.microsoft.com/en-us/windows/win32/menurc/using-keyboard-accelerators
contains an example that uses this combination:

    "B",   ID_ACCEL5, ALT                   ; ALT_SHIFT+B

Also Microsoft also includes such cases in their repo of test cases:
263dd514ad/Samples/Win7Samples/begin/sdkdiff/sdkdiff.rc (L161-L164)

Also MS rc.exe doesn't warn/error about this. However if applying SHIFT
or CONTROL on a non-virtkey accelerator, MS rc.exe does produce this
warning:

    warning RC4203 : SHIFT or CONTROL used without VIRTKEY

Hence, keep the checks for SHIFT and CONTROL, but remove the checks for
ALT, which seems to have been incorrect.

This fixes one aspect of
https://github.com/llvm/llvm-project/issues/143157.

(cherry picked from commit 77347d6513de6a6f5dee8ade76e0a0ad1552c12b)
This commit is contained in:
Martin Storsjö 2025-06-10 10:23:19 +03:00 committed by Tom Stellard
parent 6fa0cdf372
commit c4f257cb74
4 changed files with 8 additions and 16 deletions

View File

@ -1,4 +0,0 @@
2 ACCELERATORS {
"A", 15, ASCII, ALT
}

View File

@ -110,5 +110,6 @@ LANGUAGE 5, 1
"7", 71, VIRTKEY, NOINVERT, CONTROL, SHIFT, ALT
"^j", 72, ASCII
"^j", 73, ASCII, NOINVERT
"A", 15, ASCII, ALT
}

View File

@ -37,7 +37,7 @@
; ACCELERATORS-NEXT: Version (major): 0
; ACCELERATORS-NEXT: Version (minor): 0
; ACCELERATORS-NEXT: Characteristics: 0
; ACCELERATORS-NEXT: Data size: 592
; ACCELERATORS-NEXT: Data size: 600
; ACCELERATORS-NEXT: Data: (
; ACCELERATORS-NEXT: 0000: 00002A00 00000000 01002A00 01000000 |..*.......*.....|
; ACCELERATORS-NEXT: 0010: 02002A00 02000000 03002A00 03000000 |..*.......*.....|
@ -75,7 +75,8 @@
; ACCELERATORS-NEXT: 0210: 15003700 42000000 0F003700 43000000 |..7.B.....7.C...|
; ACCELERATORS-NEXT: 0220: 1B003700 44000000 17003700 45000000 |..7.D.....7.E...|
; ACCELERATORS-NEXT: 0230: 1D003700 46000000 1F003700 47000000 |..7.F.....7.G...|
; ACCELERATORS-NEXT: 0240: 00000A00 48000000 82000A00 49000000 |....H.......I...|
; ACCELERATORS-NEXT: 0240: 00000A00 48000000 02000A00 49000000 |....H.......I...|
; ACCELERATORS-NEXT: 0250: 90004100 0F000000 |..A.....|
; ACCELERATORS-NEXT: )
@ -94,19 +95,13 @@
; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2
; ASCII2: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII2-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; ASCII2-NEXT: Accelerator ID 15: Can only apply SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3
; ASCII3: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII3-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4
; ASCII4: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII4-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
; ASCII3-NEXT: Accelerator ID 15: Can only apply SHIFT or CONTROL to VIRTKEY accelerators
; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-bad-key-id.rc 2>&1 | FileCheck %s --check-prefix BADKEYID

View File

@ -631,8 +631,8 @@ Error ResourceFileWriter::writeSingleAccelerator(
if (IsASCII && IsVirtKey)
return createAccError("Accelerator can't be both ASCII and VIRTKEY");
if (!IsVirtKey && (Obj.Flags & (Opt::ALT | Opt::SHIFT | Opt::CONTROL)))
return createAccError("Can only apply ALT, SHIFT or CONTROL to VIRTKEY"
if (!IsVirtKey && (Obj.Flags & (Opt::SHIFT | Opt::CONTROL)))
return createAccError("Can only apply SHIFT or CONTROL to VIRTKEY"
" accelerators");
if (Obj.Event.isInt()) {