This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


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

Broken C array autosizing breaks glibc compile


Hi,

with current CVS gcc at least PPC and alpha have problems with compiling a 
locale test in the glibc testsuite. Inspection shows that gcc miscompiles 
this routine:

struct keyword_t
{
  const char *name;
  int token;
  int symname_or_ident;
  int locale;
  int base;
  int group;
  int list;
};
 
static const struct keyword_t *
repertoiremap_hash (const char *str, unsigned int len)
{
  static const struct keyword_t wordlist[0] =
  {
    {"escape_char", 1, 0},
    {"comment_char", 2, 0},
    {"CHARIDS", 3, 0},
    {"END", 4, 0},
  };
 
  if (len == 11 && memcmp (wordlist[0].name, str, 11) == 0)
    return &wordlist[0];
  if (len == 12 && memcmp (wordlist[1].name, str, 12) == 0)
    return &wordlist[1];
  if (len == 7 && memcmp (wordlist[2].name, str, 7) == 0)
    return &wordlist[2];
  if (len == 3 && memcmp (wordlist[3].name, str, 3) == 0)
    return &wordlist[3];
 
  return ((void *)0);
}

In the .s I get:

        .file   "repertoire.c"
gcc2_compiled.:
                .section        ".rodata"
        .align 2
.LC0:
        .string "escape_char"
        .align 2
.LC1:
        .string "comment_char"
        .align 2
.LC2:
        .string "CHARIDS"
        .align 2
.LC3:
        .string "END"
        .align 2
        .type    wordlist.0,@object
        .size    wordlist.0,0
wordlist.0:
        .section        ".text"
        .align 2
        .type    repertoiremap_hash,@function
repertoiremap_hash:
....

So wordlist is never initialized :-(. If I change the wordlist[0] to 
wordlist[4] in the source above, everything is as expected:

...
        .string "END"
        .align 2
        .type    wordlist.0,@object
        .size    wordlist.0,112
wordlist.0:
        .long .LC0
        .long 1
        .long 0
        .space  16
        .long .LC1
        .long 2
        .long 0
        .space  16
        .long .LC2
        .long 3
        .long 0
        .space  16
        .long .LC3
        .long 4
        .long 0
        .space  16
        .section        ".text"
...

Franz.

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