public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc 3.3.1 segmentation fault (in rtlanal.c, rtx_varies_p())
@ 2004-08-26 16:19 Grigory Tolstolytkin
  2004-08-26 17:06 ` Paul Brook
  2004-08-26 21:04 ` Giovanni Bajo
  0 siblings, 2 replies; 6+ messages in thread
From: Grigory Tolstolytkin @ 2004-08-26 16:19 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1893 bytes --]

When compiling attached source file, the compiler crashes with 
segmentation fault in rtx_varies_p() function in rtlanal.c
I reproduced it at least for two tragets: arm_v5t_le and arm_iwmmxt_le. 
It doesn't occur when compiling with -O0 or -O1,
but for others do.

I debugged the compiler and found that the compiler generates the 
following rtl instruction:

(insn 16 15 17 0 0x4021b344 (set (reg/f:SI 71)
        (reg:SI 0 r0)) 345 {*iwmmxt_movsi_insn} (nil)
        (insn_list:REG_RETVAL 15 (expr_list:REG_EQUAL (expr_list 
(symbol_ref:SI ("cl"))
        (nil))
        (nil))))

Then, the "expr_list (symbol_ref:SI("cl"))" comes to the hash table for 
CSE optimization (the hash table declared in cse.c)

And when CSE optimization is applied
(cse_insn() is called on the rtl instruction
    (insn 28 47 36 1 0x4021b318 (set (mem/f:SI (plus:SI (reg/f:SI 25 sfp)
    (const_int -4 [0xfffffffc])) [2 S4 A32])
    (reg/v/f:SI 68)) 345 {*iwmmxt_movsi_insn} (nil)
    (nil))
) the rtl expression from the hash table is extracted and rtx_varies_p() 
function is called on each parameter of expr_list.
But the second parameter is NIL and rtx_varies_p() crashes on the first 
line (code = GET_CODE(x)), since the x is NULL.

If I add the follwing code in the beginning of rtx_varies_p():
"
    if (x == NULL)
        return 0;    // nil expression doesn't have have a value which 
can vary even between two executions of the program
"
then the compiler successfully generates object file. I wrote a simple 
test which calls the code from that object file and everything seems to 
work fine.

But I suppose that my fix might be wrong since I don't clearly 
understand how the compiler should work. In fact, does anybody know 
whether it's possible that such expressions may occur in the hash table 
or not?

Compilation parameters:
'arm_v5t_le-gcc -Os -c test.c -o test.o'

Any help is appreciated.

[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 231 bytes --]

struct st 
{
	int ia[256];
	unsigned char uc;
};

extern struct st *cl(void) __attribute__ ((__const__));
extern void bar(int **);

void foo(int *f, __builtin_va_list arg) 
{
	if (((*cl()).uc) != 1) {
		int *p = f;
		bar(&p);
	}
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-08-31 16:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-26 16:19 gcc 3.3.1 segmentation fault (in rtlanal.c, rtx_varies_p()) Grigory Tolstolytkin
2004-08-26 17:06 ` Paul Brook
2004-08-26 21:04 ` Giovanni Bajo
2004-08-27 11:58   ` Grigory Tolstolytkin
2004-08-27 13:26     ` Giovanni Bajo
2004-08-31 17:55       ` Grigory Tolstolytkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).