[gnu.gcc.bug] bug in m68k gcc 1.28

trq@moose.cita.toronto.edu (Tom Quinn) (10/05/88)

The following code causes gcc to get a fatal signal when compiled with
the "-O -fforce-mem -finline-functions" options.  This is gcc version
1.28 on a Sun3/50 running SunOS 3.5.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.toronto.edu
SOON TO BE trq@moose.cita.utoronto.ca
UUCP   - decvax!utgpu!moose!trq
BITNET - quinn@utorphys.bitnet
ARPA   - trq%moose.cita.toronto.edu@relay.cs.net

The compile:
gcc -g -v -O -fforce-mem -finline-functions -c Text.c
gcc version 1.28
 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_FPU__ -Dmc68020 Text.c /tmp/cca22018.cpp
GNU CPP version 1.28
 /usr/local/lib/gcc-cc1 /tmp/cca22018.cpp -quiet -dumpbase Text.c -fforce-mem -finline-functions -g -O -version -o /tmp/cca22018.s
GNU C version 1.28 (68k, MIT syntax) compiled by GNU C version 1.28.
gcc: Program cc1 got fatal signal 6.

The code:
------------------------------------------------------------------------
typedef	char *	caddr_t;
typedef unsigned long XID;
typedef XID Window;
typedef struct {
	struct _XDisplay *display; 
	Window root;		 
} Screen;
typedef struct _XDisplay {
	int fd;			 
} Display;
typedef union _XEvent {
        int type;		 
} XEvent;
typedef char *String;
typedef struct _WidgetRec *Widget;
typedef struct _WidgetClassRec *WidgetClass;
typedef unsigned int   Cardinal;
typedef char	Boolean;
typedef int		Position;    
typedef unsigned int	Dimension;   
typedef long XtArgVal;
extern Widget XtCreateManagedWidget ();
extern void XtRealizeWidget ();
extern Widget XtNameToWidget();  
typedef void (*XtCallbackProc)();
typedef struct _XtCallbackRec {
    XtCallbackProc  callback;
    caddr_t	    closure;
} XtCallbackRec;
extern char *XtMalloc();  
extern void XtFree();  
typedef struct {
    String	name;
    XtArgVal	value;
} Arg;
extern Widget XtCreatePopupShell();
typedef enum {XtGrabNone, XtGrabNonexclusive, XtGrabExclusive} XtGrabKind;
extern void XtPopup();
typedef struct _CorePart {
    Widget	    parent;		 
    String          name;		 
    Screen	    *screen;		 
    Window	    window;		 
    Position        x, y;		 
    Dimension       width;	 
    Dimension       border_width;	 
} CorePart;
typedef struct _WidgetRec {
    CorePart    core;
 } WidgetRec;
typedef struct _WidgetClassRec {
    int core_class;
} WidgetClassRec;
extern void XtMoveWidget();  
extern WidgetClass     commandWidgetClass;
extern WidgetClass dialogWidgetClass;
extern  WidgetClass transientShellWidgetClass;
int	strlen();
typedef struct _TextRec      *TextWidget;
typedef long XtTextPosition;
typedef struct _XtTextSource XtTextSourceRec, *XtTextSource;
typedef enum {XttextRead, XttextAppend, XttextEdit} XtTextEditType;
typedef struct {
    int  length;
    } XtTextBlock, *XtTextBlockPtr;
typedef struct _XtTextSource {
    XtTextEditType	edit_mode;
    };
