public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/giulianob/heads/pfe_backport_dirty)] Backport PR c/89946 (ICE in assemble_start_function, at varasm.c:1871)
@ 2021-10-25 15:01 Giuliano Belinassi
  0 siblings, 0 replies; 2+ messages in thread
From: Giuliano Belinassi @ 2021-10-25 15:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a031d2467cdb73e5188fe49aa8af9e19f9bf8047

commit a031d2467cdb73e5188fe49aa8af9e19f9bf8047
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 12 09:28:35 2019 +0200

    Backport PR c/89946 (ICE in assemble_start_function, at varasm.c:1871)
    
    gcc/ChangeLog
    2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
    
            Backport from mainline
            2019-04-12  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/89946
            * varasm.c (assemble_start_function): Don't use tree_fits_uhwi_p
            and gcc_unreachable if it fails, just call tree_to_uhwi which
            verifies that too.  Test TREE_CHAIN instead of list_length > 1.
            Start warning message with a lower-case letter.  Formatting fixes.
    
            PR rtl-optimization/90026
            * cfgcleanup.c (try_optimize_cfg): When removing empty bb with no
            successors, look for BARRIERs inside of the whole BB_FOOTER chain
            rather than just at the start of it.  If e->src BB_FOOTER is not NULL
            in cfglayout mode, use emit_barrier_after_bb.
    
    gcc/c-family/ChangeLog
    2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
    
            Backport of mainline
            2019-04-12  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/89946
            * c-attribs.c (handle_patchable_function_entry_attribute): Add
            function comment.  Warn if arguments of the attribute are not positive
            integer constants.
    
    gcc/testsuite/ChangeLog
    2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
    
            Backport from mainline
            2019-04-12  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/89946
            * c-c++-common/pr89946.c: New test.
    
            PR rtl-optimization/90026
            * g++.dg/opt/pr90026.C: New test.

Diff:
---
 gcc/c-family/c-attribs.c             | 23 +++++++++++++++++++++--
 gcc/testsuite/c-c++-common/pr89946.c |  7 +++++++
 gcc/varasm.c                         | 23 ++++++++---------------
 3 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index b2820dd1586..f0d2b1ed500 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -3184,9 +3184,28 @@ handle_fallthrough_attribute (tree *, tree name, tree, int,
   return NULL_TREE;
 }
 
+/* Handle a "patchable_function_entry" attributes; arguments as in
+   struct attribute_spec.handler.  */
+
 static tree
-handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
+handle_patchable_function_entry_attribute (tree *, tree name, tree args,
+					   int, bool *no_add_attrs)
 {
-  /* Nothing to be done here.  */
+  for (; args; args = TREE_CHAIN (args))
+    {
+      tree val = TREE_VALUE (args);
+      if (val && TREE_CODE (val) != IDENTIFIER_NODE
+	  && TREE_CODE (val) != FUNCTION_DECL)
+	val = default_conversion (val);
+
+      if (!tree_fits_uhwi_p (val))
+	{
+	  warning (OPT_Wattributes,
+		   "%qE attribute argument %qE is not an integer constant",
+		   name, val);
+	  *no_add_attrs = true;
+	  return NULL_TREE;
+	}
+    }
   return NULL_TREE;
 }
