Disable -Wstringop-overflow warning after checking code path of caller.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 13 Jun 2020 08:04:33 +0000 (10:04 +0200)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 13 Jun 2020 08:04:33 +0000 (10:04 +0200)
The warning that is disabled, only on this single line, has been
inspected and found to be not applicable; it is known that the size
of the buffer is safe.

libgfortran/ChangeLog:

2020-06-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR libfortran/95313
* io/write.c (ztoa_big): Disable -Wstringop-overflow for one
line.

gcc/testsuite/gfortran.dg/finalize_36.f90 [new file with mode: 0644]
libgfortran/io/write.c

diff --git a/gcc/testsuite/gfortran.dg/finalize_36.f90 b/gcc/testsuite/gfortran.dg/finalize_36.f90
new file mode 100644 (file)
index 0000000..432f547
--- /dev/null
@@ -0,0 +1,39 @@
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-original" }
+! PR 94109
+! This used to leak memory.  Test case by Antony Lewis.
+    module debug
+    implicit none
+
+    Type Tester
+        real, dimension(:), allocatable :: Dat, Dat2
+    end Type
+
+    Type TestType2
+        Type(Tester) :: T
+    end type TestType2
+
+    contains
+
+    subroutine Leaker
+    class(TestType2), pointer :: ActiveState
+    Type(Tester) :: Temp
+
+    allocate(Temp%Dat2(10000))
+
+    allocate(TestType2::ActiveState)
+    ActiveState%T = Temp
+    deallocate(ActiveState)
+
+    end subroutine
+
+    end module
+
+
+    program run
+    use debug
+
+    call Leaker()
+
+    end program
+! { dg-final { scan-tree-dump-times "__builtin_free\\ \\(ptr2" 4 "original" } }
index 9f02683a25c61388834f0872b54b6731ce168056..346615ed597a60517e01a30e17f7f5d0c72c9ced 100644 (file)
@@ -1178,7 +1178,15 @@ ztoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)
        }
     }
 
+  /* write_z, which calls ztoa_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";