This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tree-ssa libmudflap] more tests, heuristic tweaks


Hi -

The following patch adds more tests to the mudflap testsuite.
Two of them stress arrays-in variable-length-structs, the other
is the stratcliff str*/mem* test from glibc.  There is also some
more experimentation for adapting the object lookup cache, but
this will need more work.


+2002-10-16  Frank Ch. Eigler  <fche@redhat.com>
+
+	* test/fail19-frag.c, pass24-frag.c, pass-stratcliff.c: New tests.
+	* Makefile.am: Run them.  Install mf-runtime.h.
+	* Makefile.in: Regenerated.
+	* mf-hooks.c: Add some markers for more missing functions.
+	* mf-runtime.c (__mf_adapt_cache): Experiment with a utilization-based
+	statistic to tune tune cache size (mask).
+

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/Makefile.am,v
retrieving revision 1.1.2.14
diff -u -p -r1.1.2.14 Makefile.am
--- Makefile.am	1 Oct 2002 19:52:55 -0000	1.1.2.14
+++ Makefile.am	16 Oct 2002 18:45:24 -0000
@@ -12,12 +12,12 @@ TESTS_ENVIRONMENT = LD_LIBRARY_PATH='.li
 TESTS = test/fail1.x test/fail2.x test/fail3.x test/fail4.x test/fail5.x \
  test/fail6.x test/fail7.x test/fail8.x test/fail9.x test/fail10.x \
  test/fail11.x test/fail12.x test/fail13.x test/fail14.x test/fail15.x \
- test/fail16.x test/fail17.x test/fail18.x \
+ test/fail16.x test/fail17.x test/fail18.x test/fail19.x \
  test/pass1.x test/pass2.x test/pass3.x test/pass4.x test/pass5.x \
  test/pass6.x test/pass7.x test/pass8.x test/pass9.x test/pass10.x \
  test/pass11.x test/pass12.x test/pass13.x test/pass14.x test/pass15.x \
  test/pass16.x test/pass17.x test/pass18.x test/pass19.x test/pass20.x \
- test/pass21.x test/pass22.x test/pass23.x
+ test/pass21.x test/pass22.x test/pass23.x test/pass24.x test/pass-stratcliff.x
 
 test/%.c: test/%-frag.c test/mf-driver.c
 	@mkdir -p test
@@ -52,9 +52,10 @@ clean-tests:
 
 # Cross compiler and multilib support.
 lib_LTLIBRARIES = libmudflap.la
+include_HEADERS = mf-runtime.h
 
 CFLAGS = -O2 -g -freorder-blocks
-AM_CFLAGS = -fno-builtin -fno-builtin-alloca -ansi -Wall -D__NO_STRING_INLINES
+AM_CFLAGS = -ansi -Wall
 
 # Use common includes from acinclude.m4/LIBMUDFLAP_EXPORT_INCLUDES
 LIBMUDFLAP_INCLUDES =
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/Makefile.in,v
retrieving revision 1.1.2.14
diff -u -p -r1.1.2.14 Makefile.in
--- Makefile.in	1 Oct 2002 19:52:55 -0000	1.1.2.14
+++ Makefile.in	16 Oct 2002 18:45:25 -0000
@@ -1,6 +1,6 @@
-# Makefile.in generated automatically by automake 1.4 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
 
-# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -85,7 +85,15 @@ MAINT_CHARSET = latin1
 
 TESTS_ENVIRONMENT = LD_LIBRARY_PATH='.libs:../../gcc' MUDFLAP_OPTIONS='-mode-check -viol-abort -no-heur-proc-map'
 
