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]

Bug fixes for timevar.c


This patch fixes some obscure bugs in timevar.c which cause
get_run_time() not to do what it's documented to do, and in fact to
crash horribly if you run it when the timing variable stack is empty.
You can reproduce the problem by compiling any C++ source file with
-fstats; with the present tree, you'll get a segmentation fault in
timevar_get.

Bootstrapped i386-linux and verified to fix the observed problem (this
scenario isn't covered by the test suite).

zw

	* timevar.c (timevar_add): Delete.
	(timevar_get): Also count time since the selected timer was
	last updated.  Do not examine the timevar stack if the
	selected timer is standalone.

===================================================================
Index: timevar.c
--- timevar.c	2000/08/29 20:57:11	1.10
+++ timevar.c	2000/09/06 05:55:28
@@ -95,8 +95,6 @@ static struct timevar_time_def start_tim
 
 static void get_time
   PARAMS ((struct timevar_time_def *));
-static void timevar_add
-  PARAMS ((struct timevar_time_def *, struct timevar_time_def *));
 static void timevar_accumulate
   PARAMS ((struct timevar_time_def *, struct timevar_time_def *, 
 	   struct timevar_time_def *));
@@ -197,18 +195,6 @@ get_time (now)
 #endif	/* __BEOS__ */
 }  
 
-/* Add ELAPSED to TIMER.  */
-
-static void
-timevar_add (timer, elapsed)
-     struct timevar_time_def *timer;
-     struct timevar_time_def *elapsed;
-{
-  timer->user += elapsed->user;
-  timer->sys += elapsed->sys;
-  timer->wall += elapsed->wall;
-}
-
 /* Add the difference between STOP_TIME and START_TIME to TIMER.  */
 
 static void 
@@ -387,18 +373,22 @@ timevar_get (timevar, elapsed)
      struct timevar_time_def *elapsed;
 {
   struct timevar_def *tv = &timevars[timevar];
+  struct timevar_time_def now;
 
   *elapsed = tv->elapsed;
-
+  
   /* Is TIMEVAR currently running as a standalone timer?  */
   if (tv->standalone)
-    /* Add the time elapsed since the it was started.  */
-    timevar_add (elapsed, &tv->start_time);
-
-  /* Is TIMEVAR at the top of the timer stack?  */
-  if (stack->timevar == tv)
-    /* Add the elapsed time since it was pushed.  */
-    timevar_add (elapsed, &start_time);
+    {
+      get_time (&now);
+      timevar_accumulate (elapsed, &tv->start_time, &now);
+    }
+  /* Or is TIMEVAR at the top of the timer stack?  */
+  else if (stack->timevar == tv)
+    {
+      get_time (&now);
+      timevar_accumulate (elapsed, &start_time, &now);
+    }
 }
 
 /* Summarize timing variables to FP.  The timing variable TV_TOTAL has

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