When -fobjc-nilcheck is enabled, messages that result in a struct type should yield a zero-initialized struct when sent to nil. Currently, the frontend crashes when it encounters this situation. This patch fixes the crash by generating the tree for the `{}` initializer.
Tested by running the frontend against the example in PR101666 and inspecting the generated code. I don't have commit access, so if this patch is suitable, I'd need someone else to commit it for me. Thanks. gcc/objc/ChangeLog: 2021-08-14 Matt Jacobson <mhjacob...@me.com> PR objc/101666 * objc-next-runtime-abi-02.c (build_v2_objc_method_fixup_call): Fix crash. (build_v2_build_objc_method_call): Fix crash. diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c index e391ee527ce..42645e22316 100644 --- a/gcc/objc/objc-next-runtime-abi-02.c +++ b/gcc/objc/objc-next-runtime-abi-02.c @@ -1676,11 +1676,7 @@ build_v2_objc_method_fixup_call (int super_flag, tree method_prototype, if (TREE_CODE (ret_type) == RECORD_TYPE || TREE_CODE (ret_type) == UNION_TYPE) { - vec<constructor_elt, va_gc> *rtt = NULL; - /* ??? CHECKME. hmmm..... think we need something more - here. */ - CONSTRUCTOR_APPEND_ELT (rtt, NULL_TREE, NULL_TREE); - ftree = objc_build_constructor (ret_type, rtt); + ftree = objc_build_constructor (ret_type, NULL); } else ftree = fold_convert (ret_type, integer_zero_node); @@ -1790,11 +1786,7 @@ build_v2_build_objc_method_call (int super, tree method_prototype, if (TREE_CODE (ret_type) == RECORD_TYPE || TREE_CODE (ret_type) == UNION_TYPE) { - vec<constructor_elt, va_gc> *rtt = NULL; - /* ??? CHECKME. hmmm..... think we need something more - here. */ - CONSTRUCTOR_APPEND_ELT (rtt, NULL_TREE, NULL_TREE); - ftree = objc_build_constructor (ret_type, rtt); + ftree = objc_build_constructor (ret_type, NULL); } else ftree = fold_convert (ret_type, integer_zero_node);