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

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
  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
  3 siblings, 0 replies; 10+ messages in thread
From: 1319 at bot dot ru @ 2004-03-23 22:23 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |3.3.4 3.4.0 3.5.0 tree-ssa
                   |                            |lno


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
  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 ` 1319 at bot dot ru
  2004-03-23 22:23 ` 1319 at bot dot ru
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: 1319 at bot dot ru @ 2004-03-23 22:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From 1319 at bot dot ru  2004-03-23 22:23 -------
Created an attachment (id=5984)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5984&action=view)
same patch generated by cvs diff


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
  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
  3 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-23 22:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-23 22:59 -------
Confirmed. Could you send your patch gcc-patches@gcc.gnu.org ___after___ reading http://
gcc.gnu.org/contribute.html.  Thanks.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|3.3.4 3.4.0 3.5.0 tree-ssa  |3.3.4 3.4.0 3.5.0 tree-ssa
                   |lno                         |lno 3.3.1 3.2.3 3.0.4
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-23 22:59:04
               date|                            |


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
  2004-03-23 22:19 [Bug preprocessor/14699] New: abort() in hashtable.c in approx_sqrt() with -fmem-report 1319 at bot dot ru
                   ` (2 preceding siblings ...)
  2004-03-23 22:59 ` pinskia at gcc dot gnu dot org
@ 2004-03-24  4:26 ` 1319 at bot dot ru
  3 siblings, 0 replies; 10+ messages in thread
From: 1319 at bot dot ru @ 2004-03-24  4:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From 1319 at bot dot ru  2004-03-24 04:26 -------
patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01961.html>

-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
       [not found] <20040323221847.14699.belyshev@lubercy.com>
                   ` (3 preceding siblings ...)
  2004-09-06 14:44 ` giovannibajo at libero dot it
@ 2004-09-07  8:08 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-07  8:08 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |3.5.0


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
       [not found] <20040323221847.14699.belyshev@lubercy.com>
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-06 14:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-09-06 14:44 -------
Fixed now, thakns Serge for the patch and Paolo for committing it.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
       [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
  4 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-09-06 13:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-09-06 13:22 -------
Subject: Bug 14699

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bonzini@gcc.gnu.org	2004-09-06 13:22:49

Modified files:
	libcpp         : ChangeLog symtab.c 

Log message:
	2004-09-06  Serge Belyshev  <belyshev@lubercy.com>
	
	PR preprocessor/14699
	* symtab.c (ht_dump_statistics): Change type of sum_of_squares
	from size_t to double.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/ChangeLog.diff?cvsroot=gcc&r1=1.24&r2=1.25
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/symtab.c.diff?cvsroot=gcc&r1=1.3&r2=1.4



-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
       [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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: belyshev at lubercy dot com @ 2004-06-26 15:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From belyshev at lubercy dot com  2004-06-26 14:08 -------
updated patch: http://gcc.gnu.org/ml/gcc-patches/2004-06/msg02184.html

-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug preprocessor/14699] abort() in hashtable.c in approx_sqrt() with -fmem-report
       [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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: belyshev at lubercy dot com @ 2004-05-04 16:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From belyshev at lubercy dot com  2004-05-04 16:56 -------
An updated patch here: http://gcc.gnu.org/ml/gcc-patches/2004-03/msg02049.html


2004-05-04  Serge Belyshev  <belyshev@lubercy.com>

	PR 14699
        * hashtable.c (ht_dump_statistics): Change type of sum_of_squares
        from size_t to double.

diff -u hashtable.c.~1.16.~ hashtable.c
--- hashtable.c.~1.16.~	2003-08-23 02:29:17.000000000 +0400
+++ hashtable.c	2004-03-25 01:37:01.998704560 +0300
@@ -228,8 +228,8 @@
 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 total_bytes, longest;
+  double exp_len, exp_len2, exp2_len, sum_of_squares;
   hashnode *p, *limit;
 
 #define SCALE(x) ((unsigned long) ((x) < 1024*10 \
@@ -248,7 +248,7 @@
 	size_t n = HT_LEN (*p);
 
 	total_bytes += n;
-	sum_of_squares += n * n;
+	sum_of_squares += (double) n * n;
 	if (n > longest)
 	  longest = n;
 	nids++;


Can anyone apply it as it was approved by Zack in
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg02117.html ?


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

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).