From f5dbfa73962d5443013d0193b2f91ea112a6d2d1 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/6] Abort if Gimple 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 4c1ddc6d0e3..9a28097b473 100644
--- a/gcc/ipa-field-reorder.c
+++ b/gcc/ipa-field-reorder.c
@@ -587,6 +587,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 ();
@@ -594,7 +595,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 aec7b924533..40dc89c51a2 100644
--- a/gcc/ipa-type-escape-analysis.c
+++ b/gcc/ipa-type-escape-analysis.c
@@ -171,6 +171,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.
@@ -581,6 +586,7 @@ TypeWalker::_walk (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;
@@ -634,9 +640,9 @@ TypeWalker::_walk (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;
@@ -646,18 +652,24 @@ TypeWalker::_walk (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;
}
@@ -840,6 +852,7 @@ TypeWalker::_walk_arg (tree t)
void
ExprWalker::walk (tree e)
{
+ if (detected_incompatible_syntax) return;
_walk_pre (e);
_walk (e);
_walk_post (e);
@@ -924,7 +937,11 @@ ExprWalker::_walk (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;
}
@@ -1157,6 +1174,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);
@@ -1403,7 +1421,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
@@ -2935,6 +2957,8 @@ TypeStringifier::stringify (tree t)
return std::string ("");
_stringification.clear ();
gcc_assert (t);
+ if (detected_incompatible_syntax)
+ return std::string ("");
walk (t);
return _stringification;
}
@@ -3125,14 +3149,19 @@ TypeStringifier::_walk_arg_post (__attribute__
((unused)) tree t)
std::string
TypeStringifier::get_type_identifier (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);
@@ -3202,7 +3231,12 @@ TypeStructuralEquality::_equal (tree l, 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;
}
@@ -3401,3 +3435,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 0058c145793..f29127b7f03 100644
--- a/gcc/ipa-type-escape-analysis.h
+++ b/gcc/ipa-type-escape-analysis.h
@@ -1162,4 +1162,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