-TESTS = test/fail1.x test/fail2.x test/fail3.x test/fail4.x test/fail5.x  test/fail6.x test/fail7.x test/fail8.x test/fail9.x test/fail10.x  test/fail11.x test/fail12.x test/fail13.x test/fail14.x test/fail15.x  test/fail16.x test/fail17.x test/fail18.x  test/pass1.x test/pass2.x test/pass3.x test/pass4.x test/pass5.x  test/pass6.x test/pass7.x test/pass8.x test/pass9.x test/pass10.x  test/pass11.x test/pass12.x test/pass13.x test/pass14.x test/pass15.x  test/pass16.x test/pass17.x test/pass18.x test/pass19.x test/pass20.x  test/pass21.x test/pass22.x test/pass23.x
+TESTS = test/fail1.x test/fail2.x test/fail3.x test/fail4.x test/fail5.x \
+ test/fail6.x test/fail7.x test/fail8.x test/fail9.x test/fail10.x \
+ test/fail11.x test/fail12.x test/fail13.x test/fail14.x test/fail15.x \
+ test/fail16.x test/fail17.x test/fail18.x test/fail19.x \
+ test/pass1.x test/pass2.x test/pass3.x test/pass4.x test/pass5.x \
+ test/pass6.x test/pass7.x test/pass8.x test/pass9.x test/pass10.x \
+ test/pass11.x test/pass12.x test/pass13.x test/pass14.x test/pass15.x \
+ test/pass16.x test/pass17.x test/pass18.x test/pass19.x test/pass20.x \
+ test/pass21.x test/pass22.x test/pass23.x test/pass24.x test/pass-stratcliff.x
 
 
 # Various possibilities
@@ -96,18 +104,56 @@ TESTFLAGS = -rdynamic
 
 # Cross compiler and multilib support.
 lib_LTLIBRARIES = libmudflap.la
+include_HEADERS = mf-runtime.h
 
 CFLAGS = -O2 -g -freorder-blocks
-AM_CFLAGS = -fno-builtin -fno-builtin-alloca -ansi -Wall -D__NO_STRING_INLINES
+AM_CFLAGS = -ansi -Wall
 
 # Use common includes from acinclude.m4/LIBMUDFLAP_EXPORT_INCLUDES
 LIBMUDFLAP_INCLUDES = 
 TOPLEVEL_INCLUDES = 
 
-libmudflap_la_SOURCES =  	mf-runtime.c 	mf-heuristics.c
-
-
-HOOKOBJS =   malloc-hook.lo  free-hook.lo  calloc-hook.lo  realloc-hook.lo  memcpy-hook.lo  memmove-hook.lo  memset-hook.lo  memcmp-hook.lo  memchr-hook.lo  memrchr-hook.lo  strcpy-hook.lo  strncpy-hook.lo  strcat-hook.lo  strncat-hook.lo  strcmp-hook.lo  strcasecmp-hook.lo  strncmp-hook.lo  strncasecmp-hook.lo  strdup-hook.lo  strndup-hook.lo  strchr-hook.lo  strrchr-hook.lo  strstr-hook.lo  memmem-hook.lo  strlen-hook.lo  strnlen-hook.lo  bzero-hook.lo  bcopy-hook.lo  bcmp-hook.lo  index-hook.lo  rindex-hook.lo  dlopen-hook.lo  mmap-hook.lo  munmap-hook.lo  alloca-hook.lo
+libmudflap_la_SOURCES = \
+	mf-runtime.c \
+	mf-heuristics.c
+
+
+HOOKOBJS = \
+ malloc-hook.lo \
+ free-hook.lo \
+ calloc-hook.lo \
+ realloc-hook.lo \
+ memcpy-hook.lo \
+ memmove-hook.lo \
+ memset-hook.lo \
+ memcmp-hook.lo \
+ memchr-hook.lo \
+ memrchr-hook.lo \
+ strcpy-hook.lo \
+ strncpy-hook.lo \
+ strcat-hook.lo \
+ strncat-hook.lo \
+ strcmp-hook.lo \
+ strcasecmp-hook.lo \
+ strncmp-hook.lo \
+ strncasecmp-hook.lo \
+ strdup-hook.lo \
+ strndup-hook.lo \
+ strchr-hook.lo \
+ strrchr-hook.lo \
+ strstr-hook.lo \
+ memmem-hook.lo \
+ strlen-hook.lo \
+ strnlen-hook.lo \
+ bzero-hook.lo \
+ bcopy-hook.lo \
+ bcmp-hook.lo \
+ index-hook.lo \
+ rindex-hook.lo \
+ dlopen-hook.lo \
+ mmap-hook.lo \
+ munmap-hook.lo \
+ alloca-hook.lo
 
 
 libmudflap_la_LDFLAGS = 
