[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#343511: g++-3.4 -O1: wrong code generation



Package: g++-3.4
Version: 3.4.5-1
Severity: normal

Hello Debian GCC maintainers,

g++-3.4 incorrectly compiles the attached file at -O1 and up by causing
an infinite loop.

%g++-3.4 bug.c -o bug -Wall -O1
%./bug
oo-loop

gcc-3.4,g++-4.0 and gcc-4.0 all work correctly.

Cheers,
Bill.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void
mpqs_add_relation(long *ei, char *rel)
{
  char *s;

  s = strchr(rel, ':') - 1;
  *s = '\0';

  s = strtok(s + 3, " \n");
  while (s != NULL)
  {
    long e = atol(s);
    if (!e) break;
    s = strtok(NULL, " \n");
    ei[atol(s)] += e;
    s = strtok(NULL, " \n");
  }
  return;
}

int
main(void)
{
  long N=163;
  char *res="84481755 : 1 1 4 2 1 3 1 5 1 6 1 13 1 14 1 16 1 18 1 21 1 99 1 113 1 122 0\n";
  long *e=(long*)calloc(sizeof(long),N);
  mpqs_add_relation(e,strdup(res));
  return 0;
}

Reply to: