public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/14699] New: abort() in hashtable.c in approx_sqrt() with -fmem-report
@ 2004-03-23 22:19 1319 at bot dot ru
  2004-03-23 22:23 ` [Bug preprocessor/14699] " 1319 at bot dot ru
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: 1319 at bot dot ru @ 2004-03-23 22:19 UTC (permalink / raw)
  To: gcc-bugs

$ echo 'int ' > bug.c
$ tr '\0' a < /dev/zero | head -c 65536 >> bug.c
$ echo ';' >> bug.c
$ gcc-3.3 -S -fmem-report bug.c

Tree                 Number            Bytes    % Total
Total                     0               0 

RTX                  Number            Bytes    % Total
Total                     0               0 

Size   Allocated        Used    Overhead
8           8192        7824         184 
16          4096          64          60 
32          8192        5952          88 
64            36k         33k        324 
256         4096        1792          28 
512           28k         26k        196 
1024        8192        7168          56 
112           84k         80k        672 
20            16k         12k        208 
12          8192        5976         136 
44          4096         528          36 
Total        208k        181k       1988 

String pool
entries         532
identifiers     532 (100.00%)
slots           16384
bytes           69k (2353  overhead)
table size      64k
coll/search     0.0182
ins/search      0.8061
bug.c:2: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


The bug is actually in function ht_dump_statistics() in very broken code that
calculates average entry size deviation. The code is broken because it does not
takes into account 32 bit wide size_t (sum_of_squares += n * n and n here >=
65536), and it calculates standart deviation of entry size using wrong formula.

Here is a patch (against 3_4-branch or mainline):

diff -u hashtable.c.~1.16.~ hashtable.c
--- hashtable.c.~1.16.~	2003-08-23 02:29:17.000000000 +0400
+++ hashtable.c	2004-03-24 00:59:56.975755952 +0300
@@ -228,11 +228,11 @@
 ht_dump_statistics (hash_table *table)
 {
   size_t nelts, nids, overhead, headers;
-  size_t total_bytes, longest, sum_of_squares;
-  double exp_len, exp_len2, exp2_len;
+  size_t longest;
+  double total_bytes, sum_of_squares, exp2_sd;
   hashnode *p, *limit;
 
-#define SCALE(x) ((unsigned long) ((x) < 1024*10 \
+#define SCALE(x) (((x) < 1024*10 \
 		  ? (x) \
 		  : ((x) < 1024*1024*10 \
 		     ? (x) / 1024 \
@@ -247,16 +247,19 @@
       {
 	size_t n = HT_LEN (*p);
 
-	total_bytes += n;
-	sum_of_squares += n * n;
+	total_bytes += (double) n;
+	sum_of_squares += (double) n * (double) n;
 	if (n > longest)
 	  longest = n;
 	nids++;
       }
   while (++p < limit);
-
+  
+  exp2_sd = (sum_of_squares - total_bytes * total_bytes / nids)
+	  / (double) (nids - 1);
+  
   nelts = table->nelements;
-  overhead = obstack_memory_used (&table->stack) - total_bytes;
+  overhead = obstack_memory_used (&table->stack) - (size_t) total_bytes;
   headers = table->nslots * sizeof (hashnode);
 
   fprintf (stderr, "\nString pool\nentries\t\t%lu\n",
@@ -265,22 +268,17 @@
 	   (unsigned long) nids, nids * 100.0 / nelts);
   fprintf (stderr, "slots\t\t%lu\n",
 	   (unsigned long) table->nslots);
-  fprintf (stderr, "bytes\t\t%lu%c (%lu%c overhead)\n",
+  fprintf (stderr, "bytes\t\t%.0f%c (%lu%c overhead)\n",
 	   SCALE (total_bytes), LABEL (total_bytes),
-	   SCALE (overhead), LABEL (overhead));
+	   (unsigned long) SCALE (overhead), LABEL (overhead));
   fprintf (stderr, "table size\t%lu%c\n",
-	   SCALE (headers), LABEL (headers));
-
-  exp_len = (double)total_bytes / (double)nelts;
-  exp2_len = exp_len * exp_len;
-  exp_len2 = (double) sum_of_squares / (double) nelts;
-
+	   (unsigned long) SCALE (headers), LABEL (headers));
   fprintf (stderr, "coll/search\t%.4f\n",
 	   (double) table->collisions / (double) table->searches);
   fprintf (stderr, "ins/search\t%.4f\n",
 	   (double) nelts / (double) table->searches);
   fprintf (stderr, "avg. entry\t%.2f bytes (+/- %.2f)\n",
-	   exp_len, approx_sqrt (exp_len2 - exp2_len));
+	   total_bytes / nids, approx_sqrt (exp2_sd));
   fprintf (stderr, "longest entry\t%lu\n",
 	   (unsigned long) longest);
 #undef SCALE

-- 
           Summary: abort() in hashtable.c in approx_sqrt() with -fmem-
                    report
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: 1319 at bot dot ru
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14699


^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <20040323221847.14699.belyshev@lubercy.com>]

end of thread, other threads:[~2004-09-07  8:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-23 22:19 [Bug preprocessor/14699] New: abort() in hashtable.c in approx_sqrt() with -fmem-report 1319 at bot dot ru
2004-03-23 22:23 ` [Bug preprocessor/14699] " 1319 at bot dot ru
2004-03-23 22:23 ` 1319 at bot dot ru
2004-03-23 22:59 ` pinskia at gcc dot gnu dot org
2004-03-24  4:26 ` 1319 at bot dot ru
     [not found] <20040323221847.14699.belyshev@lubercy.com>
2004-05-04 16:56 ` belyshev at lubercy dot com
2004-06-26 15:12 ` belyshev at lubercy dot com
2004-09-06 13:23 ` cvs-commit at gcc dot gnu dot org
2004-09-06 14:44 ` giovannibajo at libero dot it
2004-09-07  8:08 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).