opts-common.c (integral_argument): Set errno properly in one case.
authorRoman Zhuykov <zhroma@ispras.ru>
Fri, 29 Mar 2019 18:44:01 +0000 (18:44 +0000)
committerJeff Law <law@gcc.gnu.org>
Fri, 29 Mar 2019 18:44:01 +0000 (12:44 -0600)
    * opts-common.c (integral_argument): Set errno properly in one case.

    * gcc.dg/diag-sanity.c: New test.

From-SVN: r270022

gcc/ChangeLog
gcc/opts-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/diag-sanity.c [new file with mode: 0644]

index 76457ac956e12e37fe1329f52663e2937686c778..15b24087e28227676c5f1bfb83dd4e303e53137a 100644 (file)
@@ -1,3 +1,7 @@
+2019-03-29  Roman Zhuykov  <zhroma@ispras.ru>
+
+       * opts-common.c (integral_argument): Set errno properly in one case.
+
 2019-03-29  Martin Liska  <mliska@suse.cz>
 
        * doc/invoke.texi: Remove -Wchkp from documentation.
index edbb3ac9b6d04580afbdcc29c67b4601360108da..8456dcc697bbb3a0078afd00a948bfa3d558446d 100644 (file)
@@ -205,8 +205,10 @@ integral_argument (const char *arg, int *err, bool byte_size_suffix)
          value = strtoull (arg, &end, 0);
          if (*end)
            {
-             /* errno is most likely EINVAL here.  */
-             *err = errno;
+             if (errno)
+               *err = errno;
+             else
+               *err = EINVAL;
              return -1;
            }
 
index 960a86508b06dff26df5b7ae751fdef8b8bf1fc2..9d6743d725a810df264b0831c09f274bde027d15 100644 (file)
@@ -1,3 +1,7 @@
+2019-03-29  Roman Zhuykov  <zhroma@ispras.ru>
+
+       * gcc.dg/diag-sanity.c: New test.
+
 2019-03-29  Marek Polacek  <polacek@redhat.com>
 
        PR c++/89871
diff --git a/gcc/testsuite/gcc.dg/diag-sanity.c b/gcc/testsuite/gcc.dg/diag-sanity.c
new file mode 100644 (file)
index 0000000..5e58d96
--- /dev/null
@@ -0,0 +1,7 @@
+/* Verify that an invalid argument is diagnosed correcly.
+   { dg-do compile }
+   { dg-options "-fdiagnostics-minimum-margin-width=42xyz -flto-compression-level=2-O2" } */
+
+
+/* { dg-error "argument to '-fdiagnostics-minimum-margin-width=' should be a non-negative integer" "" { target *-*-* } 0 }
+   { dg-error "argument to '-flto-compression-level=' should be a non-negative integer" "" { target *-*-* } 0 } */