Bug#635214: gcc-4.6: [sparc] miscompile PARI/GP 2.5.0 [test-case provided]
Package: gcc-4.6
Version: 4.6.1-4
Severity: normal
Hello Debian GCC Maintainers,
gcc-4.6 miscompiles pari 2.5.0 on sparc, see
See https://buildd.debian.org/status/fetch.php?pkg=pari&arch=sparc&ver=2.5.0-1&stamp=1311418380
Please find a small test-case attached (test.c)
gcc -O2 -g -Wall -fno-strict-aliasing test.c -o test
./test
zsh: segmentation fault ./test
It does not segfault with -fno-inline and also with -fPIC.
This bug is very similar to 627084 except it only happens on sparc and that the
test-case is simpler.
Cheers,
--
Bill. <ballombe@debian.org>
Imagine a large red swirl here.
#include <stdlib.h>
inline void*
pari_realloc(void *pointer, size_t size)
{
char *tmp;
if (!pointer)
tmp = (char *) malloc(size);
else
tmp = (char *) realloc(pointer,size);
return tmp;
}
typedef struct {
long offset;
long n;
long alloc;
size_t size;
} pari_stack;
inline void **
stack_base(pari_stack *s) { return (void **) ((char *)s+s->offset); }
inline void
stack_init(pari_stack *s, size_t size, void **data)
{
s->offset = (char *)data-(char *)s;
*data = NULL;
s->n = 0;
s->alloc = 0;
s->size = size;
}
inline void
stack_alloc(pari_stack *s, long nb)
{
void **sdat = stack_base(s);
if (s->n+nb <= s->alloc) return;
if (!s->alloc)
s->alloc = nb;
else
{
while (s->n+nb > s->alloc) s->alloc <<= 1;
}
*sdat = pari_realloc(*sdat,s->alloc*s->size);
}
inline long
stack_new(pari_stack *s) { stack_alloc(s, 1); return s->n++; }
inline void
stack_pushp(pari_stack *s, void *u)
{
long n = stack_new(s);
void **sdat =(void**) *stack_base(s);
sdat[n] = u;
}
static void ** MODULES, ** OLDMODULES;
static pari_stack s_MODULES, s_OLDMODULES;
void
pari_init_functions(void)
{
stack_init(&s_MODULES, sizeof(*MODULES),(void**)&MODULES);
stack_pushp(&s_MODULES,NULL);
stack_init(&s_OLDMODULES, sizeof(*OLDMODULES),(void**)&OLDMODULES);
stack_pushp(&s_OLDMODULES,NULL);
}
int main(void)
{
pari_init_functions();
return 0;
}
Reply to: