This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Empty vectors in RTL
- From: Ian Lance Taylor <ian at airs dot com>
- To: gcc at gcc dot gnu dot org
- Date: 10 Feb 2005 21:24:02 -0500
- Subject: Empty vectors in RTL
I just happened to write
(define_insn "foo"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [] 42))]
""
"xxx\t%0")
This is because I have an instruction which sets a register but
doesn't depend on anything visible to gcc. When I tried to rebuild
gcc, genflags crashed, because it tried to get the length of an empty
vector (in max_operand_1, calling XVECLEN, which tried to dereference
a NULL pointer).
This patch fixes the immediate crash, but is this the right thing to
do? Or should I always put something inside the vector, even if there
is nothing meaningful to put in there?
If it is required to always put something inside a vector, then I
think that read_rtx_1 should give an error upon seeing an empty vector
(at least for case 'E'). Otherwise, I think we need something like
this patch, as there is a lot of code which expects to call XVECLEN on
any 'E' format.
Ian
Index: read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.32
diff -p -u -r1.32 read-rtl.c
--- read-rtl.c 29 Sep 2004 11:23:11 -0000 1.32
+++ read-rtl.c 11 Feb 2005 02:21:58 -0000
@@ -1247,12 +1247,9 @@ read_rtx_1 (FILE *infile)
list_counter++;
obstack_ptr_grow (&vector_stack, read_rtx_1 (infile));
}
- if (list_counter > 0)
- {
- return_vec = rtvec_alloc (list_counter);
- memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
- list_counter * sizeof (rtx));
- }
+ return_vec = rtvec_alloc (list_counter);
+ memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
+ list_counter * sizeof (rtx));
XVEC (return_rtx, i) = return_vec;
obstack_free (&vector_stack, NULL);
/* close bracket gotten */