]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Objective-C++ : Fix ICE in potential_constant_expression_1.
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 31 Oct 2020 09:25:47 +0000 (09:25 +0000)
committerMarek Polacek <polacek@redhat.com>
Thu, 14 Jan 2021 17:33:48 +0000 (12:33 -0500)
We cannot, as things stand, handle Objective-C tree codes in
the switch and deal with this by calling out to a function that
has a dummy version when Objective-C is not enabled.

Because of the way the logic works (with a fall through to a
'sorry' in case of unhandled expressions), the function reports
cases that are known to be unsuitable for constant exprs. The
dummy function always reports 'false' and thus will fall through
to the 'sorry'.

gcc/c-family/ChangeLog:

* c-objc.h (objc_non_constant_expr_p): New.
* stub-objc.c (objc_non_constant_expr_p): New.

gcc/cp/ChangeLog:

* constexpr.c (potential_constant_expression_1): Handle
expressions known to be non-constant for Objective-C.

gcc/objc/ChangeLog:

* objc-act.c (objc_non_constant_expr_p): New.

(cherry picked from commit 878cffbd9e6e1b138a6e0d362e7b29bc0a259940)

gcc/c-family/c-objc.h
gcc/c-family/stub-objc.c
gcc/cp/constexpr.c
gcc/objc/objc-act.c

index 6025283e5cfe7eb34cd210536fe80a4b67f0dfe4..4577e4f1c7f570579a0063b6a32decd1f5a1ae0d 100644 (file)
@@ -101,6 +101,7 @@ extern void objc_add_synthesize_declaration (location_t, tree);
 extern void objc_add_dynamic_declaration (location_t, tree);
 extern const char * objc_maybe_printable_name (tree, int);
 extern bool objc_is_property_ref (tree);
+extern bool objc_non_constant_expr_p (tree);
 extern bool objc_string_ref_type_p (tree);
 extern void objc_check_format_arg (tree, tree);
 extern void objc_finish_function (void);
index c30f0b3c67d35de390cd4f6d6323f8d8b59ea079..d017acfd6fe857ca5c2b491c4eef8672bf2947a3 100644 (file)
@@ -331,6 +331,12 @@ objc_is_property_ref (tree ARG_UNUSED (node))
   return 0;
 }
 
+bool
+objc_non_constant_expr_p (tree)
+{
+  return 0;
+}
+
 tree
 objc_maybe_build_component_ref (tree ARG_UNUSED (datum), tree ARG_UNUSED (component))
 {
index 5b1e3c181a01f934533ddb642700481d7ca220b9..b28fde7b4b805b3392ac85f0ec9fc18354d9e444 100644 (file)
@@ -8301,7 +8301,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
       return false;
 
     default:
-      if (objc_is_property_ref (t))
+      if (objc_non_constant_expr_p (t))
        return false;
 
       sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t)));
index 54af1cff53365ace2856fbf4f5f5b900d2766aeb..10beb6afc5c54335863af101857be8aa2beb5334 100644 (file)
@@ -1720,7 +1720,6 @@ objc_build_class_component_ref (tree class_name, tree property_ident)
 }
 
 
-
 /* This is used because we don't want to expose PROPERTY_REF to the
    C/C++ frontends.  Maybe we should!  */
 bool
@@ -1732,6 +1731,21 @@ objc_is_property_ref (tree node)
     return false;
 }
 
+/* We use this to report tree codes that are known to be invalid in const-
+   expression contexts.  */
+bool
+objc_non_constant_expr_p (tree node)
+{
+  switch (TREE_CODE (node))
+    {
+      default:
+       return false;
+      case MESSAGE_SEND_EXPR:
+      case PROPERTY_REF:
+       return true;
+    }
+}
+
 /* This function builds a setter call for a PROPERTY_REF (real, for a
    declared property, or artificial, for a dot-syntax accessor which
    is not corresponding to a property).  'lhs' must be a PROPERTY_REF