Bug#202016: gcc-3.3: Unnecessary store onto stack
Package: gcc-3.3
Version: 1:3.3.1-0pre0
Severity: minor
The following code induces an unnecessary store of fromp onto the stack.
It is never loaded again.
--
#include <sys/socket.h>
int
main(void)
{
struct sockaddr_storage from;
struct sockaddr *const fromp = (void *)&from;
socklen_t fromlen;
fromlen = sizeof(from);
if (getpeername(0, fromp, &fromlen) < 0) {
return 1;
}
return 0;
}
--
If you compile it with
gcc-3.3 -D_GNU_SOURCE -S -O2
you will get
--
.file "b.c"
.text
.p2align 2,,3
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $152, %esp
andl $-16, %esp
pushl %edx
leal -144(%ebp), %edx
leal -136(%ebp), %eax
pushl %edx
pushl %eax
pushl $0
movl $128, -144(%ebp)
movl %eax, -140(%ebp)
call getpeername
shrl $31, %eax
addl $16, %esp
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.2.3 20030415 (Debian prerelease)"
--
The store into -140(%ebp) is useless.
This does not occur if you remove the -D_GNU_SOURCE, so this is related
to the __SOCKADDR_ARG magic in sys/socket.h. I can reproduce this with
gcc 3.2. gcc 2.95 does not have this problem.
I've appended the preprocessed source.
-- System Information
Debian Release: testing/unstable
Kernel Version: Linux gondolin 2.4.21-2-686-smp #1 SMP Sat Jul 5 01:42:22 EST 2003 i686 GNU/Linux
Versions of the packages gcc-3.3 depends on:
ii binutils 2.14.90.0.4-0. The GNU assembler, linker and binary utiliti
ii cpp-3.3 3.3.1-0pre0 The GNU C preprocessor
ii gcc-3.3-base 3.3.1-0pre0 The GNU Compiler Collection (base package)
ii libc6 2.3.1-16 GNU C Library: Shared libraries and Timezone
ii libgcc1 3.3.1-0pre0 GCC support library
--
# 1 "b.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "b.c"
# 1 "/usr/include/sys/socket.h" 1 3 4
# 23 "/usr/include/sys/socket.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 291 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 292 "/usr/include/features.h" 2 3 4
# 314 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4
# 315 "/usr/include/features.h" 2 3 4
# 24 "/usr/include/sys/socket.h" 2 3 4
# 1 "/usr/include/sys/uio.h" 1 3 4
# 24 "/usr/include/sys/uio.h" 3 4
# 1 "/usr/include/sys/types.h" 1 3 4
# 29 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/bits/types.h" 1 3 4
# 28 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 29 "/usr/include/bits/types.h" 2 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/stddef.h" 1 3 4
# 213 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/stddef.h" 3 4
typedef unsigned int size_t;
# 32 "/usr/include/bits/types.h" 2 3 4
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;
__extension__ typedef long long int __quad_t;
__extension__ typedef unsigned long long int __u_quad_t;
# 128 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 129 "/usr/include/bits/types.h" 2 3 4
typedef unsigned long long int __dev_t;
typedef unsigned int __uid_t;
typedef unsigned int __gid_t;
typedef unsigned long int __ino_t;
typedef unsigned long long int __ino64_t;
typedef unsigned int __mode_t;
typedef unsigned int __nlink_t;
typedef long int __off_t;
typedef long long int __off64_t;
typedef int __pid_t;
typedef struct { int __val[2]; } __fsid_t;
typedef long int __clock_t;
typedef unsigned long int __rlim_t;
typedef unsigned long long int __rlim64_t;
typedef unsigned int __id_t;
typedef long int __time_t;
typedef unsigned int __useconds_t;
typedef long int __suseconds_t;
typedef int __daddr_t;
typedef long int __swblk_t;
typedef int __key_t;
typedef int __clockid_t;
typedef int __timer_t;
typedef long int __blksize_t;
typedef long int __blkcnt_t;
typedef long long int __blkcnt64_t;
typedef unsigned long int __fsblkcnt_t;
typedef unsigned long long int __fsblkcnt64_t;
typedef unsigned long int __fsfilcnt_t;
typedef unsigned long long int __fsfilcnt64_t;
typedef int __ssize_t;
typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
typedef char *__caddr_t;
typedef int __intptr_t;
typedef unsigned int __socklen_t;
# 32 "/usr/include/sys/types.h" 2 3 4
typedef __u_char u_char;
typedef __u_short u_short;
typedef __u_int u_int;
typedef __u_long u_long;
typedef __quad_t quad_t;
typedef __u_quad_t u_quad_t;
typedef __fsid_t fsid_t;
typedef __loff_t loff_t;
typedef __ino_t ino_t;
typedef __ino64_t ino64_t;
typedef __dev_t dev_t;
typedef __gid_t gid_t;
typedef __mode_t mode_t;
typedef __nlink_t nlink_t;
typedef __uid_t uid_t;
typedef __off_t off_t;
typedef __off64_t off64_t;
typedef __pid_t pid_t;
typedef __id_t id_t;
typedef __ssize_t ssize_t;
typedef __daddr_t daddr_t;
typedef __caddr_t caddr_t;
typedef __key_t key_t;
# 133 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/time.h" 1 3 4
# 58 "/usr/include/time.h" 3 4
typedef __clock_t clock_t;
# 74 "/usr/include/time.h" 3 4
typedef __time_t time_t;
# 92 "/usr/include/time.h" 3 4
typedef __clockid_t clockid_t;
# 104 "/usr/include/time.h" 3 4
typedef __timer_t timer_t;
# 134 "/usr/include/sys/types.h" 2 3 4
typedef __useconds_t useconds_t;
typedef __suseconds_t suseconds_t;
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/stddef.h" 1 3 4
# 148 "/usr/include/sys/types.h" 2 3 4
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
# 191 "/usr/include/sys/types.h" 3 4
typedef int int8_t __attribute__ ((__mode__ (__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__ ((__mode__ (__DI__)));
typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
typedef int register_t __attribute__ ((__mode__ (__word__)));
# 213 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/endian.h" 1 3 4
# 37 "/usr/include/endian.h" 3 4
# 1 "/usr/include/bits/endian.h" 1 3 4
# 38 "/usr/include/endian.h" 2 3 4
# 214 "/usr/include/sys/types.h" 2 3 4
# 1 "/usr/include/sys/select.h" 1 3 4
# 31 "/usr/include/sys/select.h" 3 4
# 1 "/usr/include/bits/select.h" 1 3 4
# 32 "/usr/include/sys/select.h" 2 3 4
# 1 "/usr/include/bits/sigset.h" 1 3 4
# 23 "/usr/include/bits/sigset.h" 3 4
typedef int __sig_atomic_t;
typedef struct
{
unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
} __sigset_t;
# 35 "/usr/include/sys/select.h" 2 3 4
typedef __sigset_t sigset_t;
# 1 "/usr/include/time.h" 1 3 4
# 116 "/usr/include/time.h" 3 4
struct timespec
{
__time_t tv_sec;
long int tv_nsec;
};
# 45 "/usr/include/sys/select.h" 2 3 4
# 1 "/usr/include/bits/time.h" 1 3 4
# 67 "/usr/include/bits/time.h" 3 4
struct timeval
{
__time_t tv_sec;
__suseconds_t tv_usec;
};
# 47 "/usr/include/sys/select.h" 2 3 4
# 55 "/usr/include/sys/select.h" 3 4
typedef long int __fd_mask;
# 67 "/usr/include/sys/select.h" 3 4
typedef struct
{
__fd_mask fds_bits[1024 / (8 * sizeof (__fd_mask))];
} fd_set;
typedef __fd_mask fd_mask;
# 99 "/usr/include/sys/select.h" 3 4
extern int select (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
struct timeval *__restrict __timeout) ;
extern int pselect (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
const struct timespec *__restrict __timeout,
const __sigset_t *__restrict __sigmask) ;
# 217 "/usr/include/sys/types.h" 2 3 4
# 1 "/usr/include/sys/sysmacros.h" 1 3 4
# 220 "/usr/include/sys/types.h" 2 3 4
typedef __blksize_t blksize_t;
typedef __blkcnt_t blkcnt_t;
typedef __fsblkcnt_t fsblkcnt_t;
typedef __fsfilcnt_t fsfilcnt_t;
# 258 "/usr/include/sys/types.h" 3 4
typedef __blkcnt64_t blkcnt64_t;
typedef __fsblkcnt64_t fsblkcnt64_t;
typedef __fsfilcnt64_t fsfilcnt64_t;
# 1 "/usr/include/bits/pthreadtypes.h" 1 3 4
# 23 "/usr/include/bits/pthreadtypes.h" 3 4
# 1 "/usr/include/bits/sched.h" 1 3 4
# 83 "/usr/include/bits/sched.h" 3 4
struct __sched_param
{
int __sched_priority;
};
# 24 "/usr/include/bits/pthreadtypes.h" 2 3 4
typedef int __atomic_lock_t;
struct _pthread_fastlock
{
long int __status;
__atomic_lock_t __spinlock;
};
typedef struct _pthread_descr_struct *_pthread_descr;
typedef struct __pthread_attr_s
{
int __detachstate;
int __schedpolicy;
struct __sched_param __schedparam;
int __inheritsched;
int __scope;
size_t __guardsize;
int __stackaddr_set;
void *__stackaddr;
size_t __stacksize;
} pthread_attr_t;
typedef struct
{
struct _pthread_fastlock __c_lock;
_pthread_descr __c_waiting;
} pthread_cond_t;
typedef struct
{
int __dummy;
} pthread_condattr_t;
typedef unsigned int pthread_key_t;
typedef struct
{
int __m_reserved;
int __m_count;
_pthread_descr __m_owner;
int __m_kind;
struct _pthread_fastlock __m_lock;
} pthread_mutex_t;
typedef struct
{
int __mutexkind;
} pthread_mutexattr_t;
typedef int pthread_once_t;
typedef struct _pthread_rwlock_t
{
struct _pthread_fastlock __rw_lock;
int __rw_readers;
_pthread_descr __rw_writer;
_pthread_descr __rw_read_waiting;
_pthread_descr __rw_write_waiting;
int __rw_kind;
int __rw_pshared;
} pthread_rwlock_t;
typedef struct
{
int __lockkind;
int __pshared;
} pthread_rwlockattr_t;
typedef volatile int pthread_spinlock_t;
typedef struct {
struct _pthread_fastlock __ba_lock;
int __ba_required;
int __ba_present;
_pthread_descr __ba_waiting;
} pthread_barrier_t;
typedef struct {
int __pshared;
} pthread_barrierattr_t;
typedef unsigned long int pthread_t;
# 267 "/usr/include/sys/types.h" 2 3 4
# 25 "/usr/include/sys/uio.h" 2 3 4
# 1 "/usr/include/bits/uio.h" 1 3 4
# 42 "/usr/include/bits/uio.h" 3 4
struct iovec
{
void *iov_base;
size_t iov_len;
};
# 30 "/usr/include/sys/uio.h" 2 3 4
extern ssize_t readv (int __fd, __const struct iovec *__vector, int __count)
;
extern ssize_t writev (int __fd, __const struct iovec *__vector, int __count)
;
# 28 "/usr/include/sys/socket.h" 2 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/stddef.h" 1 3 4
# 30 "/usr/include/sys/socket.h" 2 3 4
# 1 "/usr/include/bits/socket.h" 1 3 4
# 29 "/usr/include/bits/socket.h" 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/stddef.h" 1 3 4
# 30 "/usr/include/bits/socket.h" 2 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 1 3 4
# 11 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/syslimits.h" 1 3 4
# 1 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 1 3 4
# 122 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 3 4
# 1 "/usr/include/limits.h" 1 3 4
# 144 "/usr/include/limits.h" 3 4
# 1 "/usr/include/bits/posix1_lim.h" 1 3 4
# 126 "/usr/include/bits/posix1_lim.h" 3 4
# 1 "/usr/include/bits/local_lim.h" 1 3 4
# 36 "/usr/include/bits/local_lim.h" 3 4
# 1 "/usr/include/linux/limits.h" 1 3 4
# 37 "/usr/include/bits/local_lim.h" 2 3 4
# 127 "/usr/include/bits/posix1_lim.h" 2 3 4
# 145 "/usr/include/limits.h" 2 3 4
# 1 "/usr/include/bits/posix2_lim.h" 1 3 4
# 149 "/usr/include/limits.h" 2 3 4
# 1 "/usr/include/bits/xopen_lim.h" 1 3 4
# 34 "/usr/include/bits/xopen_lim.h" 3 4
# 1 "/usr/include/bits/stdio_lim.h" 1 3 4
# 35 "/usr/include/bits/xopen_lim.h" 2 3 4
# 153 "/usr/include/limits.h" 2 3 4
# 123 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 2 3 4
# 8 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/syslimits.h" 2 3 4
# 12 "/usr/lib/gcc-lib/i386-linux/3.3.1/include/limits.h" 2 3 4
# 32 "/usr/include/bits/socket.h" 2 3 4
typedef __socklen_t socklen_t;
enum __socket_type
{
SOCK_STREAM = 1,
SOCK_DGRAM = 2,
SOCK_RAW = 3,
SOCK_RDM = 4,
SOCK_SEQPACKET = 5,
SOCK_PACKET = 10
};
# 142 "/usr/include/bits/socket.h" 3 4
# 1 "/usr/include/bits/sockaddr.h" 1 3 4
# 29 "/usr/include/bits/sockaddr.h" 3 4
typedef unsigned short int sa_family_t;
# 143 "/usr/include/bits/socket.h" 2 3 4
struct sockaddr
{
sa_family_t sa_family;
char sa_data[14];
};
# 162 "/usr/include/bits/socket.h" 3 4
struct sockaddr_storage
{
sa_family_t ss_family;
__uint32_t __ss_align;
char __ss_padding[(128 - (2 * sizeof (__uint32_t)))];
};
enum
{
MSG_OOB = 0x01,
MSG_PEEK = 0x02,
MSG_DONTROUTE = 0x04,
MSG_TRYHARD = MSG_DONTROUTE,
MSG_CTRUNC = 0x08,
MSG_PROXY = 0x10,
MSG_TRUNC = 0x20,
MSG_DONTWAIT = 0x40,
MSG_EOR = 0x80,
MSG_WAITALL = 0x100,
MSG_FIN = 0x200,
MSG_SYN = 0x400,
MSG_CONFIRM = 0x800,
MSG_RST = 0x1000,
MSG_ERRQUEUE = 0x2000,
MSG_NOSIGNAL = 0x4000,
MSG_MORE = 0x8000
};
struct msghdr
{
void *msg_name;
socklen_t msg_namelen;
struct iovec *msg_iov;
size_t msg_iovlen;
void *msg_control;
size_t msg_controllen;
int msg_flags;
};
struct cmsghdr
{
size_t cmsg_len;
int cmsg_level;
int cmsg_type;
__extension__ unsigned char __cmsg_data [];
};
# 257 "/usr/include/bits/socket.h" 3 4
extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
struct cmsghdr *__cmsg) ;
# 284 "/usr/include/bits/socket.h" 3 4
enum
{
SCM_RIGHTS = 0x01,
SCM_CREDENTIALS = 0x02,
__SCM_CONNECT = 0x03
};
struct ucred
{
pid_t pid;
uid_t uid;
gid_t gid;
};
# 1 "/usr/include/asm/socket.h" 1 3 4
# 1 "/usr/include/asm/sockios.h" 1 3 4
# 5 "/usr/include/asm/socket.h" 2 3 4
# 306 "/usr/include/bits/socket.h" 2 3 4
struct linger
{
int l_onoff;
int l_linger;
};
# 36 "/usr/include/sys/socket.h" 2 3 4
struct osockaddr
{
unsigned short int sa_family;
unsigned char sa_data[14];
};
enum
{
SHUT_RD = 0,
SHUT_WR,
SHUT_RDWR
};
# 87 "/usr/include/sys/socket.h" 3 4
typedef union { struct sockaddr *__restrict __sockaddr__; struct sockaddr_at *__restrict __sockaddr_at__; struct sockaddr_ax25 *__restrict __sockaddr_ax25__; struct sockaddr_dl *__restrict __sockaddr_dl__; struct sockaddr_eon *__restrict __sockaddr_eon__; struct sockaddr_in *__restrict __sockaddr_in__; struct sockaddr_in6 *__restrict __sockaddr_in6__; struct sockaddr_inarp *__restrict __sockaddr_inarp__; struct sockaddr_ipx *__restrict __sockaddr_ipx__; struct sockaddr_iso *__restrict __sockaddr_iso__; struct sockaddr_ns *__restrict __sockaddr_ns__; struct sockaddr_un *__restrict __sockaddr_un__; struct sockaddr_x25 *__restrict __sockaddr_x25__;
} __SOCKADDR_ARG __attribute__ ((__transparent_union__));
typedef union { __const struct sockaddr *__restrict __sockaddr__; __const struct sockaddr_at *__restrict __sockaddr_at__; __const struct sockaddr_ax25 *__restrict __sockaddr_ax25__; __const struct sockaddr_dl *__restrict __sockaddr_dl__; __const struct sockaddr_eon *__restrict __sockaddr_eon__; __const struct sockaddr_in *__restrict __sockaddr_in__; __const struct sockaddr_in6 *__restrict __sockaddr_in6__; __const struct sockaddr_inarp *__restrict __sockaddr_inarp__; __const struct sockaddr_ipx *__restrict __sockaddr_ipx__; __const struct sockaddr_iso *__restrict __sockaddr_iso__; __const struct sockaddr_ns *__restrict __sockaddr_ns__; __const struct sockaddr_un *__restrict __sockaddr_un__; __const struct sockaddr_x25 *__restrict __sockaddr_x25__;
} __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
extern int socket (int __domain, int __type, int __protocol) ;
extern int socketpair (int __domain, int __type, int __protocol,
int __fds[2]) ;
extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
;
extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
socklen_t *__restrict __len) ;
extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
;
extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
socklen_t *__restrict __len) ;
extern ssize_t send (int __fd, __const void *__buf, size_t __n, int __flags)
;
extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags)
;
extern ssize_t sendto (int __fd, __const void *__buf, size_t __n,
int __flags, __CONST_SOCKADDR_ARG __addr,
socklen_t __addr_len) ;
extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
__SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
;
extern ssize_t sendmsg (int __fd, __const struct msghdr *__message, int __flags)
;
extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags)
;
extern int getsockopt (int __fd, int __level, int __optname,
void *__restrict __optval,
socklen_t *__restrict __optlen) ;
extern int setsockopt (int __fd, int __level, int __optname,
__const void *__optval, socklen_t __optlen) ;
extern int listen (int __fd, int __n) ;
extern int accept (int __fd, __SOCKADDR_ARG __addr,
socklen_t *__restrict __addr_len)
;
extern int shutdown (int __fd, int __how) ;
extern int sockatmark (int __fd) ;
extern int isfdtype (int __fd, int __fdtype) ;
# 2 "b.c" 2
int
main(void)
{
struct sockaddr_storage from;
struct sockaddr *const fromp = (void *)&from;
socklen_t fromlen;
fromlen = sizeof(from);
if (getpeername(0, fromp, &fromlen) < 0) {
return 1;
}
return 0;
}
Reply to: