]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgfortran: Use __builtin_unreachable() not -Wno-stringop-overflow to silence warning
authorTobias Burnus <tobias@codesourcery.com>
Thu, 28 Sep 2023 11:06:13 +0000 (13:06 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 28 Sep 2023 11:06:13 +0000 (13:06 +0200)
The only caller of write_z is formatted_transfer_scalar_write that passes
kind to 'len'; in turn, write_z is the only caller of xtoa_big, passing on
its 'len'.  The kind is passed as is, except for GFC_REAL_17 for which
len = 16 is used.

libgfortran/
* io/write.c (xtoa_big): Change a 'GCC diagnostic ignored
"-Wstringop-overflow"' to an assumption (via __builtin_unreachable).t

libgfortran/io/write.c

index 5d47a6d25f7839f28745e6df6e790b388f69dd23..00c8fd2e288e982e081a63479f982f1917ad951c 100644 (file)
@@ -1179,6 +1179,15 @@ xtoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)
   uint8_t h, l;
   int i;
 
+  /* write_z, which calls xtoa_big, is called from transfer.c,
+     formatted_transfer_scalar_write.  There it is passed the kind as
+     'len' argument, which means a maximum of 16.  The buffer is large
+     enough, but the compiler does not know that, so shut up the
+     warning here.  */
+
+  if (len > 16)
+    __builtin_unreachable ();
+
   q = buffer;
 
   if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -1212,15 +1221,7 @@ xtoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)
        }
     }
 
-  /* write_z, which calls xtoa_big, is called from transfer.c,
-     formatted_transfer_scalar_write.  There it is passed the kind as
-     argument, which means a maximum of 16.  The buffer is large
-     enough, but the compiler does not know that, so shut up the
-     warning here.  */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wstringop-overflow"
   *q = '\0';
-#pragma GCC diagnostic pop
 
   if (*n == 0)
     return "0";