@@ -129,6 +175,8 @@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
 LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+HEADERS =  $(include_HEADERS)
+
 DIST_COMMON =  ./stamp-h.in ChangeLog Makefile.am Makefile.in aclocal.m4 \
 config.h.in configure configure.in
 
@@ -252,6 +300,21 @@ maintainer-clean-libtool:
 libmudflap.la: $(libmudflap_la_OBJECTS) $(libmudflap_la_DEPENDENCIES)
 	$(LINK) -rpath $(libdir) $(libmudflap_la_LDFLAGS) $(libmudflap_la_OBJECTS) $(libmudflap_la_LIBADD) $(LIBS)
 
+install-includeHEADERS: $(include_HEADERS)
+	@$(NORMAL_INSTALL)
+	$(mkinstalldirs) $(DESTDIR)$(includedir)
+	@list='$(include_HEADERS)'; for p in $$list; do \
+	  if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
+	  echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
+	  $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
+	done
+
+uninstall-includeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	list='$(include_HEADERS)'; for p in $$list; do \
+	  rm -f $(DESTDIR)$(includedir)/$$p; \
+	done
+
 tags: TAGS
 
 ID: $(HEADERS) $(SOURCES) $(LISP)
@@ -371,20 +434,20 @@ all-recursive-am: config.h
 install-exec-am: install-libLTLIBRARIES
 install-exec: install-exec-am
 
-install-data-am:
+install-data-am: install-includeHEADERS
 install-data: install-data-am
 
 install-am: all-am
 	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 install: install-am
-uninstall-am: uninstall-libLTLIBRARIES
+uninstall-am: uninstall-libLTLIBRARIES uninstall-includeHEADERS
 uninstall: uninstall-am
-all-am: Makefile $(LTLIBRARIES) config.h
+all-am: Makefile $(LTLIBRARIES) $(HEADERS) config.h
 all-redirect: all-am
 install-strip:
 	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
 installdirs:
-	$(mkinstalldirs)  $(DESTDIR)$(libdir)
+	$(mkinstalldirs)  $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
 
 
 mostlyclean-generic:
@@ -432,14 +495,15 @@ clean-libLTLIBRARIES maintainer-clean-li
 uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
 distclean-compile clean-compile maintainer-clean-compile \
 mostlyclean-libtool distclean-libtool clean-libtool \
-maintainer-clean-libtool tags mostlyclean-tags distclean-tags \
-clean-tags maintainer-clean-tags distdir check-TESTS info-am info \
-dvi-am dvi check check-am installcheck-am installcheck install-info-am \
-install-info all-recursive-am install-exec-am install-exec \
-install-data-am install-data install-am install uninstall-am uninstall \
-all-redirect all-am all installdirs mostlyclean-generic \
-distclean-generic clean-generic maintainer-clean-generic clean \
-mostlyclean distclean maintainer-clean
+maintainer-clean-libtool uninstall-includeHEADERS \
+install-includeHEADERS tags mostlyclean-tags distclean-tags clean-tags \
+maintainer-clean-tags distdir check-TESTS info-am info dvi-am dvi check \
+check-am installcheck-am installcheck install-info-am install-info \
+all-recursive-am install-exec-am install-exec install-data-am \
+install-data install-am install uninstall-am uninstall all-redirect \
+all-am all installdirs mostlyclean-generic distclean-generic \
+clean-generic maintainer-clean-generic clean mostlyclean distclean \
+maintainer-clean
 
 
 test/%.c: test/%-frag.c test/mf-driver.c
Index: mf-hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-hooks.c,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 mf-hooks.c
--- mf-hooks.c	1 Oct 2002 19:52:55 -0000	1.1.2.17
+++ mf-hooks.c	16 Oct 2002 18:45:25 -0000
@@ -844,7 +844,10 @@ WRAPPER(char *, rindex, const char *s, i
 }
 #endif
 
-/* *printf,*scanf */
+/* XXX:  stpcpy, memccpy */
+
+
+/* XXX: *printf,*scanf */
 
 
 
Index: mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-runtime.c,v
retrieving revision 1.1.2.18
diff -u -p -r1.1.2.18 mf-runtime.c
--- mf-runtime.c	1 Oct 2002 19:52:55 -0000	1.1.2.18
+++ mf-runtime.c	16 Oct 2002 18:45:26 -0000
@@ -1195,27 +1195,44 @@ __mf_adapt_cache ()
   uintptr_t new_mask;
   uintptr_t shifted;
   unsigned char new_shift;
-  unsigned num_buckets;
+  double cache_utilization;
+  unsigned i;
 
   memset (&s, 0, sizeof (s));
-  __mf_tree_analyze (__mf_object_root, & s);
-  assert (s.obj_count > 0);
-  assert (s.live_obj_count > 0);
-  assert (s.total_weight > 0.0);
+  if (__mf_object_root)
+    __mf_tree_analyze (__mf_object_root, & s);
+
+  /* Maybe we're dealing with funny aging/adaptation parameters, or an
+     empty tree.  Just leave the cache alone in such cases, rather
+     than risk dying by division-by-zero.  */
+  if (! (s.obj_count > 0) && (s.live_obj_count > 0) && (s.total_weight > 0.0))
+    return;
+
   avg_weight = s.total_weight / s.live_obj_count;
   weighted_avg_size = (uintptr_t) (s.weighted_size / s.total_weight);
   avg_size = (uintptr_t) (s.total_size / s.obj_count);
   if (avg_size == 0) avg_size = 1;
 
-  /* Find a good new cache size. */
-  num_buckets = 1.5 * s.obj_count * (weighted_avg_size / avg_size);
-  for (new_mask=0xff;
-       new_mask < LOOKUP_CACHE_SIZE_MAX;
-       new_mask = new_mask * 2 + 1)
-    if (num_buckets < new_mask+1)
-      break;
+  /* Count number of used buckets.  */
+  cache_utilization = 0.0;
+  for (i = 0; i < (1 + __mf_lc_mask); i++)
+    if (__mf_lookup_cache[i].low != 0 || __mf_lookup_cache[i].high != 0)
+      cache_utilization += 1.0;
+  cache_utilization /= (1 + __mf_lc_mask);
+  if (cache_utilization < 0.5)
+    new_mask = __mf_lc_mask >> 1;
+  else if (cache_utilization > 0.7)
+    new_mask = (__mf_lc_mask << 1) | 1;
+  else
+    new_mask = __mf_lc_mask;
+  
+  new_mask |= 0x3ff; /* impose a practical minimum */
   new_mask &= (LOOKUP_CACHE_SIZE_MAX - 1);
 
+#if 0 /* giving up on heuristics? */
+  new_mask = __mf_lc_mask;
+#endif
+
   /* Find a good new shift amount.  Make it big enough that the
      popular objects take up 1-2 "cache lines".  The 24 in the
      next line imposes a practical 16MB upper limit on the cache line
@@ -1227,11 +1244,11 @@ __mf_adapt_cache ()
       break;
     
   VERBOSE_TRACE ("mf: adapt cache %u/%u/%u/%.0f/%.0f => "
-		 "%.0f/%lu/%lu => "
+		 "%.0f/%lu/%lu/%.0f%% => "
 		 "%08lx/%u\n",
 		 s.obj_count, s.live_obj_count, s.total_size,
 		 s.total_weight, s.weighted_size,
-		 avg_weight, weighted_avg_size, avg_size,
+		 avg_weight, weighted_avg_size, avg_size, (cache_utilization*100.0),
 		 new_mask, new_shift);
 
   /* We should reinitialize cache if its parameters have changed.  */
