bugGNU Development Chain for 68HC11/68HC12 - Bugs: bug #11741, wrong code generated for m68hc12...


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

bug #11741: wrong code generated for m68hc12 on an strncpy()

Submitted by:  Stephane Carrez <ciceron>
Submitted on:  Wed 26 Jan 2005 08:31:14 PM UTC  
Category:  gcc Severity:  4 - Important
Item Group:  sw-bug Status:  None
Privacy:  Public Assigned to:  Stephane Carrez <ciceron>
Open/Closed:  Open

Wed 26 Jan 2005 08:31:14 PM UTC, original submission:  

The following function:

typedef short bsdstuff_size_t;
PUBLIC char strncpy(char dst, const char *src, bsdstuff_size_t n)
  // printf("src=%s\r\n", src);
  //    printf("size=%d", n);
        if (n != 0) {
                char *d = dst;
                const char *s = src;

                do {
                        if ((*d++ = *s++) == 0) {
                                /* NUL pad the remaining n-1 bytes */
                                while (--n != 0)
                                        *d++ = 0;
                } while (--n != 0);
//printf("dst=%s\r\n", dst);

        return (dst);


appears to be invalidly compiled with:

m6811-elf-gcc -g -DHI7  -DS12 -g -Os -mshort -m68hcs12 -mauto-incdec
-mlong-calls -msoft-reg-count=4
-L/usr/lib/gcc-lib/m6811-elf/3.0.4/m68hc12/ -fno-builtin  -c -o
obj/S12/bsdstuff.elf bsdstuff.c

and the following sequence generated looks suspicious:

   d4a69:       fe 19 c7        ldx     19c7 <_.frame>
   d4a6c:       ed 00           ldy     0,X
      reg.y = s
   d4a6e:       ee 02           ldx     2,X
      reg.x = d
   d4a70:       18 0a 70 00     movb    1,Y+, 0,X
       reg.x =  reg.y++
       i.e.  d = (s++)   (except s++ not stored)

   d4a74:       6d 00           sty     0,X
       should be s = reg.y 
       but actually, is *d = reg.y

It's probably due to the "sty" that thinks register X
corresponds to the frame which does not look correct
at first glance.

Stephane Carrez <ciceron>
Project AdministratorIn charge of this item.


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.




No changes have been made to this item

Back to the top

Powered by Savane 3.5