diff mbox

[hsa-branch,2/5] Make emit_insn_operands handle zero operands

Message ID 6d712c697c72d0d6359fd9e57f1b8e012565686e.1465479214.git.mjambor@suse.cz
State New
Headers show

Commit Message

Martin Jambor June 2, 2016, 4:32 p.m. UTC
Hi,

the patch below allows emit_insn_operands to instructions with no
operands gracefully.  Apparently so far we have not produced any.

I'll commit this to the hsa branch in a few moments and then to trunk
at some point in summer.

Martin

2016-06-02  Martin Jambor  <mjambor@suse.cz>

	* hsa-brig.c (emit_insn_operands): Cope with zero operands in an
	instruction.
---
 gcc/hsa-brig.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index 9c74b9a..471533c 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -1236,20 +1236,20 @@  emit_insn_operands (hsa_insn_basic *insn)
     operand_offsets;
 
   unsigned l = insn->operand_count ();
-  operand_offsets.safe_grow (l);
-
-  for (unsigned i = 0; i < l; i++)
-    operand_offsets[i] = lendian32 (enqueue_op (insn->get_op (i)));
 
   /* We have N operands so use 4 * N for the byte_count.  */
   uint32_t byte_count = lendian32 (4 * l);
-
   unsigned offset = brig_data.add (&byte_count, sizeof (byte_count));
-  brig_data.add (operand_offsets.address (),
-		 l * sizeof (BrigOperandOffset32_t));
+  if (l > 0)
+    {
+      operand_offsets.safe_grow (l);
+      for (unsigned i = 0; i < l; i++)
+	operand_offsets[i] = lendian32 (enqueue_op (insn->get_op (i)));
 
+      brig_data.add (operand_offsets.address (),
+		     l * sizeof (BrigOperandOffset32_t));
+    }
   brig_data.round_size_up (4);
-
   return offset;
 }