Article View: gnu.gcc.bug
Article #2704unportable code fragment in emit-rtl.c
From: Peter R. Ham
Date: Thu, 01 Jun 1989 15:36
Date: Thu, 01 Jun 1989 15:36
61 lines
2223 bytes
2223 bytes
The applies to gcc version 1.35 in the target independent portions of the code.
The following code fragment in the function "copy_rtx_if_shared()" in the file
"emit-rtl.c" is not very robustly portable:
bcopy (x, copy, sizeof (int) * (GET_RTX_LENGTH (code) + 1));
Notice how the length in bytes of an rtx is calculated. This
code depends to heavily (and subtly) on the fact that an rtx_def
is exactly 12 bytes (or 3x32 bit words) long. A lot of care in
the definition of rtx_def has attempted to assure this, but the
C compiler available to me doesn't treat bitfields and enums so
well, so things don't work out so nicely.
The function "rtx_alloc()" in the file "rtl.c" accomplishes the
same result in a much more portable way:
/* Allocate an rtx of code CODE. The CODE is stored in the rtx;
all the rest is initialized to zero. */
rtx
rtx_alloc (code)
RTX_CODE code;
{
rtx rt;
register int nelts = GET_RTX_LENGTH (code);
register int length = sizeof (struct rtx_def)
+ (nelts - 1) * sizeof (rtunion);
rt = (rtx) obstack_alloc (rtl_obstack, length);
* (int *) rt = 0;
PUT_CODE (rt, code);
return rt;
}
I propose that the code fragment in emit-rtl.c use the
same code as rtx_alloc. Better yet, the following function
could be defined and used in both cases:
int
rtx_node_length_in_bytes(code)
RTX_CODE code;
{
int nelts = GET_RTX_LENGTH (code);
int length = sizeof (struct rtx_def)
+ (nelts - 1) * sizeof (rtunion);
return ( length );
}
I'd appreciate any feedback on this proposed small change.
I would like to get a feel for what kind of code
improvements are accepted by GNU for gcc.
--
Peter Ham PO Box 3430 (415) 324-4782
MS Computer Science Student Stanford, CA ham@polya.stanford.edu
Stanford University 94309
Technical Details
Message-ID:
<HAM.89Jun1083602@polya.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!polya!hamShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!polya!ham From: ham@polya.Stanford.EDU (Peter R. Ham) Newsgroups: gnu.gcc.bug Subject: unportable code fragment in emit-rtl.c Message-ID: <HAM.89Jun1083602@polya.Stanford.EDU> Date: 1 Jun 89 15:36:02 GMT Sender: Peter R. Ham <ham@polya.Stanford.EDU> Distribution: gnu Organization: Stanford University Lines: 61