Bug 13122 - h8300 - local variable gets corrupted by function call when -fomit-frame-pointer is given
Summary: h8300 - local variable gets corrupted by function call when -fomit-frame-poin...
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.3.3
Assignee: Kazu Hirata
Keywords: wrong-code
Depends on:
Reported: 2003-11-19 10:44 UTC by Dhananjay Deshpande
Modified: 2003-12-15 21:02 UTC (History)
2 users (show)

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


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 ;
        a = 10;
        bar(a, 1);
        printf("a=%d\n", a);

h8300-hms-run a.out prints

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.

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);

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);

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. 

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.


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