This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Subtle bug with GCC optimization?


Marius Vollmer <mvo@zagadka.ping.de> writes:

> after changing something in scm_ithrow, Guile crashed for me when
> there was no matching tag on the wind list.  It crashed only when
> compiled with -O2 on i386.  I traced it to the following code:
> 
>     for (winds = dynwinds; SCM_NIMP (winds); winds = SCM_CDR (winds))
>       {
>         if (! SCM_CONSP (winds))
> 	  abort ();
> 
>         dynpair = SCM_CAR (winds);
>         ...
>       }
> 
> which is compiled to this code fragment (see below for complete
> listings):
> 
> 	movl %ecx,%ebx
> 	andl $6,%ebx                     ;; SCM_NIMP
> 	movl (%ecx),%edx                 ;; SCM_CAR  -> crash!
> 	jne .L19
> 	testb $1,%dl                     ;; SCM_CONSP
> 	je .L22
> 	call abort
> 	.p2align 4,,7
> 
> As you can see, the code checks whether winds is NIMP and takes it CAR
> regardless (probably because it is needed to check for CONSP).
> 
> Is GCC allowed to do that?

Wow!  8-o

No, I don't think so.  First I thought that if we have the SCM type
defined as a void *, GCC might have the right to assume that it's
valid.

But this is not the default.

My guess it that it is a GCC bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]