trans.c (Pragma_to_gnu): Replace linear search with call to find_opt and issue warnin...
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 2 Oct 2015 09:28:56 +0000 (09:28 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 2 Oct 2015 09:28:56 +0000 (09:28 +0000)
* gcc-interface/trans.c (Pragma_to_gnu) <Pragma_Warnings>: Replace
linear search with call to find_opt and issue warnings if the -W
switch is not appropriate.

From-SVN: r228379

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/warn13.adb [new file with mode: 0644]

index 0e5d83abddfa914780c1740e1ebe573640144f3a..a4b159ddd020619e6caa8a95ba8e2f8f9d41addf 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-02  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/trans.c (Pragma_to_gnu) <Pragma_Warnings>: Replace
+       linear search with call to find_opt and issue warnings if the -W
+       switch is not appropriate.
+
 2015-10-02  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/ada-tree.h (DECL_RESTRICTED_ALIASING_P): New flag.
index 1da381b9cc67b139d0fcad87c9698ca52fa88ddb..3252ea2732e7c4dc345fe29df0c1053c778c2b8f 100644 (file)
@@ -1442,21 +1442,28 @@ Pragma_to_gnu (Node_Id gnat_node)
          gcc_unreachable ();
 
        /* This is the same implementation as in the C family of compilers.  */
+       const unsigned int lang_mask = CL_Ada | CL_COMMON;
        if (Present (gnat_expr))
          {
            tree gnu_expr = gnat_to_gnu (gnat_expr);
-           const char *opt_string = TREE_STRING_POINTER (gnu_expr);
+           const char *option_string = TREE_STRING_POINTER (gnu_expr);
            const int len = TREE_STRING_LENGTH (gnu_expr);
-           if (len < 3 || opt_string[0] != '-' || opt_string[1] != 'W')
+           if (len < 3 || option_string[0] != '-' || option_string[1] != 'W')
              break;
-           for (option_index = 0;
-                option_index < cl_options_count;
-                option_index++)
-             if (strcmp (cl_options[option_index].opt_text, opt_string) == 0)
+           option_index = find_opt (option_string + 1, lang_mask);
+           if (option_index == OPT_SPECIAL_unknown)
+             {
+               post_error ("?unknown -W switch", gnat_node);
                break;
-           if (option_index == cl_options_count)
+             }
+           else if (!(cl_options[option_index].flags & CL_WARNING))
+             {
+               post_error ("?-W switch does not control warning", gnat_node);
+               break;
+             }
+           else if (!(cl_options[option_index].flags & lang_mask))
              {
-               post_error ("unknown -W switch", gnat_node);
+               post_error ("?-W switch not valid for Ada", gnat_node);
                break;
              }
          }
@@ -1465,7 +1472,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 
        set_default_handlers (&handlers);
        control_warning_option (option_index, (int) kind, imply, location,
-                               CL_Ada, &handlers, &global_options,
+                               lang_mask, &handlers, &global_options,
                                &global_options_set, global_dc);
       }
       break;
index ae4f5aa4efd2915d1d3dbd787fcb7dd339ad9b79..169c0c4e218b117632dd62d45420d5ee96167119 100644 (file)
@@ -1,3 +1,7 @@
+2015-10-02  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/warn13.adb: New test.
+
 2015-10-02  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/vect15.ad[sb]: New test.
diff --git a/gcc/testsuite/gnat.dg/warn13.adb b/gcc/testsuite/gnat.dg/warn13.adb
new file mode 100644 (file)
index 0000000..2a9c4e3
--- /dev/null
@@ -0,0 +1,11 @@
+-- { dg-compile }
+
+procedure Warn13 is
+
+  pragma Warnings ("-Wbogus");  -- { dg-warning "unknown" }
+  pragma Warnings ("-Werror");  -- { dg-warning "does not control warning" }
+  pragma Warnings ("-Wformat"); -- { dg-warning "switch not valid for Ada" }
+
+begin
+  null;
+end;