public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9269] Objective-C++ : Fix ICE in potential_constant_expression_1.
@ 2021-01-14 17:34 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2021-01-14 17:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3e08dcab3aaa7916d782cb5994f269bbfc216cdc

commit r10-9269-g3e08dcab3aaa7916d782cb5994f269bbfc216cdc
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sat Oct 31 09:25:47 2020 +0000

    Objective-C++ : Fix ICE in potential_constant_expression_1.
    
    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)

Diff:
---
 gcc/c-family/c-objc.h    |  1 +
 gcc/c-family/stub-objc.c |  6 ++++++
 gcc/cp/constexpr.c       |  2 +-
 gcc/objc/objc-act.c      | 16 +++++++++++++++-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c-objc.h b/gcc/c-family/c-objc.h
index 6025283e5cf..4577e4f1c7f 100644
--- a/gcc/c-family/c-objc.h
+++ b/gcc/c-family/c-objc.h
@@ -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);
diff --git a/gcc/c-family/stub-objc.c b/gcc/c-family/stub-objc.c
index c30f0b3c67d..d017acfd6fe 100644
--- a/gcc/c-family/stub-objc.c
+++ b/gcc/c-family/stub-objc.c
@@ -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))
 {
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5b1e3c181a0..b28fde7b4b8 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -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)));
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 54af1cff533..10beb6afc5c 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-14 17:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 17:34 [gcc r10-9269] Objective-C++ : Fix ICE in potential_constant_expression_1 Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).