Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Apr 2000 22:17:21 +0000
From:      mirko.viviani@rccr.cremona.it
To:        current@FreeBSD.org
Cc:        obrien@FreeBSD.org
Subject:   4.0 possible compiler bug ?
Message-ID:  <200004082017.WAA05269@rccr1.rccr.cremona.it>

next in thread | raw e-mail | index | archive | help
Ciao!

I'm testing the __builtin_apply() to make a patch to GNUstep, but I'm getting
in troubles.

rey:/tmp/tmp> gcc -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)

rey:/tmp/tmp> uname -a
FreeBSD rey.procom2.it 4.0-STABLE FreeBSD 4.0-STABLE #0: Fri Apr  7 01:02:03
CEST 2000    
mirko@rey.procom2.it:/mnt/amy/lpub/freebsd/usr/obj/mnt/amy/lpub/freebsd/usr/src/sys/rey 
i386

rey:/tmp/tmp> gcc -o test contest_i.c -Wall
contest_i.c: In function `main':
contest_i.c:37: warning: implicit declaration of function `printf'

rey:/tmp/tmp> ./test 
Segmentation fault (core dumped)

If the sizeof struct p is up to 8 bytes it returns the struct on the stack,
else it cores. But it dumps only with the __builtin_apply(), if you define
'pippo' it works.

Tested also on 3.4-stable with system gcc and it dumps.

I hope I'm wrong, since I need it.

Any hints ?


<-*- cut -*->
#include <sys/types.h>

struct p
{
	char p[10];
};

struct p p;
struct p *value = &p;

struct p floatValue()
{
	p.p[0] = 0x20;
	p.p[1] = 3;
	p.p[2] = 4;
	p.p[3] = 0x21;
	p.p[9] = 0xfe;
	return p;
}

int main()
{
	int i;
	char *(imp) = (char *)floatValue;
	void* retframe;
	void* frame = __builtin_apply_args(); //malloc(116);
	*(void**)frame = 0;
#ifdef pippo
	retframe=frame;
	floatValue();
#else
	retframe = __builtin_apply((void(*)(void))imp, frame, 0);
#endif
	for(i=0; i < 40; i++)
		printf("%02x ", ((unsigned char *)retframe)[i]);
	printf("\n");
	for(i=0; i < 4; i++)
		printf("%02x ", ((unsigned char *)&value)[i]);
	printf("\n");

	exit(0);
}
<-*- cut -*->

--
Bye,
Mirko  <mirko.viviani@rccr.cremona.it>




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004082017.WAA05269>