public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/29950]  New: Generated code changes after unrelated edits in source.
@ 2006-11-22 22:56 vda dot linux at googlemail dot com
  2006-11-22 22:57 ` [Bug rtl-optimization/29950] " vda dot linux at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: vda dot linux at googlemail dot com @ 2006-11-22 22:56 UTC (permalink / raw)
  To: gcc-bugs

I noticed that sizes of functions in generated code change when I do simple
unrelated changes. Example:

# diff -u vi_small.c vi_big.c
--- vi_small.c  2006-11-22 23:35:39.000000000 +0100
+++ vi_big.c    2006-11-22 23:35:42.000000000 +0100
@@ -3414,6 +3414,8 @@
 } sockaddr_inet;
 extern int dotted2sockaddr(const char *dotted, struct sockaddr* sp, int
socklen);
 extern int create_and_bind_socket_ip4or6(const char *hostaddr, int port);
+extern int setsockopt_reuseaddr(int fd);
+extern int setsockopt_reuseaddr2(int fd);
 extern char *xstrdup(const char *s);
 extern char *xstrndup(const char *s, int n);
 extern char *safe_strncpy(char *dst, const char *src, size_t size);

Both .c files have this simple function at the end:

Byte *find_pair(Byte * p, Byte c)
{
 Byte match, *q;
 int dir, level;
 match = ')';
 level = 1;
 dir = 1;
 switch (c) {
 case '(':
  match = ')';
  break;
 case '[':
  match = ']';
  break;
 case '{':
  match = '}';
  break;
 case ')':
  match = '(';
  dir = -1;
  break;
 case ']':
  match = '[';
  dir = -1;
  break;
 case '}':
  match = '{';
  dir = -1;
  break;
 }
 for (q = p + dir; text <= q && q < end; q += dir) {
  if (*q == c)
   level++;
  if (*q == match)
   level--;
  if (level == 0)
   break;
 }
 if (level != 0)
  q = ((void *)0);
 return (q);
}

which is obviously does not depend on setsockopt_reuseaddr[2].
I made two extra copies of it, just for fun, but it happens without copies too.
Okay, when I compile those:

#!/bin/sh
function compile() {
    gcc -fno-builtin-strlen -Os "$@"
}
compile -c -o vi_small.o vi_small.c
compile -c -o vi_big.o   vi_big.c
nm --size-sort vi_small.o | grep find_pair
nm --size-sort vi_big.o   | grep find_pair

I am getting:

000000a9 T find_pair   (vi_small.c)
000000a9 T find_pairB
000000a9 T find_pairC

000000a9 T find_pairB  (vi_big.c)
000000a9 T find_pairC
000000b9 T find_pair   <--------- different??

How come gcc generates different code for identical source files?
You saw the diff, it cannot matter at all...
How come gcc generates different code for identical functions???
(vi_big.c:find_pairB is the same as vi_big.c:find_pair to the last byte)

# gcc -v
Using built-in specs.
Target: i386-pc-linux-gnu
Configured with: ../gcc-4.1.1.org/configure --prefix=/usr/app/gcc-4.1.1.org
--exec-prefix=/usr/app/gcc-4.1.1.org --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/app/gcc-4.1.1.org/libexec
--datadir=/usr/app/gcc-4.1.1.org/share --sysconfdir=/etc
--sharedstatedir=/usr/app/gcc-4.1.1.org/var/com
--localstatedir=/usr/app/gcc-4.1.1.org/var --libdir=/usr/lib
--includedir=/usr/include --infodir=/usr/info --mandir=/usr/man
--with-slibdir=/usr/app/gcc-4.1.1.org/lib --with-local-prefix=/usr/local
--with-gxx-include-dir=/usr/app/gcc-4.1.1.org/include/g++-v3
--enable-languages=c,c++ --with-system-zlib --disable-nls
--enable-threads=posix i386-pc-linux-gnu
Thread model: posix
gcc version 4.1.1


-- 
           Summary: Generated code changes after unrelated edits in source.
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vda dot linux at googlemail dot com
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu


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


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

end of thread, other threads:[~2008-03-29  0:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-22 22:56 [Bug rtl-optimization/29950] New: Generated code changes after unrelated edits in source vda dot linux at googlemail dot com
2006-11-22 22:57 ` [Bug rtl-optimization/29950] " vda dot linux at googlemail dot com
2006-11-22 22:59 ` vda dot linux at googlemail dot com
2006-11-24  2:51 ` pinskia at gcc dot gnu dot org
2007-07-21 23:42 ` vda dot linux at googlemail dot com
2007-08-28 14:49 ` vda dot linux at googlemail dot com
2007-08-31  1:47 ` pinskia at gcc dot gnu dot org
2007-08-31 11:30 ` vda dot linux at googlemail dot com
2008-03-29  0:57 ` 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).