https://gcc.gnu.org/g:6af6c65c19ea1801adbee1089c6f7af7730406c8

commit 6af6c65c19ea1801adbee1089c6f7af7730406c8
Author: Yangyu Chen <c...@cyyself.name>
Date:   Thu Oct 24 15:10:57 2024 +0800

    RISC-V: Split riscv_process_target_attr with const char *args argument
    
    This patch splits static bool riscv_process_target_attr
    (tree args, location_t loc) into two functions:
    
    - bool riscv_process_target_attr (const char *args, location_t loc)
    - static bool riscv_process_target_attr (tree args, location_t loc)
    
    Thus, we can call `riscv_process_target_attr` with a `const char *`
    argument.  This is useful for implementation of `target_version`
    attribute.
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-protos.h (riscv_process_target_attr): New.
            * config/riscv/riscv-target-attr.cc (riscv_process_target_attr):
            Split into two functions with const char *args argument
    
    (cherry picked from commit a57c16e50d478cc413e3e530db21de693e4eb2ae)

Diff:
---
 gcc/config/riscv/riscv-protos.h       |  2 ++
 gcc/config/riscv/riscv-target-attr.cc | 65 ++++++++++++++++++++---------------
 2 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 0a6b43f0c767..4ed04321d32c 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -805,6 +805,8 @@ extern bool riscv_use_divmod_expander (void);
 void riscv_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int);
 extern bool
 riscv_option_valid_attribute_p (tree, tree, tree, int);
+extern bool
+riscv_process_target_attr (const char *, location_t);
 extern void
 riscv_override_options_internal (struct gcc_options *);
 extern void riscv_option_override (void);
diff --git a/gcc/config/riscv/riscv-target-attr.cc 
b/gcc/config/riscv/riscv-target-attr.cc
index bf14ade5ce08..8ce9607b3c9b 100644
--- a/gcc/config/riscv/riscv-target-attr.cc
+++ b/gcc/config/riscv/riscv-target-attr.cc
@@ -304,35 +304,13 @@ num_occurrences_in_str (char c, char *str)
   return res;
 }
 
-/* Parse the tree in ARGS that contains the target attribute information
+/* Parse the string in ARGS that contains the target attribute information
    and update the global target options space.  */
 
-static bool
-riscv_process_target_attr (tree args, location_t loc)
+bool
+riscv_process_target_attr (const char *args, location_t loc)
 {
-  if (TREE_CODE (args) == TREE_LIST)
-    {
-      do
-       {
-         tree head = TREE_VALUE (args);
-         if (head)
-           {
-             if (!riscv_process_target_attr (head, loc))
-               return false;
-           }
-         args = TREE_CHAIN (args);
-      } while (args);
-
-      return true;
-    }
-
-  if (TREE_CODE (args) != STRING_CST)
-    {
-      error_at (loc, "attribute %<target%> argument not a string");
-      return false;
-    }
-
-  size_t len = strlen (TREE_STRING_POINTER (args));
+  size_t len = strlen (args);
 
   /* No need to emit warning or error on empty string here, generic code 
already
      handle this case.  */
@@ -343,7 +321,7 @@ riscv_process_target_attr (tree args, location_t loc)
 
   std::unique_ptr<char[]> buf (new char[len+1]);
   char *str_to_check = buf.get ();
-  strcpy (str_to_check, TREE_STRING_POINTER (args));
+  strcpy (str_to_check, args);
 
   /* Used to catch empty spaces between semi-colons i.e.
      attribute ((target ("attr1;;attr2"))).  */
@@ -366,7 +344,7 @@ riscv_process_target_attr (tree args, location_t loc)
   if (num_attrs != num_semicolons + 1)
     {
       error_at (loc, "malformed %<target(\"%s\")%> attribute",
-               TREE_STRING_POINTER (args));
+               args);
       return false;
     }
 
@@ -376,6 +354,37 @@ riscv_process_target_attr (tree args, location_t loc)
   return true;
 }
 
+/* Parse the tree in ARGS that contains the target attribute information
+   and update the global target options space.  */
+
+static bool
+riscv_process_target_attr (tree args, location_t loc)
+{
+  if (TREE_CODE (args) == TREE_LIST)
+    {
+      do
+       {
+         tree head = TREE_VALUE (args);
+         if (head)
+           {
+             if (!riscv_process_target_attr (head, loc))
+               return false;
+           }
+         args = TREE_CHAIN (args);
+      } while (args);
+
+      return true;
+    }
+
+  if (TREE_CODE (args) != STRING_CST)
+    {
+      error_at (loc, "attribute %<target%> argument not a string");
+      return false;
+    }
+
+  return riscv_process_target_attr (TREE_STRING_POINTER (args), loc);
+}
+
 /* Implement TARGET_OPTION_VALID_ATTRIBUTE_P.
    This is used to process attribute ((target ("..."))).
    Note, that riscv_set_current_function() has not been called before,

Reply via email to