re PR c/89946 (ICE in assemble_start_function, at varasm.c:1871)
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Apr 2019 07:28:35 +0000 (09:28 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 12 Apr 2019 07:28:35 +0000 (09:28 +0200)
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.

From-SVN: r270305

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr89946.c [new file with mode: 0644]
gcc/varasm.c

index a5dda2bedec37b42c2230313239da085c737f8f2..e728a9a1692119080f86cb14c9cca04441bc04be 100644 (file)
@@ -1,5 +1,11 @@
 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
index 2d118f2f73b89bc973f8ddfa496672ba86949e4f..aeba529b2325cd70355561efea656cc977be23ee 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2019-04-09  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-ada-spec.c (print_destructor): Deal with deleting destructors.
index d055a0897acd0be2b7cf5f91c2e24509344f369c..7e9df674f0b77e52ae52bb0c417871d0abed425e 100644 (file)
@@ -3988,10 +3988,29 @@ 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;
 }
 
index d66bc36415c0afd3f099f127636cde915e0e13ce..fe02e42e21d8a6d4446021a9cbce9890ca5a3441 100644 (file)
@@ -1,5 +1,8 @@
 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 --git a/gcc/testsuite/c-c++-common/pr89946.c b/gcc/testsuite/c-c++-common/pr89946.c
new file mode 100644 (file)
index 0000000..23acd63
--- /dev/null
@@ -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" } */
index da10ba3c51004fdbab31a5e6d6669f5c1d2113d1..cb43248ec492d8eb3287f24947b9c17b70cd18ac 100644 (file)
@@ -1865,28 +1865,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;
     }
 
@@ -1906,7 +1898,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)))