godot: new undefined behaviour with `Key` enum

Godot version

master, 7ab604b677c0bb4f5b06d661fbed07cc2faffc00

System information

MacOS

Issue description

ubsan=yes reporting lots of different new undefined behaviour in master.

scene/gui/popup_menu.cpp:1309:7: runtime error: load of value 134217789, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior scene/gui/popup_menu.cpp:1309:7 in 
scene/gui/popup_menu.cpp:1309:38: runtime error: load of value 134217789, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior scene/gui/popup_menu.cpp:1309:38 in 
core/input/input_event.cpp:393:18: runtime error: load of value 50331650, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/input/input_event.cpp:393:18 in 
core/input/input_event.cpp:393:18: runtime error: load of value 50331650, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/input/input_event.cpp:393:18 in 
core/os/keyboard.h:345:20: runtime error: load of value 50331650, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/os/keyboard.h:345:20 in 
core/input/input_event.cpp:394:18: runtime error: load of value 50331650, which is not a valid value for type 'Key'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/input/input_event.cpp:394:18 in ```

### Steps to reproduce

1. load master
2. build with ubsan=yes
3. run build 


### Minimal reproduction project

_No response_

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Ok, I’ve started working on this for the past hour. Good news: These enum classes are indeed a lot nicer, the code that works so far is looking nice, and another piece of good news is that this is a really good way to catch places that aren’t using the enum but should. Bad news: This is going to take forever, hopefully not more than the weekend, but I need to fix >100 files.

EDIT: 8 hours so far. No idea how much more, going to bed for now.

@RevoluPowered Done! Here’s the branch https://github.com/aaronfranke/godot/tree/enum-class

The next step is to test if it works as expected (no undefined behavior etc).