From bad08833616e9dd7a212e55b93503200393da942 Mon Sep 17 00:00:00 2001
From: Erick Ochoa <erick.oc...@theobroma-systems.com>
Date: Sun, 30 Aug 2020 10:21:35 +0200
Subject: [PATCH 5/7] Abort if Gimple produced from C++ or Fortran sources is
 found.

2020-11-04  Erick Ochoa  <erick.oc...@theobroma-systems.com>

        * gcc/ipa-field-reorder: Add flag to exit transformation
        * gcc/ipa-type-escape-analysis: Same

---
 gcc/ipa-field-reorder.c        |  3 +-
 gcc/ipa-type-escape-analysis.c | 53 ++++++++++++++++++++++++++++------
 gcc/ipa-type-escape-analysis.h |  2 ++
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/gcc/ipa-field-reorder.c b/gcc/ipa-field-reorder.c
index 611089ecf24..c23e6a3f818 100644
--- a/gcc/ipa-field-reorder.c
+++ b/gcc/ipa-field-reorder.c
@@ -590,6 +590,7 @@ lto_fr_execute ()
 {
   log ("here in field reordering \n");
   // Analysis.
+  detected_incompatible_syntax = false;
   tpartitions_t escaping_nonescaping_sets
     = partition_types_into_escaping_nonescaping ();
   record_field_map_t record_field_map = find_fields_accessed ();
@@ -597,7 +598,7 @@ lto_fr_execute ()
     = obtain_nonescaping_unaccessed_fields (escaping_nonescaping_sets,
                                            record_field_map, 0);

-  if (record_field_offset_map.empty ())
+  if (detected_incompatible_syntax || record_field_offset_map.empty ())
     return 0;

   // Prepare for transformation.
diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c
index 9944580da6c..b06f33e24fb 100644
--- a/gcc/ipa-type-escape-analysis.c
+++ b/gcc/ipa-type-escape-analysis.c
@@ -170,6 +170,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-type-escape-analysis.h"
 #include "ipa-dfe.h"

+#define ABORT_IF_NOT_C true
+
+bool detected_incompatible_syntax = false;
+
 // Main function that drives dfe.
 static unsigned int
 lto_dfe_execute ();
@@ -256,13 +260,14 @@ static void
 lto_dead_field_elimination ()
 {
   // Analysis.
+  detected_incompatible_syntax = false;
   tpartitions_t escaping_nonescaping_sets
     = partition_types_into_escaping_nonescaping ();
   record_field_map_t record_field_map = find_fields_accessed ();
   record_field_offset_map_t record_field_offset_map
     = obtain_nonescaping_unaccessed_fields (escaping_nonescaping_sets,
                                            record_field_map, OPT_Wdfa);
-  if (record_field_offset_map.empty ())
+  if (detected_incompatible_syntax || record_field_offset_map.empty ())
     return;

     // Prepare for transformation.
@@ -589,6 +594,7 @@ TypeWalker::_walk (const_tree type)
   // Improve, verify that having a type is an invariant.
   // I think there was a specific example which didn't
   // allow for it
+  if (detected_incompatible_syntax) return;
   if (!type)
     return;

@@ -642,9 +648,9 @@ TypeWalker::_walk (const_tree type)
     case POINTER_TYPE:
       this->walk_POINTER_TYPE (type);
       break;
-    case REFERENCE_TYPE:
-      this->walk_REFERENCE_TYPE (type);
-      break;
+    //case REFERENCE_TYPE:
+    //  this->walk_REFERENCE_TYPE (type);
+    //  break;
     case ARRAY_TYPE:
       this->walk_ARRAY_TYPE (type);
       break;
@@ -654,18 +660,24 @@ TypeWalker::_walk (const_tree type)
     case FUNCTION_TYPE:
       this->walk_FUNCTION_TYPE (type);
       break;
-    case METHOD_TYPE:
-      this->walk_METHOD_TYPE (type);
-      break;
+    //case METHOD_TYPE:
+      //this->walk_METHOD_TYPE (type);
+      //break;
     // Since we are dealing only with C at the moment,
     // we don't care about QUAL_UNION_TYPE nor LANG_TYPEs
     // So fail early.
+    case REFERENCE_TYPE:
+    case METHOD_TYPE:
     case QUAL_UNION_TYPE:
     case LANG_TYPE:
     default:
       {
        log ("missing %s\n", get_tree_code_name (code));
+#ifdef ABORT_IF_NOT_C
+       detected_incompatible_syntax = true;
+#else
        gcc_unreachable ();
+#endif
       }
       break;
     }
@@ -848,6 +860,7 @@ TypeWalker::_walk_arg (const_tree t)
 void
 ExprWalker::walk (const_tree e)
 {
+  if (detected_incompatible_syntax) return;
   _walk_pre (e);
   _walk (e);
   _walk_post (e);
@@ -932,7 +945,11 @@ ExprWalker::_walk (const_tree e)
     default:
       {
        log ("missing %s\n", get_tree_code_name (code));
+#ifdef ABORT_IF_NOT_C
+       detected_incompatible_syntax = true;
+#else
        gcc_unreachable ();
+#endif
       }
       break;
     }
@@ -1165,6 +1182,7 @@ GimpleWalker::walk ()
   cgraph_node *node = NULL;
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
     {
+      if (detected_incompatible_syntax) return;
       node->get_untransformed_body ();
       tree decl = node->decl;
       gcc_assert (decl);
@@ -1411,7 +1429,11 @@ GimpleWalker::_walk_gimple (gimple *stmt)
   // Break if something is unexpected.
   const char *name = gimple_code_name[code];
   log ("gimple code name %s\n", name);
+#ifdef ABORT_IF_NOT_C
+  detected_incompatible_syntax = true;
+#else
   gcc_unreachable ();
+#endif
 }

 void
@@ -2947,6 +2969,8 @@ TypeStringifier::stringify (const_tree t)
     return std::string ("");
   _stringification.clear ();
   gcc_assert (t);
+  if (detected_incompatible_syntax)
+    return std::string ("");
   walk (t);
   return _stringification;
 }
