🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1381

2.3.3: Illegal code on sparc

#1381
From: Klamer Schutte
Date: Mon, 11 Jan 1993 15:17
67 lines
2448 bytes
The following code gives wrong results (Illegal instruction) on a sparc.
The error is that a 'function entry trampoline' is put on the stack when 
calling a varargs function. When the function is called later, this
'function entry trampoline' does not exist any more, resulting in a bug.

The same program runs OK as a ANSI C program using gcc and (Sun) acc, and
as C++ program using Sun C++ 2.1 and g++ 2.2.1.

----------------------- va3.c --------------------------
#include        <stdio.h>
#include        <stdarg.h>

typedef int     (*FN)(int,int);
FN      fn;

void
va_fn(int a, ...)
{
        va_list args;

        va_start(args, a);

        fn = va_arg(args, FN);

        va_end(args);
}

void
call_va_fn()
{
        extern void     aap(int a, int b);

        va_fn(0,aap);
}

main()
{
        call_va_fn();
        printf("In main\n");
        fn(0,1);
}

void
aap(int a, int b)
{
        printf("In aap\n");
}
-------------------- EOF ------------------
0 klamer@mi7 14:16 172> g++ -v va3.c
Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.3/specs
gcc version 2.3.3
 /usr/local/lib/gcc-lib/sun4/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix va3.c /tmp/cca03752.i
GNU CPP version 2.3.3 (sparc)
 /usr/local/lib/gcc-lib/sun4/2.3.3/cc1plus /tmp/cca03752.i -quiet -dumpbase va3.cc -version -o /tmp/cca03752.s
GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.3.
 as -o /tmp/cca037521.o /tmp/cca03752.s
 /usr/local/lib/gcc-lib/sun4/2.3.3/ld -e start -dc -dp /lib/crt0.o -L/usr/local/lib/gcc-lib/sun4/2.3.3 -L/usr/local/lib /tmp/cca037521.o -lg++ -lgcc -lc -lgcc
0 klamer@mi7 14:17 173> a.out
In main
Illegal instruction

Klamer


Klamer Schutte			Tel: +31-53-892778	Fax: +31-53-340045
Faculty of electrical engineering -- University of Twente, The Netherlands
preferred: klamer@mi.el.utwente.nl     SMTP: klamer@utelmi01.el.utwente.nl
Technical Details
Message-ID: <9301111317.AA04435@mi.el.utwente.nl>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mi.eltn.utwente.NL!klamer

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mi.eltn.utwente.NL!klamer
From: klamer@mi.eltn.utwente.NL (Klamer Schutte)
Subject: 2.3.3: Illegal code on sparc
Message-ID: <9301111317.AA04435@mi.el.utwente.nl>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 11 Jan 1993 15:17:40 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 69