diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc index d81b7d122f7..1ec800526f7 100644 --- a/gcc/d/d-attribs.cc +++ b/gcc/d/d-attribs.cc @@ -852,7 +852,9 @@ parse_optimize_options (tree args) unsigned j = 1; for (unsigned i = 1; i < decoded_options_count; ++i) { - if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION)) + unsigned opt_index = decoded_options[i].opt_index; + if (opt_index >= cl_options_count + && ! (cl_options[opt_index].flags & CL_OPTIMIZATION)) { ret = false; warning (OPT_Wattributes,