Article View: gnu.gcc.bug
Article #284va-sparc.h bug
From: Lupe Christoph
Date: Thu, 06 Aug 1992 16:17
Date: Thu, 06 Aug 1992 16:17
49 lines
2450 bytes
2450 bytes
As I don't save all the bug reports going by, I don't know if this has already
been reported.
Anyway, here is a bug report and a fix.
Both gcc and g++ use the same architecture-dependend include file for
<stdarg.h>. In my case, va-sparc.h. This file contains the SPARC
definition of va_arg(pvar,TYPE).
The definition gives wrong results if sizeof (TYPE) < sizeof (int);
The part that does the argument fetch dereferences the starting
address of the argument with a *(TYPE*). This is correct for large
arguments (>= sizeof (int)). For a small argument, it works correctly
only on a little endian architecture. SPARC isn't.
I have fixed this by testing for small argument types and dereferencing
the pointer as an int *, *then* casting to TYPE. This should work on
all architectures, big or little endian, but I'm currently only interested
in SPARC.
Attached is a context diff with the entire macro.
*** va-sparc.h.orig Sun Jun 21 11:41:38 1992
--- va-sparc.h Thu Aug 6 14:05:49 1992
***************
*** 51,64 ****
--- 51,66 ----
#define va_arg(pvar,TYPE) \
__extension__ \
({ TYPE __va_temp; \
((__builtin_classify_type (__va_temp) >= 12) \
? ((pvar) += __va_rounded_size (TYPE *), \
**(TYPE **) ((pvar) - __va_rounded_size (TYPE *))) \
: __va_rounded_size (TYPE) == 8 \
? ({ union {TYPE d; int i[2];} u; \
u.i[0] = ((int *) (pvar))[0]; \
u.i[1] = ((int *) (pvar))[1]; \
(pvar) += 8; \
u.d; }) \
: ((pvar) += __va_rounded_size (TYPE), \
+ (sizeof (TYPE) < sizeof (int)) ? \
+ (TYPE) *((int *) ((pvar) - __va_rounded_size (TYPE))) : \
*((TYPE *) ((pvar) - __va_rounded_size (TYPE)))));})
| ...!unido!ukw!lupe (German EUNet, "bang") | Disclaimer: |
| lupe@ukw.UUCP (German EUNet, domain) | As I am self-employed, |
| suninfo!alanya!lupe (Sun Germany) | this *is* the opinion |
| Res non sunt complicanda praeter necessitatem. | of my employer. |
Technical Details
Message-ID:
<9208061217.AA04108@ukw.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ukw.UUCP!lupeShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ukw.UUCP!lupe From: lupe@ukw.UUCP (Lupe Christoph) Subject: va-sparc.h bug Message-ID: <9208061217.AA04108@ukw.uucp> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 6 Aug 1992 16:17:14 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 50