go: don't crash if __atomic_fetch_add functions are used
authorIan Lance Taylor <iant@golang.org>
Thu, 10 Nov 2022 00:05:08 +0000 (16:05 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 10 Nov 2022 00:06:10 +0000 (16:06 -0800)
The Go frontend only generates __atomic_add_fetch, but in some cases
thost calls become __atomic_fetch_add.

Patch originally by Marc Poulhiès.

PR target/107581
* go-gcc.cc (Gcc_backend::Gcc_backend): Define
__atomic_fetch_add_{4,8}.

gcc/go/go-gcc.cc

index 1ba7206..6e5887a 100644 (file)
@@ -886,16 +886,20 @@ Gcc_backend::Gcc_backend()
                                uint32_type_node,
                                integer_type_node,
                                NULL_TREE);
-  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_4, "__atomic_add_fetch_4", NULL,
-                       t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_4, "__atomic_add_fetch_4",
+                      NULL, t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_FETCH_ADD_4, "__atomic_fetch_add_4",
+                      NULL, t, 0);
 
   t = build_function_type_list(uint64_type_node,
                                ptr_type_node,
                                uint64_type_node,
                                integer_type_node,
                                NULL_TREE);
-  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_8, "__atomic_add_fetch_8", NULL,
-                       t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_8, "__atomic_add_fetch_8",
+                      NULL, t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_FETCH_ADD_8, "__atomic_fetch_add_8",
+                      NULL, t, 0);
 
   t = build_function_type_list(unsigned_char_type_node,
                               ptr_type_node,