aboutsummaryrefslogtreecommitdiff
path: root/gcc/objc/objc-next-runtime-abi-02.c
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2021-08-14 12:27:55 +0100
committerIain Sandoe <iain@sandoe.co.uk>2021-08-18 19:41:43 +0100
commitd2aa4e0b3b5053df8f5853d9ed29022ff0d3ecf6 (patch)
treeaf7be9b0ba6076f8d448735eb9eff65403a8cc33 /gcc/objc/objc-next-runtime-abi-02.c
parent220c410162ebece4fffa2912ed79e348d3731d77 (diff)
downloadgcc-d2aa4e0b3b5053df8f5853d9ed29022ff0d3ecf6.zip
gcc-d2aa4e0b3b5053df8f5853d9ed29022ff0d3ecf6.tar.gz
gcc-d2aa4e0b3b5053df8f5853d9ed29022ff0d3ecf6.tar.bz2
Objective-C: fix crash with -fobjc-nilcheck
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. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> Co-authored-by: Matt Jacobson <mhjacobson@me.com> PR objc/101666 gcc/objc/ChangeLog: * objc-act.c (objc_build_constructor): Handle empty constructor lists. * objc-next-runtime-abi-02.c (build_v2_objc_method_fixup_call): Handle nil receivers. (build_v2_build_objc_method_call): Likewise. gcc/testsuite/ChangeLog: * obj-c++.dg/pr101666-0.mm: New test. * obj-c++.dg/pr101666-1.mm: New test. * obj-c++.dg/pr101666.inc: New. * objc.dg/pr101666-0.m: New test. * objc.dg/pr101666-1.m: New test. * objc.dg/pr101666.inc: New.
Diffstat (limited to 'gcc/objc/objc-next-runtime-abi-02.c')
-rw-r--r--gcc/objc/objc-next-runtime-abi-02.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index c552013..0d963e3 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -1675,13 +1675,8 @@ 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);
- }
+ /* An empty constructor is zero-filled by the middle end. */
+ ftree = objc_build_constructor (ret_type, NULL);
else
ftree = fold_convert (ret_type, integer_zero_node);
@@ -1694,11 +1689,11 @@ build_v2_objc_method_fixup_call (int super_flag, tree method_prototype,
ifexp, ret_val, ftree,
tf_warning_or_error);
#else
- /* ??? CHECKME. */
ret_val = build_conditional_expr (input_location,
- ifexp, 1,
+ ifexp, 0,
ret_val, NULL_TREE, input_location,
ftree, NULL_TREE, input_location);
+ ret_val = fold_convert (ret_type, ret_val);
#endif
}
return ret_val;
@@ -1790,11 +1785,8 @@ 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);
+ /* An empty constructor is zero-filled by the middle end. */
+ ftree = objc_build_constructor (ret_type, NULL);
}
else
ftree = fold_convert (ret_type, integer_zero_node);
@@ -1807,10 +1799,10 @@ build_v2_build_objc_method_call (int super, tree method_prototype,
ret_val = build_conditional_expr (loc, ifexp, ret_val, ftree,
tf_warning_or_error);
#else
- /* ??? CHECKME. */
ret_val = build_conditional_expr (loc, ifexp, 1,
ret_val, NULL_TREE, loc,
ftree, NULL_TREE, loc);
+ ret_val = fold_convert (ret_type, ret_val);
#endif
}
return ret_val;