gccrs: intrinsics: Add `sorry_handler` intrinsic handler
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 25 Oct 2022 08:48:43 +0000 (10:48 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 21 Feb 2023 11:36:42 +0000 (12:36 +0100)
gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (sorry_handler): New intrinsic handler.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-3.rs: New test.

gcc/rust/backend/rust-compile-intrinsic.cc
gcc/testsuite/rust/compile/torture/intrinsics-3.rs [new file with mode: 0644]

index a418b86..2a2091c 100644 (file)
@@ -93,6 +93,15 @@ prefetch_write_data (Context *ctx, TyTy::FnType *fntype)
   return prefetch_data_handler (ctx, fntype, Prefetch::Write);
 }
 
+static inline tree
+sorry_handler (Context *ctx, TyTy::FnType *fntype)
+{
+  rust_sorry_at (fntype->get_locus (), "intrinsic %qs is not yet implemented",
+                fntype->get_identifier ().c_str ());
+
+  return error_mark_node;
+}
+
 static const std::map<std::string,
                      std::function<tree (Context *, TyTy::FnType *)>>
   generic_intrinsics = {
@@ -107,6 +116,7 @@ static const std::map<std::string,
     {"copy_nonoverlapping", &copy_nonoverlapping_handler},
     {"prefetch_read_data", &prefetch_read_data},
     {"prefetch_write_data", &prefetch_write_data},
+    {"atomic_load", &sorry_handler},
 };
 
 Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-3.rs b/gcc/testsuite/rust/compile/torture/intrinsics-3.rs
new file mode 100644 (file)
index 0000000..1acb353
--- /dev/null
@@ -0,0 +1,9 @@
+extern "rust-intrinsic" {
+    fn not_an_intrinsic();
+    fn atomic_load(); // { dg-message "sorry, unimplemented: intrinsic .atomic_load. is not yet implemented" }
+}
+
+fn main() {
+    unsafe { not_an_intrinsic() }; // { dg-error "unknown builtin intrinsic: not_an_intrinsic" }
+    unsafe { atomic_load() };
+}