diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2021-08-14 12:27:55 +0100 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2021-08-18 19:41:43 +0100 |
commit | d2aa4e0b3b5053df8f5853d9ed29022ff0d3ecf6 (patch) | |
tree | af7be9b0ba6076f8d448735eb9eff65403a8cc33 /gcc/objc/objc-act.c | |
parent | 220c410162ebece4fffa2912ed79e348d3731d77 (diff) | |
download | gcc-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-act.c')
-rw-r--r-- | gcc/objc/objc-act.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index ec20891..6e4fb62 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -3377,8 +3377,10 @@ objc_build_string_object (tree string) return addr; } -/* Build a static constant CONSTRUCTOR - with type TYPE and elements ELTS. */ +/* Build a static constant CONSTRUCTOR with type TYPE and elements ELTS. + We might be presented with a NULL for ELTS, which means 'empty ctor' + which will subsequently be converted into a zero initializer in the + middle end. */ tree objc_build_constructor (tree type, vec<constructor_elt, va_gc> *elts) @@ -3390,12 +3392,10 @@ objc_build_constructor (tree type, vec<constructor_elt, va_gc> *elts) TREE_READONLY (constructor) = 1; #ifdef OBJCPLUS - /* Adjust for impedance mismatch. We should figure out how to build - CONSTRUCTORs that consistently please both the C and C++ gods. */ - if (!(*elts)[0].index) + /* If we know the initializer, then set the type to what C++ expects. */ + if (elts && !(*elts)[0].index) TREE_TYPE (constructor) = init_list_type_node; #endif - return constructor; } @@ -9664,7 +9664,9 @@ objc_gimplify_property_ref (tree *expr_p) call_exp = TREE_OPERAND (getter, 1); } #endif - gcc_assert (TREE_CODE (call_exp) == CALL_EXPR); + gcc_checking_assert ((flag_objc_nilcheck + && TREE_CODE (call_exp) == COND_EXPR) + || TREE_CODE (call_exp) == CALL_EXPR); *expr_p = call_exp; } |