bugGNU Development Chain for 68HC11/68HC12 - Bugs: bug #13917, Bug in gcc 3.0.1. Error with...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #13917: Bug in gcc 3.0.1. Error with pre-decremented pointer array and -Ox switch

Submitter:  None
Submitted:  Mon 25 Jul 2005 01:29:53 PM UTC
   
 
Category:  gcc Severity:  3 - Normal
Item Group:  sw-bug Status:  Fixed
Privacy:  Public Assigned to:  ciceron
Open/Closed:  Closed

Sat 18 Feb 2006 09:50:06 PM UTC, comment #2: 

Fixed in release 3.1

Stephane Carrez <ciceron>
Group administrator
Sat 05 Nov 2005 08:52:23 PM UTC, comment #1: 

Thanks for the bug report.

This is a reload problem.

This note is for me to remember.

The following insn:

(insn:HI 56 55 57 6 0x40189344 (set (mem:QI (pre_dec:HI (reg/v/f:HI 56)) [0 S1 A8])
        (plus:QI (subreg:QI (reg/v:HI 57) 1)
            (const_int 48 [0x30]))) 54 {addqi3} (nil)
    (expr_list:REG_DEAD (reg/v:HI 57)
        (expr_list:REG_INC (reg/v/f:HI 56)
            (nil))))

gets reloaded incorrectly as it emits:

        ldx     28,y
        addb    #48
        ldy     _.frame

This is probable a reload emit order problem.
(Last insn should be emitted first).  No clue why this is so.

Stephane Carrez <ciceron>
Group administrator
Mon 25 Jul 2005 01:29:53 PM UTC, original submission:  

I have found a bug with the -O2, -O3 and -Os switches and pre-decremented pointer, with the release 3.0.1 of the gcc tool chain. This problem does not occur with the -O1 or -O0 switches. The code genarted does not restore the .frame pointer in the Y register after calling a lib function.

In the listing generated, pay attention in the comment >>>>>>>> to understand the problem.

This is the command line to compile the src:

c:/cygwin/bin/m6811-elf-gcc -W -m68hc12 -minmax -mauto-incdec -mrelax -msoft-reg-count=0 -mshort -g -Os -Wa,-ahlms -Wall -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Winline -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused Ltoa.c -c -S -o Ltoa.asm
c:/cygwin/bin/m6811-elf-as -ahlms -m68hc12 -mshort Ltoa.asm -o
Ltoa.o -ahlms=Ltoa.lst

This is the source code:

#include <string.h>

void ltoa(char *buf, unsigned long i, int base);

void ltoa(char *buf, unsigned long i, int base)
{
    char *s;
    #define LEN 25
    int rem;
    char rev[LEN+1];

    if (i == 0)
        s = "0";
    else
    {
        rev[LEN] = 0;
        s = &rev[LEN];
        while (i)
        {
            rem = i % base;
            if (rem < 10)
                *--s = rem + '0';        >>>>>>>> Here appears the error.
            else
            if (base == 16)
                *--s = "abcdef"[rem - 10];
            i /= base;
        }
    }
    strcpy(buf, s);
}

And this is the final listing.

