about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-28 00:31:26 +0000
committerbors <bors@rust-lang.org>2025-02-28 00:31:26 +0000
commite6059f522264ed2ec3ede21bfeef15bf3d814bf7 (patch)
treef867882751d2de0b3f660038cd65f1adc4a36bd3 /tests/codegen
parentf45d4acf1bb635aa010f19f8a749eed8293203b3 (diff)
parentfbe0075a86601e490ae217f3b291768759c39930 (diff)
downloadrust-e6059f522264ed2ec3ede21bfeef15bf3d814bf7.tar.gz
rust-e6059f522264ed2ec3ede21bfeef15bf3d814bf7.zip
Auto merge of #137669 - DianQK:fn-atts-virtual, r=saethlin
Don't infer attributes of virtual calls based on the function body

Fixes (after backport) #137646.
Since we don't know the exact implementation of the virtual call, it might write to parameters, we can't infer the readonly attribute.
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/virtual-call-attrs-issue-137646.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/codegen/virtual-call-attrs-issue-137646.rs b/tests/codegen/virtual-call-attrs-issue-137646.rs
new file mode 100644
index 00000000000..5e453947f27
--- /dev/null
+++ b/tests/codegen/virtual-call-attrs-issue-137646.rs
@@ -0,0 +1,37 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/137646.
+//! Since we don't know the exact implementation of the virtual call,
+//! it might write to parameters, we can't infer the readonly attribute.
+//@ compile-flags: -C opt-level=3 -C no-prepopulate-passes
+
+#![crate_type = "lib"]
+#![feature(rustc_attrs)]
+
+pub trait Trait {
+    #[rustc_nounwind]
+    fn m(&self, _: (i32, i32, i32)) {}
+}
+
+#[no_mangle]
+pub fn foo(trait_: &dyn Trait) {
+    // CHECK-LABEL: @foo(
+    // CHECK: call void
+    // CHECK-NOT: readonly
+    trait_.m((1, 1, 1));
+}
+
+#[no_mangle]
+#[rustc_nounwind]
+pub fn foo_nounwind(trait_: &dyn Trait) {
+    // CHECK-LABEL: @foo_nounwind(
+    // FIXME: Here should be invoke.
+    // COM: CHECK: invoke
+    trait_.m((1, 1, 1));
+}
+
+#[no_mangle]
+pub extern "C" fn c_nounwind(trait_: &dyn Trait) {
+    // CHECK-LABEL: @c_nounwind(
+    // FIXME: Here should be invoke.
+    // COM: CHECK: invoke
+    trait_.m((1, 1, 1));
+}