[BRIGFE] Support BRIG_KIND_NONE directives.
authorPekka Jääskeläinen <visit0r@gcc.gnu.org>
Mon, 9 Oct 2017 13:06:01 +0000 (13:06 +0000)
committerPekka Jääskeläinen <visit0r@gcc.gnu.org>
Mon, 9 Oct 2017 13:06:01 +0000 (13:06 +0000)
These directives are legal everywhere.  They can be used to
patch away BRIG entries at the binary level.

Also add extra error detection for zeroed regions: make sure
the byteCount field is never zero.

The call code still failed a few PRM test cases. Now all PRM
branch cases pass again.

From-SVN: r253545

gcc/brig/ChangeLog
gcc/brig/brigfrontend/brig-branch-inst-handler.cc
gcc/brig/brigfrontend/brig-to-generic.cc
gcc/brig/brigfrontend/phsa.h

index bdb7018..fa76684 100644 (file)
@@ -1,3 +1,18 @@
+2017-10-09  Pekka Jääskeläinen  <pekka.jaaskelainen@parmance.com>
+
+       * brigfrontend/brig-to-generic.cc: Support BRIG_KIND_NONE
+       directives.  These directives are legal everywhere.  They
+       can be used to patch away BRIG entries at the binary level.
+       Also add extra error detection for zeroed regions: make sure
+       the byteCount field is never zero.
+       * brig/brigfrontend/phsa.h: Added a new error prefix for
+       errors which are due to corrupted BRIG modules.
+
+2017-10-09  Henry Linjamäki  <henry.linjamaki@parmance.com>
+
+       * brigfrontend/brig-branch-inst-handler.cc: The call code
+       still failed a few test cases. Now all PRM cases pass again.
+
 2017-10-03  Henry Linjamäki  <henry.linjamaki@parmance.com>
 
        * brigfrontend/brig-branch-inst-handler.cc: Fix (more) crash with
index 30aec37..039f185 100644 (file)
@@ -70,7 +70,7 @@ brig_branch_inst_handler::operator () (const BrigBase *base)
          const BrigOperandOffset32_t *operand_ptr
            = (const BrigOperandOffset32_t *) data->bytes;
 
-         vec<tree, va_gc> *&args = i == 0 ? out_args : in_args;
+         bool out_args_p = i == 0;
 
          while (bytes > 0)
            {
@@ -85,7 +85,7 @@ brig_branch_inst_handler::operator () (const BrigBase *base)
              if (brig_var->type & BRIG_TYPE_ARRAY)
                {
                  /* Array return values are passed as the first argument.  */
-                 args = in_args;
+                 out_args_p = false;
                  /* Pass pointer to the element zero and use its element zero
                     as the base address.  */
                  tree etype = TREE_TYPE (TREE_TYPE (var));
@@ -97,8 +97,7 @@ brig_branch_inst_handler::operator () (const BrigBase *base)
                }
 
              gcc_assert (var != NULL_TREE);
-             vec_safe_reserve (args, 1);
-             vec_safe_push (args, var);
+             vec_safe_push (out_args_p ? out_args : in_args, var);
              ++operand_ptr;
              bytes -= 4;
            }
index 6459f9e..41246ba 100644 (file)
@@ -248,7 +248,12 @@ brig_to_generic::analyze (const char *brig_blob)
          if (handlers[i].kind == entry->kind)
            handler = handlers[i].handler;
        }
-      b += (*handler) (entry);
+
+      int bytes_processed = (*handler) (entry);
+      if (bytes_processed == 0)
+       fatal_error (UNKNOWN_LOCATION, PHSA_ERROR_PREFIX_CORRUPTED_MODULE
+                    "Element with 0 bytes.");
+      b += bytes_processed;
     }
 
   if (m_cf != NULL)
@@ -335,7 +340,10 @@ brig_to_generic::parse (const char *brig_blob)
        /* There are no supported pragmas at this moment.  */
        {BRIG_KIND_DIRECTIVE_PRAGMA, &skipped_handler},
        {BRIG_KIND_DIRECTIVE_CONTROL, &control_handler},
-       {BRIG_KIND_DIRECTIVE_EXTENSION, &skipped_handler}};
+       {BRIG_KIND_DIRECTIVE_EXTENSION, &skipped_handler},
+       /* BRIG_KIND_NONE entries are valid anywhere.  They can be used
+         for patching BRIGs before finalization.  */
+       {BRIG_KIND_NONE, &skipped_handler}};
 
   const BrigSectionHeader *csection_header = (const BrigSectionHeader *) m_code;
 
index 2da21c8..88e87eb 100644 (file)
@@ -61,9 +61,10 @@ typedef struct __attribute__((__packed__))
 #define PHSA_DESC_SECTION_PREFIX "phsa.desc."
 #define PHSA_HOST_DEF_PTR_PREFIX "__phsa.host_def."
 
-/* The frontend error messages are parsed by the host runtime, known
+/* The frontend error messages are parsed by the host runtime.  Known
    prefix strings are used to separate the different runtime error
    codes.  */
-#define PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE "Incompatible module:"
+#define PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE "Incompatible module: "
+#define PHSA_ERROR_PREFIX_CORRUPTED_MODULE "Corrupted module: "
 
 #endif