@@ -3137,14 +3161,19 @@ TypeStringifier::_walk_arg_post (__attribute__ ((unused)) const_tree t)
 std::string
 TypeStringifier::get_type_identifier (const_tree t)
 {
+  if (detected_incompatible_syntax)
+    return std::string ("");
   tree name = TYPE_NAME (t);
-  const bool no_name = NULL_TREE == name;
+  bool no_name = NULL_TREE == name;
   if (no_name)
     return std::string ("");

   const enum tree_code name_code = TREE_CODE (name);
   const bool is_name_type_decl = TYPE_DECL == name_code;
   name = is_name_type_decl ? DECL_NAME (name) : name;
+  no_name = NULL_TREE == name;
+  if (no_name)
+    return std::string ("");
   const char *identifier_ptr = IDENTIFIER_POINTER (name);
   gcc_assert (identifier_ptr);
   return std::string (identifier_ptr);
@@ -3214,7 +3243,12 @@ TypeStructuralEquality::_equal (const_tree l, const_tree r)
       TSE_CASE (FUNCTION_TYPE);
       TSE_CASE (METHOD_TYPE);
     default:
-      gcc_unreachable ();
+#ifdef ABORT_IF_NOT_C
+       detected_incompatible_syntax = true;
+       return false;
+#else
+       gcc_unreachable ();
+#endif
       break;
     }

@@ -3413,3 +3447,4 @@ make_pass_ipa_type_escape_analysis (gcc::context *ctx)
 {
   return new pass_ipa_type_escape_analysis (ctx);
 }
+
diff --git a/gcc/ipa-type-escape-analysis.h b/gcc/ipa-type-escape-analysis.h
index 38e3a36cefd..8582248e9ad 100644
--- a/gcc/ipa-type-escape-analysis.h
+++ b/gcc/ipa-type-escape-analysis.h
@@ -1165,4 +1165,6 @@ obtain_nonescaping_unaccessed_fields (tpartitions_t casting,
                                      record_field_map_t record_field_map,
                                      int warning);

+extern bool detected_incompatible_syntax;
+
 #endif /* GCC_IPA_TYPE_ESCAPE_ANALYSIS_H */
--
2.18.1

Reply via email to