Bug 13122 - h8300 - local variable gets corrupted by function call when -fomit-frame-pointer is given
h8300 - local variable gets corrupted by function call when -fomit-frame-poin...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: target
3.4.0
: P2 normal
: 3.3.3
Assigned To: Kazu Hirata
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-11-19 10:44 UTC by Dhananjay Deshpande
Modified: 2003-12-15 21:02 UTC (History)
2 users (show)

See Also:
Host:
Target: h8300-unknown-hms
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-11-22 16:47:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dhananjay Deshpande 2003-11-19 10:44:49 UTC
Try compiling code below with

h8300-coff-gcc -fomit-frame-pointer -mh -mn bug.c

==================================================
void foo(int a, int b, int c, int d)
{
}
void bar ( char a, char b )
{
}
void main(void)
{
        char a ;
        foo(1,2,3,4);
        a = 10;
        bar(a, 1);
        printf("a=%d\n", a);
}
==================================================

h8300-hms-run a.out prints
a=244

If you see the generated assembly, variable a is accessed using -ve offset from 
SP. It should be +ve offset.

    mov.b   r2l,@(-1,er7)   ;#  a

The problem doesn't appear if line calling function foo() is commented.
I think this is related to INITIAL_ELIMINATION_OFFSET.

-Dhananjay
Comment 1 Kazu Hirata 2003-11-22 16:47:03 UTC
Confirmed with gcc-3.4 20031121.
Comment 2 Kazu Hirata 2003-11-22 16:53:17 UTC
Reduced to:

void foo (int, int, int, int);

char
bar (void)
{
  char a;
  foo (0, 0, 0, 0);
  a = 10;
  return a;
}

Comment 3 Kazu Hirata 2003-11-22 17:26:56 UTC
Probably the following better describes the problem.
You get a positive (correct) offset for "a = 10;"
and a negative one for "return a;".
So I doubt the problem is related to INITIAL_ELIMINATION_OFFSET.

void foo (int, int, int, int);

short
bar (void)
{
  short a = 10;
  foo (0, 0, 0, 0);
  return a;
}
Comment 4 Kazu Hirata 2003-11-23 02:32:25 UTC
OK.  I've got a patch and am testing it now.
Comment 6 Dhananjay Deshpande 2003-11-24 05:34:52 UTC
Subject: RE:  h8300 - local variable gets corrupted by function call when -fomit-frame-pointer is given


Thanks Kazu.

This PR can be closed. 

-Dhananjay
Comment 7 CVS Commits 2003-12-15 20:24:35 UTC
Subject: Bug 13122

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	kazu@gcc.gnu.org	2003-12-15 20:24:33

Modified files:
	gcc            : ChangeLog 
	gcc/config/h8300: h8300.c h8300.h h8300.md lib1funcs.asm 

Log message:
	PR target/13122
	* config/h8300/h8300.md (pushqi1_h8300hs_normal): New.
	(pushqi1): Call gen_pushqi1_h8300hs_normal in normal mode.
	(pushhi1_h8300hs_normal): New.
	(pushhi1): Call gen_pushqi1_h8300hs_normal in normal mode.
	
	* config/h8300/h8300.h (LINK_SPEC): Support normal mode.
	* config/h8300/h8300.c (asm_file_start): Correctly output
	an architecture directive.
	* config/h8300/lib1funcs.asm: Correctly specify an
	architecture directive.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.843&r2=1.16114.2.844
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/h8300/h8300.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.174.2.4&r2=1.174.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/h8300/h8300.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.123.2.1&r2=1.123.2.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/h8300/h8300.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.123.2.6&r2=1.123.2.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/h8300/lib1funcs.asm.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16&r2=1.16.4.1

Comment 8 Dara Hazeghi 2003-12-15 21:02:47 UTC
Fixed for 3.3.3.