]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix problems with the MSP430 port's handling of persistent data.
authorJozef Lawrynowicz <jozef.l@somniumtech.com>
Thu, 15 Jun 2017 13:38:52 +0000 (13:38 +0000)
committerNick Clifton <nickc@gcc.gnu.org>
Thu, 15 Jun 2017 13:38:52 +0000 (13:38 +0000)
PR target/78818
gcc * config/msp430/msp430.c (msp430_data_attr): Check that it's possible
for a variable to have a section before checking if the section has a
name.
Set section to.persistent if persistent attribute is set.
Warn if .persistent attribute is used on an automatic variable.

tests * gcc.target/msp430/pr78818-real.c: New template for tests.
* gcc.target/msp430/pr78818-auto.c: New test.
* gcc.target/msp430/pr78818-data-region.c: New test.
* gcc.target/msp430/pr78818-data-sec.c: New test.
* gcc.target/msp430/pr78818-auto-warn.c: New test.

From-SVN: r249222

gcc/ChangeLog
gcc/config/msp430/msp430.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/msp430/pr78818-auto-warn.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/pr78818-auto.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/pr78818-data-region.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/pr78818-data-sec.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/pr78818-real.c [new file with mode: 0644]

index fc9554f0142f9e30b12471e153f8bced42c40f18..3f2f34417c656660f8167f1dcd6f8f5dba017b3b 100644 (file)
@@ -1,3 +1,12 @@
+2017-06-15  Jozef Lawrynowicz  <jozef.l@somniumtech.com>
+
+       PR target/78818
+       * config/msp430/msp430.c (msp430_data_attr): Check that it's possible
+       for a variable to have a section before checking if the section has a
+       name.
+       Set section to.persistent if persistent attribute is set.
+       Warn if .persistent attribute is used on an automatic variable.
+
 2017-06-15  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR rtl-optimization/80474
index dd53dea685b5a90f1d4ddfe68a412f8972385605..6acab1e70cb6987ab4b52ff94b45af39c76d3b13 100644 (file)
@@ -40,6 +40,7 @@
 #include "expr.h"
 #include "langhooks.h"
 #include "builtins.h"
+#include "intl.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -1993,10 +1994,24 @@ msp430_data_attr (tree * node,
   gcc_assert (args == NULL);
 
   if (TREE_CODE (* node) != VAR_DECL)
-    message = "%qE attribute only applies to variables";
-
-  if (DECL_SECTION_NAME (* node))
-    message = "%qE attribute cannot be applied to variables with specific sections";
+    message = G_("%qE attribute only applies to variables");
+
+  /* Check that it's possible for the variable to have a section.  */
+  if ((TREE_STATIC (* node) || DECL_EXTERNAL (* node) || in_lto_p)
+      && DECL_SECTION_NAME (* node))
+    message = G_("%qE attribute cannot be applied to variables with specific sections");
+
+  if (!message && TREE_NAME_EQ (name, ATTR_PERSIST) && !TREE_STATIC (* node)
+      && !TREE_PUBLIC (* node) && !DECL_EXTERNAL (* node))
+    message = G_("%qE attribute has no effect on automatic variables");
+
+  /* It's not clear if there is anything that can be set here to prevent the
+     front end placing the variable before the back end can handle it, in a
+     similar way to how DECL_COMMON is used below.
+     So just place the variable in the .persistent section now.  */
+  if ((TREE_STATIC (* node) || DECL_EXTERNAL (* node) || in_lto_p)
+      && TREE_NAME_EQ (name, ATTR_PERSIST))
+    set_decl_section_name (* node, ".persistent");
 
   /* If this var is thought to be common, then change this.  Common variables
      are assigned to sections before the backend has a chance to process them.  */
index 4b7433e2edad9dbb135f034d2295cc6e1bab1469..3677d15c453efb77a59e74ba3b952495a6e41744 100644 (file)
@@ -1,3 +1,12 @@
+2017-06-15  Jozef Lawrynowicz  <jozef.l@somniumtech.com>
+
+       PR target/78818
+       * gcc.target/msp430/pr78818-real.c: New template for tests.
+       * gcc.target/msp430/pr78818-auto.c: New test.
+       * gcc.target/msp430/pr78818-data-region.c: New test.
+       * gcc.target/msp430/pr78818-data-sec.c: New test.
+       * gcc.target/msp430/pr78818-auto-warn.c: New test.
+
 2017-06-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * gcc.target/arm/its.c: Check that no IT blocks has more than 2
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-auto-warn.c b/gcc/testsuite/gcc.target/msp430/pr78818-auto-warn.c
new file mode 100644 (file)
index 0000000..3dba361
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+__attribute__((persistent)) int persistent_1_g = 1;
+__attribute__((persistent)) int persistent_2_g = 0;
+static __attribute__((persistent)) int persistent_3_g = 1;
+static __attribute__((persistent)) int persistent_4_g = 0;
+
+int
+main (void)
+{
+  __attribute__((persistent)) int persistent_1 = 1; /* { dg-warning "attribute has no effect on automatic" } */
+  __attribute__((persistent)) int persistent_2 = 0; /* { dg-warning "attribute has no effect on automatic" } */
+  static __attribute__((persistent)) int persistent_3 = 1;
+  static __attribute__((persistent)) int persistent_4 = 0;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-auto.c b/gcc/testsuite/gcc.target/msp430/pr78818-auto.c
new file mode 100644 (file)
index 0000000..1fb0b28
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+/* { dg-final { scan-assembler-not "\\.comm" } } */
+
+#include "pr78818-real.c"
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c b/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c
new file mode 100644 (file)
index 0000000..22b1fa2
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-mdata-region=either" } */
+
+/* { dg-final { scan-assembler-not "\\.either" } } */
+
+#include "pr78818-real.c"
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-data-sec.c b/gcc/testsuite/gcc.target/msp430/pr78818-data-sec.c
new file mode 100644 (file)
index 0000000..6367e01
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-fdata-sections" } */
+
+/* { dg-final { scan-assembler-not "\\.data" } } */
+/* { dg-final { scan-assembler-not "\\.bss" } } */
+
+#include "pr78818-real.c"
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-real.c b/gcc/testsuite/gcc.target/msp430/pr78818-real.c
new file mode 100644 (file)
index 0000000..504ed4a
--- /dev/null
@@ -0,0 +1,9 @@
+__attribute__((persistent)) int persistent_1 = 1;
+__attribute__((persistent)) int persistent_2 = 0;
+static __attribute__((persistent)) int persistent_3 = 1;
+static __attribute__((persistent)) int persistent_4 = 0;
+
+int main (void)
+{
+  return 0;
+}