diff gcc/testsuite/gcc.dg/free-2.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/free-2.c	Fri Oct 27 22:46:09 2017 +0900
@@ -0,0 +1,26 @@
+/* PR c/36970 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+extern void free (void *);
+
+char *p, buf3[10], d;
+struct S { char a; int b; } *r;
+
+void foo (void)
+{
+  char buf[10], buf2[10], c;
+  static char buf4[10], e;
+  char *q = buf;
+  free (p);
+  free (q);	      /* At -O0 no warning is reported here.  */
+  free (buf2);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (&c);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (buf3);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (&d);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (buf4);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (&e);	      /* { dg-warning "attempt to free a non-heap object" } */
+  free (&r->a);
+  free ("abcd");      /* { dg-warning "attempt to free a non-heap object" } */
+  free (L"abcd");     /* { dg-warning "attempt to free a non-heap object" } */
+}