diff --git a/gcc/testsuite/c-c++-common/pr89946.c b/gcc/testsuite/c-c++-common/pr89946.c
new file mode 100644
index 00000000000..23acd63fc6a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr89946.c
@@ -0,0 +1,7 @@
+/* PR c/89946 */
+
+__attribute__((patchable_function_entry (-1))) void foo (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument '-1' is not an integer constant" } */
+__attribute__((patchable_function_entry (5, -5))) void bar (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument '-5' is not an integer constant" } */
+int i, j;
+__attribute__((patchable_function_entry (i))) void baz (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument 'i' is not an integer constant" } */
+__attribute__((patchable_function_entry (2, j))) void qux (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument 'j' is not an integer constant" } */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 5711ba69555..0e6f20db361 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1839,28 +1839,20 @@ assemble_start_function (tree decl, const char *fnname)
       tree pp_val = TREE_VALUE (patchable_function_entry_attr);
       tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
 
-      if (tree_fits_uhwi_p (patchable_function_entry_value1))
-	patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
-      else
-	gcc_unreachable ();
-
+      patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
       patch_area_entry = 0;
-      if (list_length (pp_val) > 1)
+      if (TREE_CHAIN (pp_val) != NULL_TREE)
 	{
-	  tree patchable_function_entry_value2 =
-	    TREE_VALUE (TREE_CHAIN (pp_val));
-
-	  if (tree_fits_uhwi_p (patchable_function_entry_value2))
-	    patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
-	  else
-	    gcc_unreachable ();
+	  tree patchable_function_entry_value2
+	    = TREE_VALUE (TREE_CHAIN (pp_val));
+	  patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
 	}
     }
 
   if (patch_area_entry > patch_area_size)
     {
       if (patch_area_size > 0)
-	warning (OPT_Wattributes, "Patchable function entry > size");
+	warning (OPT_Wattributes, "patchable function entry > size");
       patch_area_entry = 0;
     }
 
@@ -1880,7 +1872,8 @@ assemble_start_function (tree decl, const char *fnname)
   /* And the area after the label.  Record it if we haven't done so yet.  */
   if (patch_area_size > patch_area_entry)
     targetm.asm_out.print_patchable_function_entry (asm_out_file,
-					     patch_area_size-patch_area_entry,
+						    patch_area_size
+						    - patch_area_entry,
 						    patch_area_entry == 0);
 
   if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))


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

* [gcc(refs/users/giulianob/heads/pfe_backport_dirty)] Backport PR c/89946 (ICE in assemble_start_function, at varasm.c:1871)
@ 2021-10-11 20:34 Giuliano Belinassi
  0 siblings, 0 replies; 2+ messages in thread
From: Giuliano Belinassi @ 2021-10-11 20:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ef463982d6047673dd83c1c94e6981f4090a1757

commit ef463982d6047673dd83c1c94e6981f4090a1757
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 12 09:28:35 2019 +0200

    Backport PR c/89946 (ICE in assemble_start_function, at varasm.c:1871)
    
            PR c/89946
            * varasm.c (assemble_start_function): Don't use tree_fits_uhwi_p
            and gcc_unreachable if it fails, just call tree_to_uhwi which
            verifies that too.  Test TREE_CHAIN instead of list_length > 1.
            Start warning message with a lower-case letter.  Formatting fixes.
    c-family/
            * c-attribs.c (handle_patchable_function_entry_attribute): Add
            function comment.  Warn if arguments of the attribute are not positive
            integer constants.
    testsuite/
            * c-c++-common/pr89946.c: New test.

Diff:
---
 gcc/ChangeLog                        | 17 +++++++++++++++++
 gcc/c-family/ChangeLog               | 10 ++++++++++
 gcc/c-family/c-attribs.c             | 23 +++++++++++++++++++++--
 gcc/testsuite/ChangeLog              | 11 +++++++++++
 gcc/testsuite/c-c++-common/pr89946.c |  7 +++++++
 gcc/varasm.c                         | 23 ++++++++---------------
 6 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b76758ea45b..6c5cf067063 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,20 @@
+2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
+
+	Backport from mainline
+	2019-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/89946
+	* varasm.c (assemble_start_function): Don't use tree_fits_uhwi_p
+	and gcc_unreachable if it fails, just call tree_to_uhwi which
+	verifies that too.  Test TREE_CHAIN instead of list_length > 1.
+	Start warning message with a lower-case letter.  Formatting fixes.
+
+	PR rtl-optimization/90026
+	* cfgcleanup.c (try_optimize_cfg): When removing empty bb with no
+	successors, look for BARRIERs inside of the whole BB_FOOTER chain
+	rather than just at the start of it.  If e->src BB_FOOTER is not NULL
+	in cfglayout mode, use emit_barrier_after_bb.
+
 2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
 
 	Backport from mainline
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 9442adb234e..2d76461fd60 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,13 @@
+2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
+
+	Backport of mainline
+	2019-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/89946
+	* c-attribs.c (handle_patchable_function_entry_attribute): Add
+	function comment.  Warn if arguments of the attribute are not positive
+	integer constants.
+
 2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
 
 	Backport from mainline
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index b2820dd1586..f0d2b1ed500 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -3184,9 +3184,28 @@ handle_fallthrough_attribute (tree *, tree name, tree, int,
   return NULL_TREE;
 }
 
+/* Handle a "patchable_function_entry" attributes; arguments as in
+   struct attribute_spec.handler.  */
+
 static tree
-handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
+handle_patchable_function_entry_attribute (tree *, tree name, tree args,
+					   int, bool *no_add_attrs)
 {
-  /* Nothing to be done here.  */
+  for (; args; args = TREE_CHAIN (args))
+    {
+      tree val = TREE_VALUE (args);
+      if (val && TREE_CODE (val) != IDENTIFIER_NODE
+	  && TREE_CODE (val) != FUNCTION_DECL)
+	val = default_conversion (val);
+
+      if (!tree_fits_uhwi_p (val))
+	{
+	  warning (OPT_Wattributes,
+		   "%qE attribute argument %qE is not an integer constant",
+		   name, val);
+	  *no_add_attrs = true;
+	  return NULL_TREE;
+	}
+    }
   return NULL_TREE;
 }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 46c0d937aa6..e5ffe726153 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
+
+	Backport from mainline
+	2019-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/89946
+	* c-c++-common/pr89946.c: New test.
+
+	PR rtl-optimization/90026
+	* g++.dg/opt/pr90026.C: New test.
+
 2021-10-07  Giuliano Belinassi  <gbelinassi@suse.de>
 
 	Backport from mainline
diff --git a/gcc/testsuite/c-c++-common/pr89946.c b/gcc/testsuite/c-c++-common/pr89946.c
new file mode 100644
index 00000000000..23acd63fc6a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr89946.c
@@ -0,0 +1,7 @@
+/* PR c/89946 */
+
+__attribute__((patchable_function_entry (-1))) void foo (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument '-1' is not an integer constant" } */
+__attribute__((patchable_function_entry (5, -5))) void bar (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument '-5' is not an integer constant" } */
+int i, j;
+__attribute__((patchable_function_entry (i))) void baz (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument 'i' is not an integer constant" } */
+__attribute__((patchable_function_entry (2, j))) void qux (void) {}	/* { dg-warning "'patchable_function_entry' attribute argument 'j' is not an integer constant" } */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 5711ba69555..0e6f20db361 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1839,28 +1839,20 @@ assemble_start_function (tree decl, const char *fnname)
       tree pp_val = TREE_VALUE (patchable_function_entry_attr);
       tree patchable_function_entry_value1 = TREE_VALUE (pp_val);
 
-      if (tree_fits_uhwi_p (patchable_function_entry_value1))
-	patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
-      else
-	gcc_unreachable ();
-
+      patch_area_size = tree_to_uhwi (patchable_function_entry_value1);
       patch_area_entry = 0;
-      if (list_length (pp_val) > 1)
+      if (TREE_CHAIN (pp_val) != NULL_TREE)
 	{
-	  tree patchable_function_entry_value2 =
-	    TREE_VALUE (TREE_CHAIN (pp_val));
-
-	  if (tree_fits_uhwi_p (patchable_function_entry_value2))
-	    patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
-	  else
-	    gcc_unreachable ();
+	  tree patchable_function_entry_value2
+	    = TREE_VALUE (TREE_CHAIN (pp_val));
+	  patch_area_entry = tree_to_uhwi (patchable_function_entry_value2);
 	}
     }
 
   if (patch_area_entry > patch_area_size)
     {
       if (patch_area_size > 0)
-	warning (OPT_Wattributes, "Patchable function entry > size");
+	warning (OPT_Wattributes, "patchable function entry > size");
       patch_area_entry = 0;
     }
 
@@ -1880,7 +1872,8 @@ assemble_start_function (tree decl, const char *fnname)
   /* And the area after the label.  Record it if we haven't done so yet.  */
   if (patch_area_size > patch_area_entry)
     targetm.asm_out.print_patchable_function_entry (asm_out_file,
-					     patch_area_size-patch_area_entry,
+						    patch_area_size
+						    - patch_area_entry,
 						    patch_area_entry == 0);
 
   if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))


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

end of thread, other threads:[~2021-10-25 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 15:01 [gcc(refs/users/giulianob/heads/pfe_backport_dirty)] Backport PR c/89946 (ICE in assemble_start_function, at varasm.c:1871) Giuliano Belinassi
  -- strict thread matches above, loose matches on Subject: below --
2021-10-11 20:34 Giuliano Belinassi

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