]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: Fix option check in handle_pragma_diagnostic [PR106252]
authorLewis Hyatt <lhyatt@gmail.com>
Mon, 11 Jul 2022 12:12:33 +0000 (08:12 -0400)
committerLewis Hyatt <lhyatt@gmail.com>
Mon, 11 Jul 2022 12:42:39 +0000 (08:42 -0400)
In r13-1544, handle_pragma_diagnostic was refactored to support processing
early pragmas. During that process the part looking up option arguments was
inadvertenly moved too early, prior to checking the option was valid, causing
PR106252. Fixed by moving the check back where it goes.

gcc/c-family/ChangeLog:

PR preprocessor/106252
* c-pragma.cc (handle_pragma_diagnostic_impl): Don't look up the
option argument prior to verifying the option was found.

gcc/c-family/c-pragma.cc

index 62bce2ed0f586d4855ec40756b82c5c2f099c974..789719e6e6af5d92c4765edc54505f64b0d37c70 100644 (file)
@@ -1009,10 +1009,6 @@ handle_pragma_diagnostic_impl ()
   if (early && !c_option_is_from_cpp_diagnostics (option_index))
     return;
 
-  const char *arg = NULL;
-  if (cl_options[option_index].flags & CL_JOINED)
-    arg = data.option_str + 1 + cl_options[option_index].opt_len;
-
   if (option_index == OPT_SPECIAL_unknown)
     {
       if (want_diagnostics)
@@ -1052,6 +1048,10 @@ handle_pragma_diagnostic_impl ()
       return;
     }
 
+  const char *arg = NULL;
+  if (cl_options[option_index].flags & CL_JOINED)
+    arg = data.option_str + 1 + cl_options[option_index].opt_len;
+
   struct cl_option_handlers handlers;
   set_default_handlers (&handlers, NULL);
   /* FIXME: input_location isn't the best location here, but it is