typedef struct {
    XtTextPosition left, right;
} XtTextSelection;
typedef struct _TextPart {
    XtTextSource	source;
    XtTextPosition	insertPos;
    XtTextSelection	s;
    int			dialog_horiz_offset;  
    int			dialog_vert_offset;   
    Widget	    sbar;	     
    Boolean	    showposition;    
    struct _dialog {
	TextWidget  text;	     
	Widget      widget;	     
	Widget	    doit;	     
	Widget	    message;	     
	Boolean	    mapped;	     
	struct _dialog *next;	     
    } *dialog;			     
} TextPart;
typedef struct _TextRec {
    CorePart	core;
    TextPart	text;
} TextRec;
char *_XtTextGetText();
static DeleteOrKill(ctx, from, to, kill)
    TextWidget	   ctx;
    XtTextPosition from, to;
    Boolean	   kill;
{
    XtTextBlock text;
    char *ptr;
    if (kill && from < to) {
	ptr = _XtTextGetText(ctx, from, to);
	XStoreBuffer(((ctx)->core.screen->display) , ptr, strlen(ptr), 1);
	XtFree(ptr);
    }
    text.length = 0;
    if (ReplaceText(ctx, from, to, &text)) {
	XBell(((ctx)->core.screen->display) , 50);
	return;
    }
    _XtTextSetNewSelection(ctx, from, from);
    ctx->text.insertPos = from;
    ctx->text.showposition =  1 ;
}
static void DeleteCurrentSelection(ctx, event)
    TextWidget ctx;
   XEvent *event;
{
   StartAction(ctx, event);
    DeleteOrKill(ctx, ctx->text.s.left, ctx->text.s.right, 0 );
   EndAction(ctx);
}
void _XtTextAbortDialog();
static void DoInsert();
static void InsertFile(w, event)
    Widget w;
    XEvent *event;
{
    TextWidget ctx = (TextWidget)w;
    register struct _dialog *dialog, *prev;
    char *ptr;
    register Widget popup;
    static Arg popup_args[] = {
	{		"x" , 0 },
	{		"y" , 0 },
	{"iconName" , (XtArgVal)"Insert File:" },
	{"geometry" , 0 },
	{"allowShellResize" , 1 },
	{	"saveUnder" , 1 },
    };
    Arg args[2];
    static XtCallbackRec callbacks[] = { {0 , 0 }, {0 , 0 } };
    int x, y;
    Window j;
   StartAction(ctx, event);
    if (ctx->text.source->edit_mode != XttextEdit) {
	XBell(((w)->core.screen->display) , 50);
	EndAction(ctx);
	return;
    }
    if (ctx->text.s.left < ctx->text.s.right) {
	ptr = _XtTextGetText(ctx, ctx->text.s.left, ctx->text.s.right);
	DeleteCurrentSelection(ctx, (XEvent*)0 );
    }
    else {
	ptr = "";
    }
    XTranslateCoordinates( ((w)->core.screen->display) , ((w)->core.window) ,
			   ((((w)->core.screen) )->root) , 0, 0, &x, &y, &j );
    x += ctx->text.dialog_horiz_offset;
    y += ctx->text.dialog_vert_offset;
    if (ctx->text.sbar)
	x += ctx->text.sbar->core.width + ctx->text.sbar->core.border_width;
    prev = 0 ;
    for (dialog = ctx->text.dialog; dialog; dialog = dialog->next) {
	if (!dialog->mapped)
	    break;
	x += ctx->text.dialog_horiz_offset;
	y += ctx->text.dialog_vert_offset;
	prev = dialog;
    }
    if (dialog) {
	_XtTextAbortDialog(w, (caddr_t)dialog, 0 );
	XtMoveWidget(popup = dialog->widget->core.parent, x, y);
    }
    else {
	dialog = ((struct _dialog *) XtMalloc((unsigned) sizeof(struct _dialog))) ;
	if (prev)
	    prev->next = dialog;  
	else			  
	    ctx->text.dialog = dialog;
	dialog->text = ctx;
	dialog->message = (Widget)0 ;
	dialog->next = 0 ;
	popup_args[0].value = (XtArgVal)x;
	popup_args[1].value = (XtArgVal)y;
	popup = XtCreatePopupShell( "insertFile", transientShellWidgetClass, w,
				    popup_args, 	((Cardinal) (sizeof(popup_args) / sizeof(popup_args[0])))  );
	( ( args[0]).name = ( 	"label" ), ( args[0]).value = (XtArgVal)( "Insert File:"  ) ) ;
	( ( args[1]).name = ( 	"value" ), ( args[1]).value = (XtArgVal)( ptr ) ) ; 
	dialog->widget =
	    XtCreateManagedWidget("fileInsert", dialogWidgetClass, popup,
				  args, ((Cardinal)2) );
	XtSetKeyboardFocus( dialog->widget,
			    XtNameToWidget( dialog->widget, "value" ));
	callbacks[0].callback = _XtTextAbortDialog;
	callbacks[0].closure = (caddr_t)dialog;
	( ( args[0]).name = ( 	"callback" ), ( args[0]).value = (XtArgVal)( callbacks ) ) ;
	XtCreateManagedWidget( "Cancel", commandWidgetClass, dialog->widget,
			       args, ((Cardinal)1)  );
	callbacks[0].callback = DoInsert;
	dialog->doit =
	    XtCreateManagedWidget( "DoIt", commandWidgetClass, dialog->widget,
				   args, ((Cardinal)1)  );
	XtRealizeWidget( popup );
    }
    XtPopup(popup, XtGrabNone);
    dialog->mapped = 1 ;
   EndAction(ctx);
}