Fix assert in generated `direct` property getter/setters due to removal of `_cmd...
authorMichael Wyman <michael@mwyman.com>
Tue, 11 Oct 2022 21:32:21 +0000 (14:32 -0700)
committerMichael Wyman <michael@mwyman.com>
Wed, 12 Oct 2022 04:15:53 +0000 (21:15 -0700)
commit1fbb6d8b34dec217179d8e46d8c5d8e243047045
tree534be5283e017c49b518c3a1c2ad15cf991bfd4e
parent7b45dfc6811a52ff4e9a6054dc276d70d77fddaf
Fix assert in generated `direct` property getter/setters due to removal of `_cmd` parameter.

This fixes a bug from https://reviews.llvm.org/D131424 that removed the implicit `_cmd` parameter as an argument to `objc_direct` method implementations. In many cases the generated getter/setter will call `objc_getProperty` or `objc_setProperty`, both of which require the selector of the getter/setter; since `_cmd` didn't automatically have backing storage, attempting to load the address asserted.

For direct property generated getters/setters, this now passes an undefined/uninitialized/poison value as the `_cmd` argument to `objc_getProperty`/`objc_setProperty`. Prior to removing the `_cmd` argument from the ABI of direct methods, it was left uninitialized/undefined; although references within hand-implemented methods would load the selector in the method prologue, generated getters/setters never did and just forwarded the undefined value that was passed as the argument.

This change keeps the generated code mostly similar to before, passing an uninitialized/undefined/poison value; for setters, the value argument may be moved to another register.

Added a test that triggers the assert prior to the implementation code.

Differential Revision: https://reviews.llvm.org/D135091
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/direct-method.m