re PR target/34734 ([avr] attribute((progmem)) not handled properly in C++)
authorGeorg-Johann Lay <avr@gjlay.de>
Mon, 4 Jul 2011 12:48:04 +0000 (12:48 +0000)
committerGeorg-Johann Lay <gjl@gcc.gnu.org>
Mon, 4 Jul 2011 12:48:04 +0000 (12:48 +0000)
PR target/34734
PR target/44643
* gcc.target/avr/avr.exp: Run over cpp files, too.
* gcc.target/avr/torture/avr-torture.exp: Ditto.
* gcc.target/avr/progmem.h: New file.
* gcc.target/avr/exit-abort.h: New file.
* gcc.target/avr/progmem-error-1.c: New file.
* gcc.target/avr/progmem-error-1.cpp: New file.
* gcc.target/avr/progmem-warning-1.c: New file.
* gcc.target/avr/torture/progmem-1.c: New file.
* gcc.target/avr/torture/progmem-1.cpp: New file.

From-SVN: r175811

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/avr/avr.exp
gcc/testsuite/gcc.target/avr/exit-abort.h [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/progmem-error-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/progmem-error-1.cpp [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/progmem-warning-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/progmem.h [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/torture/avr-torture.exp
gcc/testsuite/gcc.target/avr/torture/progmem-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/avr/torture/progmem-1.cpp [new file with mode: 0644]

index 70806e1acfa13c15561044e47a21c98dac545985..21bab4d45ef243ef65653010bc1f2f9622ffb530 100644 (file)
@@ -1,3 +1,17 @@
+2011-07-04  Georg-Johann Lay  <avr@gjlay.de>
+       
+       PR target/34734
+       PR target/44643
+       * gcc.target/avr/avr.exp: Run over cpp files, too.
+       * gcc.target/avr/torture/avr-torture.exp: Ditto.
+       * gcc.target/avr/progmem.h: New file.
+       * gcc.target/avr/exit-abort.h: New file.
+       * gcc.target/avr/progmem-error-1.c: New file.
+       * gcc.target/avr/progmem-error-1.cpp: New file.
+       * gcc.target/avr/progmem-warning-1.c: New file.
+       * gcc.target/avr/torture/progmem-1.c: New file.
+       * gcc.target/avr/torture/progmem-1.cpp: New file.
+
 2011-07-04  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/49615
index 90aeed41e1fa1a4192eeffbfc8ded404edcfffae..a552a9685602a8f8fa03065837312037a2b0f8d4 100644 (file)
@@ -34,7 +34,7 @@ if ![info exists DEFAULT_CFLAGS] then {
 dg-init\r
 \r
 # Main loop.\r
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \\r
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{\[cCS\],cpp}]] \\r
        "" $DEFAULT_CFLAGS\r
 \r
 # All done.\r
diff --git a/gcc/testsuite/gcc.target/avr/exit-abort.h b/gcc/testsuite/gcc.target/avr/exit-abort.h
new file mode 100644 (file)
index 0000000..cf7df20
--- /dev/null
@@ -0,0 +1,8 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+  extern void exit (int);
+  extern void abort (void);
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/avr/progmem-error-1.c b/gcc/testsuite/gcc.target/avr/progmem-error-1.c
new file mode 100644 (file)
index 0000000..cf53cc8
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+#include "progmem.h"
+
+char str[] PROGMEM = "Hallo"; /* { dg-error "must be const" } */
diff --git a/gcc/testsuite/gcc.target/avr/progmem-error-1.cpp b/gcc/testsuite/gcc.target/avr/progmem-error-1.cpp
new file mode 100644 (file)
index 0000000..cf53cc8
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+#include "progmem.h"
+
+char str[] PROGMEM = "Hallo"; /* { dg-error "must be const" } */
diff --git a/gcc/testsuite/gcc.target/avr/progmem-warning-1.c b/gcc/testsuite/gcc.target/avr/progmem-warning-1.c
new file mode 100644 (file)
index 0000000..67af05f
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR target/34734 */
+/* { dg-do compile } */
+/* { dg-options "-Wuninitialized" } */
+
+#include "progmem.h"
+
+const char c PROGMEM; /* { dg-warning "uninitialized variable 'c' put into program memory area" } */
diff --git a/gcc/testsuite/gcc.target/avr/progmem.h b/gcc/testsuite/gcc.target/avr/progmem.h
new file mode 100644 (file)
index 0000000..d5e86c9
--- /dev/null
@@ -0,0 +1,14 @@
+#define PROGMEM __attribute__((progmem))
+
+#define PSTR(s)                                             \
+    (__extension__({                                        \
+            static const char __c[] PROGMEM = (s);          \
+            &__c[0];}))
+
+#define pgm_read_char(addr)                                 \
+    (__extension__({                                        \
+            unsigned int __addr16 = (unsigned int)(addr);   \
+            char __result;                                  \
+            __asm__ ("lpm %0, %a1"                          \
+                     : "=r" (__result) : "z" (__addr16));   \
+            __result; }))
index 355b3ad88bd71c8c506510513707f83982f00be8..e2f83d6689b3bfd52ace1d5ad5bbbdf2477619ff 100644 (file)
@@ -52,7 +52,7 @@ set-torture-options $AVR_TORTURE_OPTIONS
 \r
 \r
 # Main loop.\r
-gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] $DEFAULT_CFLAGS\r
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{\[cS\],cpp}]] $DEFAULT_CFLAGS\r
 \r
 # Finalize use of torture lists.\r
 torture-finish\r
diff --git a/gcc/testsuite/gcc.target/avr/torture/progmem-1.c b/gcc/testsuite/gcc.target/avr/torture/progmem-1.c
new file mode 100644 (file)
index 0000000..790c676
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+
+#include "../exit-abort.h"
+#include "../progmem.h"
+
+const char strA[] PROGMEM = "@A";
+const char strc PROGMEM = 'c';
+
+unsigned int volatile s = 2;
+
+int main()
+{
+    char c;
+    
+    c = pgm_read_char (&strA[s-1]);
+    if (c != 'A')
+        abort();
+
+    c = pgm_read_char (&PSTR ("@@B")[s]);
+    if (c != 'B')
+        abort();
+
+    c = pgm_read_char (&strc);
+    if (c != 'c')
+        abort();
+
+    exit (0);
+
+    return 0;
+}
diff --git a/gcc/testsuite/gcc.target/avr/torture/progmem-1.cpp b/gcc/testsuite/gcc.target/avr/torture/progmem-1.cpp
new file mode 100644 (file)
index 0000000..a1df9e7
--- /dev/null
@@ -0,0 +1,2 @@
+/* { dg-do run } */
+#include "progmem-1.c"