void ltoa(char *buf, unsigned long i, int base)
 {
    68d4: 18 01 ae 20  movw 2006 <_.frame>, 2,-SP
    68d8: 06
    68d9: 1b f1 de     leas -34,SP
    68dc: 7f 20 06     sts 2006 <_.frame>
    68df: fe 20 06     ldx 2006 <_.frame>
    68e2: 6c e0 1a     std 26,X

000068e5 <.LM2>:
 char *s;
#define LEN 25
 int rem;
 char rev[LEN+1];

 if (i == 0)
    68e5: ec e0 26     ldd 38,X
    68e8: 26 0e        bne 68f8 <.LM4>
    68ea: ed e0 28     ldy 40,X
    68ed: 26 09        bne 68f8 <.LM4>

000068ef <.LM3>:
  s = "0";
    68ef: cc 8f 55     ldd #8f55 <.LC0>
    68f2: 6c e0 1c     std 28,X
    68f5: 06 69 8a     jmp 698a <.L4>

000068f8 <.LM4>:
 else
  {
  rev[LEN] = 0;
    68f8: fd 20 06     ldy 2006 <_.frame>
    68fb: 69 e8 19     clr 25,Y

000068fe <.LM5>:
  s = &rev[LEN];
    68fe: 19 e8 19     leay 25,Y
    6901: fe 20 06     ldx 2006 <_.frame>
    6904: 6d e0 1c     sty 28,X

00006907 <.LM6>:
  while (i)
    6907: ec e0 26     ldd 38,X
    690a: 26 05        bne 6911 <.LM7>
    690c: ed e0 28     ldy 40,X
    690f: 27 79        beq 698a <.L4>

00006911 <.LM7>:
   {
   rem = i % base;
    6911: fe 20 06     ldx 2006 <_.frame>
    6914: ec e0 2a     ldd 42,X
    6917: ce 00 00     ldx #0 <.Ldebug_info0>
    691a: 97           tsta
    691b: 2a 01        bpl 691e <.LM7+0xd>
    691d: 09           dex
    691e: fd 20 06     ldy 2006 <_.frame>            >>>>>>>> Y register
loaded with .frame
    6921: 6c e8 20     std 32,Y
    6924: 6e e8 1e     stx 30,Y
    6927: 3b           pshd
    6928: 34           pshx
    6929: ec e8 28     ldd 40,Y
    692c: ee e8 26     ldx 38,Y
    692f: 16 8b ca     jsr 8bca <__umodsi3>    >>>>>>>>    lib function
called and Y register modified.
    6932: 1b 84        leas 4,SP
    6934: 7c 20 02     std 2002 <_.z>

00006937 <.LM8>:
   if (rem < 10)
    6937: 8c 00 09     cpd #9 <BOTNEGB+0x1>
    693a: 2e 0a        bgt 6946 <.LM10>

0000693c <.LM9>:
    *--s = rem + '0';
                                                                                                >>>>>>>> And here appears the bug!
    693c: ee e8 1c     ldx 28,Y  >>>>>>>>    using Y register content with an invalid Value!!!!!!!!!
    693f: cb 30        addb #48
    6941: fd 20 06     ldy 2006 <_.frame>
    6944: 20 1b        bra 6961 <.LM11+0x10>

00006946 <.LM10>:
   else if (base == 16)
    6946: fd 20 06     ldy 2006 <_.frame>
    6949: ec e8 2a     ldd 42,Y
    694c: 8c 00 10     cpd #10 <DMP10>
    694f: 26 15        bne 6966 <.LM12>

00006951 <.LM11>:
    *--s = "abcdef"[rem - 10];
    6951: ee e8 1c     ldx 28,Y
    6954: 7e 20 04     stx 2004 <_.xy>
    6957: fe 20 02     ldx 2002 <_.z>
    695a: e6 e2 8f 4d  ldab -28851,X
    695e: fe 20 04     ldx 2004 <_.xy>
    6961: 6b 2f        stab 1,-X
    6963: 6e e8 1c     stx 28,Y

00006966 <.LM12>:
   i /= base;
    6966: fd 20 06     ldy 2006 <_.frame>
    6969: ec e8 20     ldd 32,Y
    696c: 3b           pshd
    696d: ec e8 1e     ldd 30,Y
    6970: 3b           pshd
    6971: ec e8 28     ldd 40,Y
    6974: ee e8 26     ldx 38,Y
    6977: 16 8b a0     jsr 8ba0 <__udivsi3>
    697a: 1b 84        leas 4,SP
    697c: fd 20 06     ldy 2006 <_.frame>
    697f: 6c e8 28     std 40,Y
    6982: 6e e8 26     stx 38,Y
    6985: 26 8a        bne 6911 <.LM7>
    6987: 04 74 87     tbne D,6911 <.LM7>

0000698a <.L4>:
   }
  }
 strcpy(buf, s);
    698a: fe 20 06     ldx 2006 <_.frame>
    698d: ee e0 1c     ldx 28,X
    6990: 34           pshx
    6991: fd 20 06     ldy 2006 <_.frame>
    6994: ec e8 1a     ldd 26,Y
    6997: 16 87 06     jsr 8706 <strcpy>

0000699a <.LM14>:
 }
    699a: 1b f0 24     leas 36,SP
    699d: 18 05 b1 20  movw 2,SP+, 2006 <_.frame>
    69a1: 06
    69a2: 3d           rts

This problem does not occur if the code is modified like follows

void ltoa(char *buf, unsigned long i, int base)
{
    char *s;
    #define LEN 25
    int rem;
    char rev[LEN+1];

    if (i == 0)
        s = "0";
    else
    {
        rev[LEN] = 0;
        s = &rev[LEN];
        while (i)
        {
            rem = i % base;
            --s;                            >>>>>>>> decrement the pointer
            if (rem < 10)
                *s = rem + '0';        >>>>>>>> the problem dissapears.
            if (base == 16)
                *s = "abcdef"[rem - 10];
            i /= base;
        }
    }
    strcpy(buf, s);
}

This is the code generated for the corrected code.

