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)
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;
}
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;
}
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);
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;
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);
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;
--- /dev/null
+/* { dg-do run } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-skip-if "ABI 2 only" { *-*-* && { ! objc2 } } { "*" } { "" } } */
+/* { dg-additional-options "-fobjc-nilcheck -Wno-objc-root-class" } */
+
+#include "pr101666.inc"
+
--- /dev/null
+/* Later versions of Darwin can compile for 10.5, but cannot link it so we
+ can only run this test up to 10.13. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-do run { target *-*-darwin[89]* *-*-darwin1[0-7]* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-skip-if "ABI 2 only" { *-*-* && { ! objc2 } } { "*" } { "" } } */
+/* { dg-additional-options "-fobjc-nilcheck -mmacosx-version-min=10.5 " } */
+/* { dg-additional-options "-Wno-objc-root-class" } */
+
+#include "pr101666.inc"
--- /dev/null
+#include <cstdlib>
+struct point { double x, y, z; };
+
+@interface Foo
+- (struct point)bar;
+- (struct point)baz;
+@end
+
+@implementation Foo
+- (struct point)bar { struct point q = { 1.0, 2.0, 3.0 }; return q; };
+- (struct point)baz { struct point q = { 4.0, 5.0, 6.0 }; return q; };
+@end
+
+/* Cases where a check for nil should be inserted by the compiler, when
+ -fobjc-nilcheck is in force. We should not attempt the calls, and the
+ result should be 0-filled. */
+
+Foo *f;
+
+int main(void) {
+ struct point p = [f bar];
+ if (p.x != 0.0 || p.y != 0.0 || p.z != 0.0)
+ abort ();
+ id nilobj = (id)0;
+ p = [nilobj baz];
+ if (p.x != 0.0 || p.y != 0.0 || p.z != 0.0)
+ abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-skip-if "ABI 2 only" { *-*-* && { ! objc2 } } { "*" } { "" } } */
+/* { dg-additional-options "-fobjc-nilcheck -Wno-objc-root-class" } */
+
+#include "pr101666.inc"
+
--- /dev/null
+/* Later versions of Darwin can compile for 10.5, but cannot link it so we
+ can only run this test up to 10.13. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-do run { target *-*-darwin[89]* *-*-darwin1[0-7]* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-skip-if "ABI 2 only" { *-*-* && { ! objc2 } } { "*" } { "" } } */
+/* { dg-additional-options "-fobjc-nilcheck -mmacosx-version-min=10.5 " } */
+/* { dg-additional-options "-Wno-objc-root-class" } */
+
+#include "pr101666.inc"
--- /dev/null
+#include <stdlib.h>
+struct point { double x, y, z; };
+
+@interface Foo
+- (struct point)bar;
+- (struct point)baz;
+@end
+
+@implementation Foo
+- (struct point)bar { struct point q = { 1.0, 2.0, 3.0 }; return q; };
+- (struct point)baz { struct point q = { 4.0, 5.0, 6.0 }; return q; };
+@end
+
+/* Cases where a check for nil should be inserted by the compiler, when
+ -fobjc-nilcheck is in force. We should not attempt the calls, and the
+ result should be 0-filled. */
+
+Foo *f;
+
+int main(void) {
+ struct point p = [f bar];
+ if (p.x != 0.0 || p.y != 0.0 || p.z != 0.0)
+ abort ();
+ id nilobj = (id)0;
+ p = [nilobj baz];
+ if (p.x != 0.0 || p.y != 0.0 || p.z != 0.0)
+ abort ();
+ return 0;
+}