https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109258

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Or we could fix the go FE to make memcmp properly pure:
2023-03-23  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/109258
        * go-gcc.cc (Gcc_backend): Add new static data member builtin_pure.
        (Gcc_backend::Gcc_backend): Pass builtin_pure for BUILT_IN_MEMCMP.
        (Gcc_backend::define_builtin): Handle builtin_pure in flags.

--- gcc/go/go-gcc.cc.jj 2023-01-18 12:22:10.396234744 +0100
+++ gcc/go/go-gcc.cc    2023-03-23 11:16:08.958054518 +0100
@@ -543,6 +543,7 @@ private:
   static const int builtin_const = 1 << 0;
   static const int builtin_noreturn = 1 << 1;
   static const int builtin_novops = 1 << 2;
+  static const int builtin_pure = 1 << 3;

   void
   define_builtin(built_in_function bcode, const char* name, const char*
libname,
@@ -601,7 +602,7 @@ Gcc_backend::Gcc_backend()
                                                const_ptr_type_node,
                                                size_type_node,
                                                NULL_TREE),
-                      0);
+                      builtin_pure);

   // We use __builtin_memmove for copying data.
   this->define_builtin(BUILT_IN_MEMMOVE, "__builtin_memmove", "memmove",
@@ -3596,6 +3597,8 @@ Gcc_backend::define_builtin(built_in_fun
                                   libname, NULL_TREE);
   if ((flags & builtin_const) != 0)
     TREE_READONLY(decl) = 1;
+  if ((flags & builtin_pure) != 0)
+    DECL_PURE_P(decl) = 1;
   if ((flags & builtin_noreturn) != 0)
     TREE_THIS_VOLATILE(decl) = 1;
   if ((flags & builtin_novops) != 0)
@@ -3608,6 +3611,8 @@ Gcc_backend::define_builtin(built_in_fun
                                  NULL, NULL_TREE);
       if ((flags & builtin_const) != 0)
        TREE_READONLY(decl) = 1;
+      if ((flags & builtin_pure) != 0)
+       DECL_PURE_P(decl) = 1;
       if ((flags & builtin_noreturn) != 0)
        TREE_THIS_VOLATILE(decl) = 1;
       if ((flags & builtin_novops) != 0)

Or both.

Reply via email to