🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Thomas Kaiser Wed, 22 Jul 1992 17:41
gcc-Optimize
#182
Author: Thomas Kaiser
Date: Wed, 22 Jul 1992 17:41
138 lines
3295 bytes
Dear Sirs:

i discovered an bug, when gcc -g -O removed (optimized) a statement. It
removes count-- from the example.

With regards

Thomas Kaiser
Leibniz Supercomputing Centre
Muenchen
Germany

--
-------------------------------------------------------------------------
Thomas Kaiser         Internet:	kaiser@sunmanager.lrz-muenchen.de
LRZ-Muenchen          X400:	C=DE;A=DBP;P=LRZ-MUENCHEN;OU=LRZ;S=Kaiser
-------------------------------------------------------------------------


------------------------------------------------------------------
int make_snmp_query(ip_address, variable, the_community, count)

char *ip_address;
char *variable;
char *the_community;
int  count;

{
  int i;

  alarm(10);
  if (setjmp(env)) {
    printf("xifload: receive timed out from %s\n", ip_address);
    close(s);
    for (i=0; i<num_malloc; i++)
      free(malloc_table[i]);
    num_malloc = 0;
    if (count <= 1)
      return -1;
    else {
      count--;        <------------------ will be removed
      alarm(10);
    }
  }
  make_the_query(ip_address, variable, the_community);
  alarm(0);
  for (i=0; i<num_malloc; i++)
    free(malloc_table[i]);
  num_malloc = 0;
  return 0;
}
--------------------------------------------------
	.align 8
LC3:
	.ascii "xifload: receive timed out from %s\12\0"
	.align 4
	.global _make_snmp_query
	.proc	04
_make_snmp_query:
	!#PROLOGUE# 0
	save %sp,-144,%sp
	!#PROLOGUE# 1
	st %i0,[%fp-20]
	st %i1,[%fp-28]
	st %i2,[%fp-36]
	st %i3,[%fp-44]
	call _alarm,0
	mov 10,%o0
	sethi %hi(_env),%o0
	call _setjmp,0
	or %o0,%lo(_env),%o0
	cmp %o0,0
	be L16
	sethi %hi(LC3),%o0
	or %o0,%lo(LC3),%o0
	call _printf,0
	ld [%fp-20],%o1
	sethi %hi(_s),%o0
	call _close,0
	ld [%o0+%lo(_s)],%o0
	mov 0,%i0
	sethi %hi(_num_malloc),%o0
	ld [%o0+%lo(_num_malloc)],%o0
	cmp %i0,%o0
	bge L28
	sethi %hi(_num_malloc),%o0
	sethi %hi(_malloc_table),%o0
	or %o0,%lo(_malloc_table),%i2
	sethi %hi(_num_malloc),%i1
	sll %i0,2,%o0
L29:
	call _free,0
	ld [%o0+%i2],%o0
	add %i0,1,%i0
	ld [%i1+%lo(_num_malloc)],%o0
	cmp %i0,%o0
	bl L29
	sll %i0,2,%o0
	sethi %hi(_num_malloc),%o0
L28:
	st %g0,[%o0+%lo(_num_malloc)]
	ld [%fp-44],%o3
	cmp %o3,1
	ble L27
	mov -1,%i0          <----------- count-- is missing
	call _alarm,0
	mov 10,%o0
L16:
	ld [%fp-20],%o0
	ld [%fp-28],%o1
	call _make_the_query,0
	ld [%fp-36],%o2
	call _alarm,0
	mov 0,%o0
	mov 0,%i0
	sethi %hi(_num_malloc),%o0
	ld [%o0+%lo(_num_malloc)],%o0
	cmp %i0,%o0
	bge L24
	sethi %hi(_malloc_table),%o0
	or %o0,%lo(_malloc_table),%i2
	sethi %hi(_num_malloc),%i1
	sll %i0,2,%o0
L30:
	call _free,0
	ld [%o0+%i2],%o0
	add %i0,1,%i0
	ld [%i1+%lo(_num_malloc)],%o0
	cmp %i0,%o0
	bl L30
	sll %i0,2,%o0
L24:
	sethi %hi(_num_malloc),%o0
	st %g0,[%o0+%lo(_num_malloc)]
	mov 0,%i0
L27:
	ret
	restore
Re: gcc-Optimize
#189
Author: Michael Salmon
Date: Fri, 24 Jul 1992 08:25
89 lines
2920 bytes
In article <9207221341.AA22022@sunmanager.lrz-muenchen.de>, 
a2824ak@sunmanager.lrz-muenchen.de (Thomas Kaiser) writes:
|> Dear Sirs:
|> 
|> i discovered an bug, when gcc -g -O removed (optimized) a statement. It
|> removes count-- from the example.
|> 
|> With regards
|> 
|> Thomas Kaiser
|> Leibniz Supercomputing Centre
|> Muenchen
|> Germany
|> 
|> --
|> -------------------------------------------------------------------------
|> Thomas Kaiser         Internet:	kaiser@sunmanager.lrz-muenchen.de
|> LRZ-Muenchen          X400:	C=DE;A=DBP;P=LRZ-MUENCHEN;OU=LRZ;S=Kaiser
|> -------------------------------------------------------------------------
|> 
|> 
|> ------------------------------------------------------------------
|> int make_snmp_query(ip_address, variable, the_community, count)
|> 
|> char *ip_address;
|> char *variable;
|> char *the_community;
|> int  count;
|> 
|> {
|>   int i;
|> 
|>   alarm(10);
|>   if (setjmp(env)) {
|>     printf("xifload: receive timed out from %s\n", ip_address);
|>     close(s);
|>     for (i=0; i<num_malloc; i++)
|>       free(malloc_table[i]);
|>     num_malloc = 0;
|>     if (count <= 1)
|>       return -1;
|>     else {
|>       count--;        <------------------ will be removed
|>       alarm(10);
|>     }
|>   }
|>   make_the_query(ip_address, variable, the_community);
|>   alarm(0);
|>   for (i=0; i<num_malloc; i++)
|>     free(malloc_table[i]);
|>   num_malloc = 0;
|>   return 0;
|> }

While this is undoubtably frustrating I don't see how gcc can be
expected to understand your function without including setjmp as an
element of the language. As I see it gcc believes that count isn't used
after your decrement so why decrement it. I think that something like
this will work without problem:

{
   if (setjmp(env)) {
     printf("xifload: receive timed out from %s\n", ip_address);
     close(s);
   }
   while (num_malloc > 0)
     free(malloc_table[--num_malloc]);
   if (count-- > 0) {
     alarm(10);
     make_the_query(ip_address, variable, the_community);
     alarm(0);
   }
   while (num_malloc > 0)
     free(malloc_table[--num_malloc]);
   num_malloc = 0; /* shouldn't be required */

   return count > 0 ? 0 : -1;
}

-- 

Michael Salmon

#include	<standard.disclaimer>
#include	<witty.saying>
#include	<fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads