public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13428] New: gcc-avr doesn't work properly with PGM string
@ 2003-12-18  6:47 ken at realtronix dot net
  2003-12-18  8:04 ` [Bug c/13428] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: ken at realtronix dot net @ 2003-12-18  6:47 UTC (permalink / raw)
  To: gcc-bugs

gcc version as:
Configured with: ../configure --prefix=/e/avrdev/install --target=avr --enable-
languages=c,c++ --disable-nls --enable-win32-registry=WinAVR
Thread model: single
gcc version 3.3.1

demo program as:

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <string.h>

const char foo[] PROGMEM = "foo";
const char bar[] PROGMEM = "bar";

PGM_P  Langs[2] PROGMEM = {foo, bar};

int main(void)
{
  unsigned char i;
  char buf[2][5];
  
  //strcpy_P works fine with constant index
  strcpy_P(buf[0], Langs[0]);  //correctly copy 'foo'
  strcpy_P(buf[1], Langs[1]);  //correctly copy 'bar'
  
  //but strcpy_P copy char from wrong address if use variable indexing
  for (i=0; i<2; i++)
    strcpy_P(buf[i], Langs[i]);  //copy garbages!!!

  return 1;
}

-- 
           Summary: gcc-avr doesn't work properly with PGM string
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ken at realtronix dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with PGM string
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
@ 2003-12-18  8:04 ` pinskia at gcc dot gnu dot org
  2003-12-19 14:55 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-18  8:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-18 06:47 -------
*** Bug 13427 has been marked as a duplicate of this bug. ***

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with PGM string
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
  2003-12-18  8:04 ` [Bug c/13428] " pinskia at gcc dot gnu dot org
@ 2003-12-19 14:55 ` pinskia at gcc dot gnu dot org
  2003-12-20  3:26 ` ken at realtronix dot net
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-19 14:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-19 14:44 -------
Can you provide the preprocessed source?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
 GCC target triplet|                            |avr


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with PGM string
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
  2003-12-18  8:04 ` [Bug c/13428] " pinskia at gcc dot gnu dot org
  2003-12-19 14:55 ` pinskia at gcc dot gnu dot org
@ 2003-12-20  3:26 ` ken at realtronix dot net
  2003-12-20  3:51 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ken at realtronix dot net @ 2003-12-20  3:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ken at realtronix dot net  2003-12-20 02:53 -------
(In reply to comment #2)
> Can you provide the preprocessed source?

# 1 "pgmbug.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "pgmbug.c"
# 1 "C:/WinAVR/avr/include/avr/io.h" 1 3
# 81 "C:/WinAVR/avr/include/avr/io.h" 3
# 1 "C:/WinAVR/avr/include/avr/sfr_defs.h" 1 3
# 82 "C:/WinAVR/avr/include/avr/io.h" 2 3
# 167 "C:/WinAVR/avr/include/avr/io.h" 3
# 1 "C:/WinAVR/avr/include/avr/iom103.h" 1 3
# 168 "C:/WinAVR/avr/include/avr/io.h" 2 3
# 2 "pgmbug.c" 2
# 1 "C:/WinAVR/avr/include/avr/pgmspace.h" 1 3
# 67 "C:/WinAVR/avr/include/avr/pgmspace.h" 3
# 1 "C:/WinAVR/avr/include/inttypes.h" 1 3
# 60 "C:/WinAVR/avr/include/inttypes.h" 3
typedef signed char int8_t;




typedef unsigned char uint8_t;
# 83 "C:/WinAVR/avr/include/inttypes.h" 3
typedef int int16_t;




typedef unsigned int uint16_t;
# 99 "C:/WinAVR/avr/include/inttypes.h" 3
typedef long int32_t;




typedef unsigned long uint32_t;
# 117 "C:/WinAVR/avr/include/inttypes.h" 3
typedef long long int64_t;




typedef unsigned long long uint64_t;
# 134 "C:/WinAVR/avr/include/inttypes.h" 3
typedef int16_t intptr_t;




typedef uint16_t uintptr_t;
# 68 "C:/WinAVR/avr/include/avr/pgmspace.h" 2 3
# 1 "C:/WinAVR/lib/gcc-lib/avr/3.3.1/include/stddef.h" 1 3 4
# 213 "C:/WinAVR/lib/gcc-lib/avr/3.3.1/include/stddef.h" 3 4
typedef unsigned int size_t;
# 69 "C:/WinAVR/avr/include/avr/pgmspace.h" 2 3
# 89 "C:/WinAVR/avr/include/avr/pgmspace.h" 3
typedef void prog_void __attribute__((__progmem__));
typedef char prog_char __attribute__((__progmem__));
typedef unsigned char prog_uchar __attribute__((__progmem__));
typedef int prog_int __attribute__((__progmem__));
typedef long prog_long __attribute__((__progmem__));
typedef long long prog_long_long __attribute__((__progmem__));
# 347 "C:/WinAVR/avr/include/avr/pgmspace.h" 3
extern void *memcpy_P(void *, const prog_void *, size_t);
extern char *strcat_P(char *, const prog_char *);
extern int strcmp_P(const char *, const prog_char *) __attribute__((__pure__));
extern char *strcpy_P(char *, const prog_char *);
extern int strcasecmp_P(const char *, const prog_char *) __attribute__
((__pure__));
extern size_t strlcat_P (char *, const prog_char *, size_t );
extern size_t strlcpy_P (char *, const prog_char *, size_t );
extern size_t strlen_P(const prog_char *) __attribute__((__const__));
extern int strncmp_P(const char *, const prog_char *, size_t) __attribute__
((__pure__));
extern int strncasecmp_P(const char *, const prog_char *, size_t) __attribute__
((__pure__));
extern char *strncat_P(char *, const prog_char *, size_t);
extern char *strncpy_P(char *, const prog_char *, size_t);
# 3 "pgmbug.c" 2
# 1 "C:/WinAVR/avr/include/string.h" 1 3
# 40 "C:/WinAVR/avr/include/string.h" 3
# 1 "C:/WinAVR/lib/gcc-lib/avr/3.3.1/include/stddef.h" 1 3 4
# 41 "C:/WinAVR/avr/include/string.h" 2 3
# 59 "C:/WinAVR/avr/include/string.h" 3
extern void *memccpy(void *, const void *, int, size_t);
extern void *memchr(const void *, int, size_t) __attribute__((__pure__));
extern int memcmp(const void *, const void *, size_t) __attribute__
((__pure__));
extern void *memcpy(void *, const void *, size_t);
extern void *memmove(void *, const void *, size_t);
extern void *memset(void *, int, size_t);
extern char *strcat(char *, const char *);
extern char *strchr(const char *, int) __attribute__((__pure__));
extern int strcmp(const char *, const char *) __attribute__((__pure__));
extern char *strcpy(char *, const char *);
extern int strcasecmp(const char *, const char *) __attribute__((__pure__));
extern size_t strlcat(char *, const char *, size_t);
extern size_t strlcpy(char *, const char *, size_t);
extern size_t strlen(const char *) __attribute__((__pure__));
extern char *strlwr(char *);
extern char *strncat(char *, const char *, size_t);
extern int strncmp(const char *, const char *, size_t);
extern char *strncpy(char *, const char *, size_t);
extern int strncasecmp(const char *, const char *, size_t) __attribute__
((__pure__));
extern size_t strnlen(const char *, size_t) __attribute__((__pure__));
extern char *strrchr(const char *, int) __attribute__((__pure__));
extern char *strrev(char *);
extern char *strsep(char **, const char *) __attribute__((__pure__));
extern char *strstr(const char *, const char *) __attribute__((__pure__));
extern char *strtok_r(char *, const char *, char **) __attribute__((__pure__));
extern char *strupr(char *);
# 4 "pgmbug.c" 2

const char foo[] __attribute__((__progmem__)) = "foo";
const char bar[] __attribute__((__progmem__)) = "bar";

const prog_char * Langs[2] __attribute__((__progmem__)) = {foo, bar};

int main(void)
{
  unsigned char i;
  char buf[2][5];


  strcpy_P(buf[0], Langs[0]);
  strcpy_P(buf[1], Langs[1]);


  for (i=0; i<2; i++)
    strcpy_P(buf[i], Langs[i]);

  return 1;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with PGM string
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (2 preceding siblings ...)
  2003-12-20  3:26 ` ken at realtronix dot net
@ 2003-12-20  3:51 ` pinskia at gcc dot gnu dot org
  2003-12-20  4:00 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-20  3:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-20 02:58 -------
Marking as invalid to mark it as ...

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
           Keywords|                            |wrong-code
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with PGM string
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (3 preceding siblings ...)
  2003-12-20  3:51 ` pinskia at gcc dot gnu dot org
@ 2003-12-20  4:00 ` pinskia at gcc dot gnu dot org
  2003-12-24 21:16 ` [Bug c/13428] gcc-avr doesn't work properly with __attribute__((__progmem__)) kazu at cs dot umass dot edu
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-20  4:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-20 02:59 -------
Unconfirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work properly with __attribute__((__progmem__))
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (4 preceding siblings ...)
  2003-12-20  4:00 ` pinskia at gcc dot gnu dot org
@ 2003-12-24 21:16 ` kazu at cs dot umass dot edu
  2003-12-24 22:43 ` [Bug c/13428] gcc-avr doesn't work non-constant array references pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kazu at cs dot umass dot edu @ 2003-12-24 21:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2003-12-24 21:12 -------
What is your compiler options?
Could you explain the bug a little more and/or provide a shorter testcase?
Does your testcase expose a bug even if you remove the first two strcpy_P?
Which address is wrong?  The destination or the source?
What if you get 'i' from some function call instead of a for loop like so?
 
  i = baz ();
  strcpy_P(buf[i], Langs[i]);


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kazu at cs dot umass dot edu
            Summary|gcc-avr doesn't work        |gcc-avr doesn't work
                   |properly with PGM string    |properly with
                   |                            |__attribute__((__progmem__))


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work non-constant array references
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (5 preceding siblings ...)
  2003-12-24 21:16 ` [Bug c/13428] gcc-avr doesn't work properly with __attribute__((__progmem__)) kazu at cs dot umass dot edu
@ 2003-12-24 22:43 ` pinskia at gcc dot gnu dot org
  2003-12-25 10:01 ` ken at realtronix dot net
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-24 22:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-24 22:23 -------
Does this work without PROGMEM at all, make sure that you remove the const?
Because the attribute only sets the section different so the attribute cannot be doing 
anything to change the asm.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
            Summary|gcc-avr doesn't work        |gcc-avr doesn't work non-
                   |properly with               |constant array references
                   |__attribute__((__progmem__))|


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work non-constant array references
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (6 preceding siblings ...)
  2003-12-24 22:43 ` [Bug c/13428] gcc-avr doesn't work non-constant array references pinskia at gcc dot gnu dot org
@ 2003-12-25 10:01 ` ken at realtronix dot net
  2003-12-25 12:03 ` ken at realtronix dot net
  2003-12-25 16:11 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: ken at realtronix dot net @ 2003-12-25 10:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ken at realtronix dot net  2003-12-25 05:30 -------
(In reply to comment #6)
> What is your compiler options?
> Could you explain the bug a little more and/or provide a shorter testcase?
> Does your testcase expose a bug even if you remove the first two strcpy_P?
> Which address is wrong?  The destination or the source?
> What if you get 'i' from some function call instead of a for loop like so?
>  
>   i = baz ();
>   strcpy_P(buf[i], Langs[i]);


My complier options are as follows:

avr-gcc -MM -mmcu=atmega103 -I. -g -Os -funsigned-char -funsigned-bitfields -
fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=pgmbug.lst  -
std=gnu99 pgmbug.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > pgmbug.d; \

The bug still exposes even if I remove the firs 2 constant indexed strcpy_P.
However, I found that if I supress optimization, even constant indexed 
strcpy_P does NOT work at all. It seems that the source address pass to 
strcpy_P was wrong, the destination address was correct in any case. I tried 
to get i from a fuction call like i = baz (), the bug still exposes.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work non-constant array references
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (7 preceding siblings ...)
  2003-12-25 10:01 ` ken at realtronix dot net
@ 2003-12-25 12:03 ` ken at realtronix dot net
  2003-12-25 16:11 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: ken at realtronix dot net @ 2003-12-25 12:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ken at realtronix dot net  2003-12-25 05:51 -------
(In reply to comment #2)
> Can you provide the preprocessed source?

(In reply to comment #7)
> Does this work without PROGMEM at all, make sure that you remove the const?
> Because the attribute only sets the section different so the attribute 
cannot be doing 
> anything to change the asm.

When I remove the PROGMEM directive from Langs likes below:

  const char foo[] PROGMEM  = "foo";
  const char bar[] PROGMEM  = "bar";
  PGM_P Langs[2] = {foo, bar};

strcpy_P() works well with constant or variable index array. The source 
address is correct now. Therefore, Langs cannot be put in program memory.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/13428] gcc-avr doesn't work non-constant array references
  2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
                   ` (8 preceding siblings ...)
  2003-12-25 12:03 ` ken at realtronix dot net
@ 2003-12-25 16:11 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-25 16:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-25 15:56 -------
> When I remove the PROGMEM directive from Langs likes below:
> 
>   const char foo[] PROGMEM  = "foo";
>   const char bar[] PROGMEM  = "bar";
>   PGM_P Langs[2] = {foo, bar};
> 
> strcpy_P() works well with constant or variable index array. The source 
> address is correct now. Therefore, Langs cannot be put in program memory.

Then it is a problem with GCC at all because the attribute only puts an extra line in the asm.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13428


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-12-25 15:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-18  6:47 [Bug c/13428] New: gcc-avr doesn't work properly with PGM string ken at realtronix dot net
2003-12-18  8:04 ` [Bug c/13428] " pinskia at gcc dot gnu dot org
2003-12-19 14:55 ` pinskia at gcc dot gnu dot org
2003-12-20  3:26 ` ken at realtronix dot net
2003-12-20  3:51 ` pinskia at gcc dot gnu dot org
2003-12-20  4:00 ` pinskia at gcc dot gnu dot org
2003-12-24 21:16 ` [Bug c/13428] gcc-avr doesn't work properly with __attribute__((__progmem__)) kazu at cs dot umass dot edu
2003-12-24 22:43 ` [Bug c/13428] gcc-avr doesn't work non-constant array references pinskia at gcc dot gnu dot org
2003-12-25 10:01 ` ken at realtronix dot net
2003-12-25 12:03 ` ken at realtronix dot net
2003-12-25 16:11 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).