public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)
@ 2017-05-17 15:47 Jozef Lawrynowicz
  2017-05-18 16:08 ` Martin Sebor
  0 siblings, 1 reply; 8+ messages in thread
From: Jozef Lawrynowicz @ 2017-05-17 15:47 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 480 bytes --]

Add warning to back end and add test.

Patch is attached.

If the patch is acceptable, I would appreciate if someone could commit
it for me as I do not have write access.

2017-05-XX Jozef Lawrynowicz <jozef.l@somniumtech.com>
    gcc/
    PR target/78818
    * config/msp430/msp430.c (msp430_unique_section): Warn if .persistent
    attribute is used on an automatic variable.

    gcc/testsuite
    PR target/78818
    * gcc.target/msp430/pr78818/pr78818-auto-warn.c: New test.

[-- Attachment #2: 0002-MSP430-Emit-warning-when-persistent-attribute-is-use.patch --]
[-- Type: application/octet-stream, Size: 2503 bytes --]

From 24726c1e0d68eebeaed6bf5f3fd3f39b00a93a7e Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@somniumtech.com>
Date: Fri, 5 May 2017 15:31:39 +0000
Subject: [PATCH 2/2] MSP430: Emit warning when persistent attribute is used on
 an automatic variable

2017-05-XX	Jozef Lawrynowicz	<jozef.l@somniumtech.com>
	
	gcc/
	PR target/78818
	* config/msp430/msp430.c (msp430_unique_section): Warn if .persistent
	attribute is used on an automatic variable.

	gcc/testsuite
	PR target/78818
	* gcc.target/msp430/pr78818/pr78818-auto-warn.c: New test.
---
 gcc/config/msp430/msp430.c                                |  4 ++++
 .../gcc.target/msp430/pr78818/pr78818-auto-warn.c         | 15 +++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index c70121e..9c3720d 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -1975,6 +1975,10 @@ msp430_data_attr (tree * node,
   if (DECL_SECTION_NAME (* node))
     message = "%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 = "%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.
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c b/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c
new file mode 100644
index 0000000..1d92fe1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c
@@ -0,0 +1,15 @@
+/* { 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;
+}
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)
@ 2017-05-18 18:05 Jozef Lawrynowicz
  0 siblings, 0 replies; 8+ messages in thread
From: Jozef Lawrynowicz @ 2017-05-18 18:05 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

On 18 May 2017 at 16:46, Martin Sebor <msebor@gmail.com> wrote:
> +  if (!message && TREE_NAME_EQ (name, ATTR_PERSIST) && !TREE_STATIC (*
> node)
> +      && !TREE_PUBLIC (* node) && !DECL_EXTERNAL (* node))
> +    message = "%qE attribute has no effect on automatic variables";
>
> In code like this (both existing and new) where the format string
> is being assigned to a pointer that is then passed to one of the
> diagnostic functions, I believe the string literal needs to wrapped
> in G_() so that it can be translated.

Attached patch with the string wrapped in G_().

I'll update the other diagnostic strings without G_() in a separate patch.

Thanks,
Jozef

[-- Attachment #2: 0002-MSP430-Emit-warning-when-persistent-attribute-is-use.patch --]
[-- Type: application/octet-stream, Size: 2681 bytes --]

From 4790629950819460a22738da88b01c104012d98e Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@somniumtech.com>
Date: Fri, 5 May 2017 15:31:39 +0000
Subject: [PATCH 2/2] MSP430: Emit warning when persistent attribute is used on
 an automatic variable

2017-05-XX	Jozef Lawrynowicz	<jozef.l@somniumtech.com>
	
	gcc/
	PR target/78818
	* config/msp430/msp430.c (msp430_unique_section): Warn if .persistent
	attribute is used on an automatic variable.

	gcc/testsuite
	PR target/78818
	* gcc.target/msp430/pr78818/pr78818-auto-warn.c: New test.
---
 gcc/config/msp430/msp430.c                                |  5 +++++
 .../gcc.target/msp430/pr78818/pr78818-auto-warn.c         | 15 +++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index c70121e..959f235 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -39,6 +39,7 @@
 #include "expr.h"
 #include "langhooks.h"
 #include "builtins.h"
+#include "intl.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -1975,6 +1976,10 @@ msp430_data_attr (tree * node,
   if (DECL_SECTION_NAME (* node))
     message = "%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.
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c b/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c
new file mode 100644
index 0000000..1d92fe1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/pr78818/pr78818-auto-warn.c
@@ -0,0 +1,15 @@
+/* { 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;
+}
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)
@ 2017-05-30 11:51 Nick Clifton
  2017-06-08 15:50 ` Jozef Lawrynowicz
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 2017-05-30 11:51 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: gcc-patches

Hi Jozef,
   
> Attached patch with the string wrapped in G_().

When I applied this patch to the sources and ran the new test, I encountered
an internal compiler error:

 msp430-elf/gcc/xgcc [...] pr78818-auto-warn.c [...]
 [...]
 gcc/testsuite/gcc.target/msp430/pr78818-auto-warn.c: In function 'main':

 gcc/testsuite/gcc.target/msp430/pr78818-auto-warn.c:10:3: internal compiler error: in get, at cgraph.h:403

  0xd30d3b symtab_node::get(tree_node const*)
	gcc/current/gcc/cgraph.h:400

  0xd30d3b decl_section_name(tree_node const*)
	gcc/current/gcc/tree.c:700

  0xd9ff22 msp430_data_attr
                     gcc/current/gcc/config/msp430/msp430.c:1998


 It seems that there is a problem with calling the DECL_SECTION_NAME macro on the
 line just before your new code.  Are you able to reproduce this problem ?

Cheers
  Nick

  

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

end of thread, other threads:[~2017-06-15 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 15:47 [PATCH 2/2] [MSP430] Fix issues handling .persistent attribute (PR 78818) Jozef Lawrynowicz
2017-05-18 16:08 ` Martin Sebor
2017-05-18 18:05 Jozef Lawrynowicz
2017-05-30 11:51 Nick Clifton
2017-06-08 15:50 ` Jozef Lawrynowicz
2017-06-13 15:54   ` Nick Clifton
2017-06-13 17:46     ` Jozef Lawrynowicz
2017-06-15 13:39       ` Nick Clifton

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).