http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59587
Bug ID: 59587 Summary: cpu_names in i386.c is accessed with wrong index Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: ubizjak at gmail dot com i386.c has static const char *const cpu_names[TARGET_CPU_DEFAULT_max] = { "generic", ... "btver2" }; ... if (!opts->x_ix86_tune_string) { opts->x_ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT]; ix86_tune_defaulted = 1; } ... fprintf (file, "%*sarch = %d (%s)\n", indent, "", ptr->arch, ((ptr->arch < TARGET_CPU_DEFAULT_max) ? cpu_names[ptr->arch] : "<unknown>")); fprintf (file, "%*stune = %d (%s)\n", indent, "", ptr->tune, ((ptr->tune < TARGET_CPU_DEFAULT_max) ? cpu_names[ptr->tune] : "<unknown>")); But ptr->arch and ptr->tune are set by ptr->arch = ix86_arch; ptr->schedule = ix86_schedule; ptr->tune = ix86_tune; ix86_arch is set by /* Which instruction set architecture to use. */ enum processor_type ix86_arch; ix86_arch = processor_alias_table[i].processor; and ix86_tune is set by /* Which cpu are we optimizing for. */ enum processor_type ix86_tune; ix86_tune = processor_alias_table[i].processor; We are using enum processor_type as index to access array of enum target_cpu_default enum target_cpu_default { TARGET_CPU_DEFAULT_generic = 0, ... TARGET_CPU_DEFAULT_max }; x86 backend only uses TARGET_CPU_DEFAULT_generic to set up the default tuning: #ifndef TARGET_CPU_DEFAULT #define TARGET_CPU_DEFAULT TARGET_CPU_DEFAULT_generic #endif ... if (!opts->x_ix86_tune_string) { opts->x_ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT]; ix86_tune_defaulted = 1; } We never define a different TARGET_CPU_DEFAULT. When GCC is configured with --with-arch=/--with-cpu=, we have [hjl@gnu-6 build-x86_64-linux]$ cat gcc/configargs.h /* Generated automatically. */ static const char configuration_arguments[] = "/export/gnu/import/git/gcc/configure --enable-languages=c,c++,fortran --disable-bootstrap --prefix=/usr/gcc-4.9.0 --with-local-prefix=/usr/local --enable-gnu-indirect-function --with-fpmath=sse"; static const char thread_model[] = "posix"; static const struct { const char *name, *value; } configure_default_options[] = { { "cpu", "generic" }, { "arch", "x86-64" } }; [hjl@gnu-6 build-x86_64-linux]$ which passes -march=/-mtune= to toplev.c.