void ltoa(char *buf, unsigned long i, int base)
{
    68d4: 18 01 ae 20  movw 2006 <_.frame>, 2,-SP
    68d8: 06
    68d9: 1b f1 de     leas -34,SP
    68dc: 7f 20 06     sts 2006 <_.frame>
    68df: fe 20 06     ldx 2006 <_.frame>
    68e2: 6c e0 1a     std 26,X

000068e5 <.LM2>:
    char *s;
#define LEN 25
    int rem;
    char rev[LEN+1];

    if (i == 0)
    68e5: ec e0 26     ldd 38,X
    68e8: 26 0e        bne 68f8 <.LM4>
    68ea: ed e0 28     ldy 40,X
    68ed: 26 09        bne 68f8 <.LM4>

000068ef <.LM3>:
  s = "0";
    68ef: cc 8f 58     ldd #8f58 <.LC0>
    68f2: 6c e0 1c     std 28,X
    68f5: 06 69 8d     jmp 698d <.L4>

000068f8 <.LM4>:
    else
    {
        rev[LEN] = 0;
    68f8: fd 20 06     ldy 2006 <_.frame>
    68fb: 69 e8 19     clr 25,Y

000068fe <.LM5>:
        s = &rev[LEN];
    68fe: 19 e8 19     leay 25,Y
    6901: fe 20 06     ldx 2006 <_.frame>
    6904: 6d e0 1c     sty 28,X

00006907 <.LM6>:
        while (i)
    6907: ec e0 26     ldd 38,X
    690a: 26 05        bne 6911 <.LM7>
    690c: ed e0 28     ldy 40,X
    690f: 27 7c        beq 698d <.L4>

00006911 <.LM7>:
        {
            rem = i % base;
    6911: fe 20 06     ldx 2006 <_.frame>
    6914: ec e0 2a     ldd 42,X
    6917: ce 00 00     ldx #0 <.Ldebug_info0>
    691a: 97           tsta
    691b: 2a 01        bpl 691e <.LM7+0xd>
    691d: 09           dex
    691e: fd 20 06     ldy 2006 <_.frame>
    6921: 6c e8 20     std 32,Y
    6924: 6e e8 1e     stx 30,Y
    6927: 3b           pshd
    6928: 34           pshx
    6929: ec e8 28     ldd 40,Y
    692c: ee e8 26     ldx 38,Y
    692f: 16 8b cd     jsr 8bcd <__umodsi3>
    6932: 1b 84        leas 4,SP
    6934: 7c 20 02     std 2002 <_.z>

00006937 <.LM8>:
   --s;
    6937: fe 20 06     ldx 2006 <_.frame>
    693a: ed e0 1c     ldy 28,X
    693d: 03           dey
    693e: 6d e0 1c     sty 28,X

00006941 <.LM9>:
            if (rem < 10)
    6941: 8c 00 09     cpd #9 <BOTNEGB+0x1>
    6944: 2e 06        bgt 694c <.LM11>

00006946 <.LM10>:
                *s = rem + '0';
    6946: cb 30        addb #48
    6948: 6b 40        stab 0,Y
    694a: 20 1d        bra 6969 <.LM13>

0000694c <.LM11>:
   else
   if (base == 16)
    694c: fd 20 06     ldy 2006 <_.frame>
    694f: ec e0 2a     ldd 42,X
    6952: 8c 00 10     cpd #10 <DMP10>
    6955: 26 12        bne 6969 <.LM13>

00006957 <.LM12>:
                *s = "abcdef"[rem - 10];
    6957: fe 20 02     ldx 2002 <_.z>
    695a: e6 e2 8f 50  ldab -28848,X
    695e: b7 c5        xgdx
    6960: ed e8 1c     ldy 28,Y
    6963: b7 c5        xgdx
    6965: 6b 40        stab 0,Y
    6967: b7 c5        xgdx

00006969 <.LM13>:
            i /= base;
    6969: fd 20 06     ldy 2006 <_.frame>
    696c: ec e8 20     ldd 32,Y
    696f: 3b           pshd
    6970: ec e8 1e     ldd 30,Y
    6973: 3b           pshd
    6974: ec e8 28     ldd 40,Y
    6977: ee e8 26     ldx 38,Y
    697a: 16 8b a3     jsr 8ba3 <__udivsi3>
    697d: 1b 84        leas 4,SP
    697f: fd 20 06     ldy 2006 <_.frame>
    6982: 6c e8 28     std 40,Y
    6985: 6e e8 26     stx 38,Y
    6988: 26 87        bne 6911 <.LM7>
    698a: 04 74 84     tbne D,6911 <.LM7>

0000698d <.L4>:
        }
    }
    strcpy(buf, s);
    698d: fe 20 06     ldx 2006 <_.frame>
    6990: ee e0 1c     ldx 28,X
    6993: 34           pshx
    6994: fd 20 06     ldy 2006 <_.frame>
    6997: ec e8 1a     ldd 26,Y
    699a: 16 87 09     jsr 8709 <strcpy>

0000699d <.LM15>:
}
    699d: 1b f0 24     leas 36,SP
    69a0: 18 05 b1 20  movw 2,SP+, 2006 <_.frame>
    69a4: 06
    69a5: 3d           rts


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follow 4 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-02-18 ciceron StatusIn Progress Fixed
    Open/ClosedOpen Closed
2005-11-05 ciceron StatusNone In Progress
    Assigned toNone ciceron

Back to the top

Powered by Savane 3.13-cf05.
Corresponding source code