From e70f01b561a3d65baba2c981a4e162967e41285f Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 23 Sep 2016 09:55:57 +0200 Subject: [PATCH] re PR target/71652 (ICE in in ix86_target_macros_internal, at config/i386/i386-c.c:187) Fix PR target/71652 PR target/71652 * config/i386/i386.c (ix86_option_override_internal): Change signature and return false when there's an error related to arch string. (release_options_strings): New function. (ix86_valid_target_attribute_tree): Call the function. * gcc.target/i386/pr71652.c: New test. * gcc.target/i386/pr71652-2.c: New test. * gcc.target/i386/pr71652-3.c: New test. From-SVN: r240392 --- gcc/ChangeLog | 9 +++ gcc/config/i386/i386.c | 70 +++++++++++++++-------- gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/gcc.target/i386/pr71652-2.c | 13 +++++ gcc/testsuite/gcc.target/i386/pr71652-3.c | 14 +++++ gcc/testsuite/gcc.target/i386/pr71652.c | 13 +++++ 6 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr71652-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr71652-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr71652.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 453413be338..d3ba1c29810 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2016-09-23 Martin Liska + + PR target/71652 + * config/i386/i386.c (ix86_option_override_internal): Change + signature and return false when there's an error related to + arch string. + (release_options_strings): New function. + (ix86_valid_target_attribute_tree): Call the function. + 2016-09-23 Jakub Jelinek * hsa-gen.c (hsa_op_immed::hsa_op_immed Use CONSTRUCTOR_NELTS (...) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ff057dc60f9..2dcd5699a70 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -4731,9 +4731,10 @@ ix86_override_options_after_change (void) /* Override various settings based on options. If MAIN_ARGS_P, the options are from the command line, otherwise they are from - attributes. */ + attributes. Return true if there's an error related to march + option. */ -static void +static bool ix86_option_override_internal (bool main_args_p, struct gcc_options *opts, struct gcc_options *opts_set) @@ -5262,16 +5263,36 @@ ix86_option_override_internal (bool main_args_p, for (i = 0; i < pta_size; i++) if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name)) { + if (!strcmp (opts->x_ix86_arch_string, "generic")) + { + error (main_args_p + ? "% CPU can be used only for %<-mtune=%> switch" + : "% CPU can be used only for " + "% attribute"); + return false; + } + else if (!strcmp (opts->x_ix86_arch_string, "intel")) + { + error (main_args_p + ? "% CPU can be used only for %<-mtune=%> switch" + : "% CPU can be used only for " + "% attribute"); + return false; + } + + if (TARGET_64BIT_P (opts->x_ix86_isa_flags) + && !(processor_alias_table[i].flags & PTA_64BIT)) + { + error ("CPU you selected does not support x86-64 " + "instruction set"); + return false; + } + ix86_schedule = processor_alias_table[i].schedule; ix86_arch = processor_alias_table[i].processor; /* Default cpu tuning to the architecture. */ ix86_tune = ix86_arch; - if (TARGET_64BIT_P (opts->x_ix86_isa_flags) - && !(processor_alias_table[i].flags & PTA_64BIT)) - error ("CPU you selected does not support x86-64 " - "instruction set"); - if (processor_alias_table[i].flags & PTA_MMX && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX)) opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MMX; @@ -5469,17 +5490,7 @@ ix86_option_override_internal (bool main_args_p, if (TARGET_X32 && (ix86_isa_flags & OPTION_MASK_ISA_MPX)) error ("Intel MPX does not support x32"); - if (!strcmp (opts->x_ix86_arch_string, "generic")) - error (main_args_p - ? "% CPU can be used only for %<-mtune=%> switch" - : "% CPU can be used only for " - "% attribute"); - else if (!strcmp (opts->x_ix86_arch_string, "intel")) - error (main_args_p - ? "% CPU can be used only for %<-mtune=%> switch" - : "% CPU can be used only for " - "% attribute"); - else if (i == pta_size) + if (i == pta_size) { error (main_args_p ? "bad value (%qs) for %<-march=%> switch" @@ -6134,6 +6145,8 @@ ix86_option_override_internal (bool main_args_p, ix86_parse_stringop_strategy_string (str, true); free (str); } + + return true; } /* Implement the TARGET_OPTION_OVERRIDE hook. */ @@ -6728,6 +6741,15 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[], return ret; } +/* Release allocated strings. */ +static void +release_options_strings (char **option_strings) +{ + /* Free up memory allocated to hold the strings */ + for (unsigned i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++) + free (option_strings[i]); +} + /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */ tree @@ -6742,7 +6764,6 @@ ix86_valid_target_attribute_tree (tree args, int orig_arch_specified = ix86_arch_specified; char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL }; tree t = NULL_TREE; - int i; struct cl_target_option *def = TREE_TARGET_OPTION (target_option_default_node); struct gcc_options enum_opts_set; @@ -6803,7 +6824,12 @@ ix86_valid_target_attribute_tree (tree args, } /* Do any overrides, such as arch=xxx, or tune=xxx support. */ - ix86_option_override_internal (false, opts, opts_set); + bool r = ix86_option_override_internal (false, opts, opts_set); + if (!r) + { + release_options_strings (option_strings); + return error_mark_node; + } /* Add any builtin functions with the new isa if any. */ ix86_add_new_builtins (opts->x_ix86_isa_flags); @@ -6816,9 +6842,7 @@ ix86_valid_target_attribute_tree (tree args, opts->x_ix86_tune_string = orig_tune_string; opts_set->x_ix86_fpmath = orig_fpmath_set; - /* Free up memory allocated to hold the strings */ - for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++) - free (option_strings[i]); + release_options_strings (option_strings); } return t; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index facc0d0a4d7..6b6693efa94 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-09-23 Martin Liska + + * gcc.target/i386/pr71652.c: New test. + * gcc.target/i386/pr71652-2.c: New test. + * gcc.target/i386/pr71652-3.c: New test. + 2016-09-23 Jakub Jelinek * lib/gcc-dg.exp (process-message): Support relative line number diff --git a/gcc/testsuite/gcc.target/i386/pr71652-2.c b/gcc/testsuite/gcc.target/i386/pr71652-2.c new file mode 100644 index 00000000000..6c8eaf18d6d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr71652-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +#pragma GCC push_options +#pragma GCC target ("arch=intel") /* { dg-error "'intel' CPU can be used only for 'target\\(\"tune=\"\\)' attribute" } */ + +__attribute__((constructor)) void foo() +{ + asm (""); +} + +#pragma GCC pop_options + +int main() { return 0; } diff --git a/gcc/testsuite/gcc.target/i386/pr71652-3.c b/gcc/testsuite/gcc.target/i386/pr71652-3.c new file mode 100644 index 00000000000..ba99a3ea9d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr71652-3.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-march=haswell" } */ + +#pragma GCC push_options +#pragma GCC target ("arch=geode") /* { dg-error "CPU you selected does not support x86-64 instruction set" } */ + +__attribute__((constructor)) void foo() +{ + asm (""); +} + +#pragma GCC pop_options + +int main() { return 0; } diff --git a/gcc/testsuite/gcc.target/i386/pr71652.c b/gcc/testsuite/gcc.target/i386/pr71652.c new file mode 100644 index 00000000000..a6b04db600c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr71652.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +#pragma GCC push_options +#pragma GCC target ("arch=generic") /* { dg-error "'generic' CPU can be used only for 'target\\(\"tune=\"\\)' attribute" } */ + +__attribute__((constructor)) void foo() +{ + asm (""); +} + +#pragma GCC pop_options + +int main() { return 0; } -- 2.30.2