Index: test/fail19-frag.c
===================================================================
RCS file: test/fail19-frag.c
diff -N test/fail19-frag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/fail19-frag.c	16 Oct 2002 18:45:26 -0000
@@ -0,0 +1,7 @@
+struct foo {
+  int bar [10];
+};
+
+struct foo *k = (void *) malloc (2 * sizeof(int));
+k->bar[5] = 9;
+free (k);
Index: test/pass-stratcliff.c
===================================================================
RCS file: test/pass-stratcliff.c
diff -N test/pass-stratcliff.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/pass-stratcliff.c	16 Oct 2002 18:45:26 -0000
@@ -0,0 +1,312 @@
+/* Test for string function add boundaries of usable memory.
+   Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#define _GNU_SOURCE 1
+
+/* Make sure we don't test the optimized inline functions if we want to
+   test the real implementation.  */
+#undef __USE_STRING_INLINES
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+int
+main (int argc, char *argv[])
+{
+  int size = sysconf (_SC_PAGESIZE);
+  char *adr, *dest;
+  int result = 0;
+
+  adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
+		       MAP_PRIVATE | MAP_ANON, -1, 0);
+  dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_ANON, -1, 0);
+  if (adr == MAP_FAILED || dest == MAP_FAILED)
+    {
+      if (errno == ENOSYS)
+        puts ("No test, mmap not available.");
+      else
+        {
+          printf ("mmap failed: %m");
+          result = 1;
+        }
+    }
+  else
+    {
+      int inner, middle, outer;
+
+      mprotect(adr, size, PROT_NONE);
+      mprotect(adr + 2 * size, size, PROT_NONE);
+      adr += size;
+
+      mprotect(dest, size, PROT_NONE);
+      mprotect(dest + 2 * size, size, PROT_NONE);
+      dest += size;
+
+      memset (adr, 'T', size);
+
+      /* strlen test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+          for (inner = MAX (outer, size - 64); inner < size; ++inner)
+	    {
+	      adr[inner] = '\0';
+
+	      if (strlen (&adr[outer]) != (size_t) (inner - outer))
+		{
+		  printf ("strlen flunked for outer = %d, inner = %d\n",
+			  outer, inner);
+		  result = 1;
+		}
+
+	      adr[inner] = 'T';
+	    }
+        }
+
+      /* strchr test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+	  for (middle = MAX (outer, size - 64); middle < size; ++middle)
+	    {
+	      for (inner = middle; inner < size; ++inner)
+		{
+		  char *cp;
+		  adr[middle] = 'V';
+		  adr[inner] = '\0';
+
+		  cp = strchr (&adr[outer], 'V');
+
+		  if ((inner == middle && cp != NULL)
+		      || (inner != middle
+			  && (cp - &adr[outer]) != middle - outer))
+		    {
+		      printf ("strchr flunked for outer = %d, middle = %d, "
+			      "inner = %d\n", outer, middle, inner);
+		      result = 1;
+		    }
+
+		  adr[inner] = 'T';
+		  adr[middle] = 'T';
+		}
+	    }
+        }
+
+      /* Special test.  */
+      adr[size - 1] = '\0';
+      if (strchr (&adr[size - 1], '\n') != NULL)
+	{
+	  puts ("strchr flunked for test of empty string at end of page");
+	  result = 1;
+	}
+
+      /* strrchr test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+	  for (middle = MAX (outer, size - 64); middle < size; ++middle)
+	    {
+	      for (inner = middle; inner < size; ++inner)
+		{
+		  char *cp;
+		  adr[middle] = 'V';
+		  adr[inner] = '\0';
+
+		  cp = strrchr (&adr[outer], 'V');
+
+		  if ((inner == middle && cp != NULL)
+		      || (inner != middle
+			  && (cp - &adr[outer]) != middle - outer))
+		    {
+		      printf ("strrchr flunked for outer = %d, middle = %d, "
+			      "inner = %d\n", outer, middle, inner);
+		      result = 1;
+		    }
+
+		  adr[inner] = 'T';
+		  adr[middle] = 'T';
+		}
+	    }
+        }
+
+      /* rawmemchr test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+	  for (middle = MAX (outer, size - 64); middle < size; ++middle)
+	    {
+	      char *cp;
+	      adr[middle] = 'V';
+
+	      cp = rawmemchr (&adr[outer], 'V');
+
+	      if (cp - &adr[outer] != middle - outer)
+		{
+		  printf ("rawmemchr flunked for outer = %d, middle = %d\n",
+			  outer, middle);
+		  result = 1;
+		}
+
+	      adr[middle] = 'T';
+	    }
+        }
+
+      /* strcpy test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+          for (inner = MAX (outer, size - 64); inner < size; ++inner)
+	    {
+	      adr[inner] = '\0';
+
+	      if (strcpy (dest, &adr[outer]) != dest
+		  || strlen (dest) != (size_t) (inner - outer))
+		{
+		  printf ("strcpy flunked for outer = %d, inner = %d\n",
+			  outer, inner);
+		  result = 1;
+		}
+
+	      adr[inner] = 'T';
+	    }
+        }
+
+      /* strncpy tests */
+      adr[size-1] = 'T';
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+	{
+	  size_t len;
+
+	  for (len = 0; len < size - outer; ++len)
+	    {
+	      if (strncpy (dest, &adr[outer], len) != dest
+		  || memcmp (dest, &adr[outer], len) != 0)
+		{
+		  printf ("outer strncpy flunked for outer = %d, len = %Zd\n",
+			  outer, len);
+		  result = 1;
+		}
+	    }
+        }
+      adr[size-1] = '\0';
+
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+          for (inner = MAX (outer, size - 64); inner < size; ++inner)
+	    {
+	      size_t len;
+
+	      adr[inner] = '\0';
+
+	      for (len = 0; len < size - outer + 64; ++len)
+		{
+		  if (strncpy (dest, &adr[outer], len) != dest
+		      || memcmp (dest, &adr[outer],
+				 MIN (inner - outer, len)) != 0
+		      || (inner - outer < len
+			  && strlen (dest) != (inner - outer)))
+		    {
+		      printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n",
+			      outer, inner, len);
+		      result = 1;
+		    }
+		  if (strncpy (dest + 1, &adr[outer], len) != dest + 1
+		      || memcmp (dest + 1, &adr[outer],
+				 MIN (inner - outer, len)) != 0
+		      || (inner - outer < len
+			  && strlen (dest + 1) != (inner - outer)))
+		    {
+		      printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n",
+			      outer, inner, len);
+		      result = 1;
+		    }
+		}
+
+	      adr[inner] = 'T';
+	    }
+        }
+
+      /* stpcpy test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+          for (inner = MAX (outer, size - 64); inner < size; ++inner)
+	    {
+	      adr[inner] = '\0';
+
+	      if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer)
+		{
+		  printf ("stpcpy flunked for outer = %d, inner = %d\n",
+			  outer, inner);
+		  result = 1;
+		}
+
+	      adr[inner] = 'T';
+	    }
+        }
+
+      /* stpncpy test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+        {
+          for (middle = MAX (outer, size - 64); middle < size; ++middle)
+	    {
+	      adr[middle] = '\0';
+
+	      for (inner = 0; inner < size - outer; ++ inner)
+		{
+		  if ((stpncpy (dest, &adr[outer], inner) - dest)
+		      != MIN (inner, middle - outer))
+		    {
+		      printf ("stpncpy flunked for outer = %d, middle = %d, "
+			      "inner = %d\n", outer, middle, inner);
+		      result = 1;
+		    }
+		}
+
+	      adr[middle] = 'T';
+	    }
+        }
+
+      /* memcpy test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+	for (inner = 0; inner < size - outer; ++inner)
+	  if (memcpy (dest, &adr[outer], inner) !=  dest)
+	    {
+	      printf ("memcpy flunked for outer = %d, inner = %d\n",
+		      outer, inner);
+	      result = 1;
+	    }
+
+      /* mempcpy test */
+      for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+	for (inner = 0; inner < size - outer; ++inner)
+	  if (mempcpy (dest, &adr[outer], inner) !=  dest + inner)
+	    {
+	      printf ("mempcpy flunked for outer = %d, inner = %d\n",
+		      outer, inner);
+	      result = 1;
+	    }
+    }
+
+  return result;
+}
Index: test/pass24-frag.c
===================================================================
RCS file: test/pass24-frag.c
diff -N test/pass24-frag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/pass24-frag.c	16 Oct 2002 18:45:26 -0000
@@ -0,0 +1,11 @@
+struct foo {
+  int zoo;
+  int bar [10];
+  float baz;
+};
+
+#define offsetof(S,F) (& (((S *) 0)->F))
+
+struct foo *k = (void *) malloc (offsetof (struct foo, bar[4]));
+k->bar[1] = 9;
+free (k);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]