about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-21 17:38:38 +0000
committerbors <bors@rust-lang.org>2022-12-21 17:38:38 +0000
commita8207df49e45edd654965a52ebbad19b30093cff (patch)
treebf1d51153bb50d81d0e391e8d694a2b1f9f87d97 /src/test/codegen
parent49143814e145c711e9807fac6467c14090663796 (diff)
parenta65ec44779ab2c01ba937b40496ca648626d0308 (diff)
downloadrust-a8207df49e45edd654965a52ebbad19b30093cff.tar.gz
rust-a8207df49e45edd654965a52ebbad19b30093cff.zip
Auto merge of #105812 - ojeda:no-jump-tables, r=nikic
Add `-Zno-jump-tables`

This flag mimics GCC/Clang's `-fno-jump-tables` [1][2], which makes the codegen backend avoid generating jump tables when lowering switches.

In the case of LLVM, the `"no-jump-tables"="true"` function attribute is added to every function.

The kernel currently needs it for x86 when enabling IBT [3], as well as for Alpha (plus VDSO objects in MIPS/LoongArch).

[1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fno-jump-tables
[2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fjump-tables
[3] https://github.com/torvalds/linux/blob/v6.1/arch/x86/Makefile#L75-L83
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/no-jump-tables.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/codegen/no-jump-tables.rs b/src/test/codegen/no-jump-tables.rs
new file mode 100644
index 00000000000..8e2cb47566e
--- /dev/null
+++ b/src/test/codegen/no-jump-tables.rs
@@ -0,0 +1,22 @@
+// Test that the `no-jump-tables` function attribute are (not) emitted when
+// the `-Zno-jump-tables` flag is (not) set.
+
+// revisions: unset set
+// needs-llvm-components: x86
+// compile-flags: --target x86_64-unknown-linux-gnu
+// [set] compile-flags: -Zno-jump-tables
+
+#![crate_type = "lib"]
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[no_mangle]
+pub fn foo() {
+    // CHECK: @foo() unnamed_addr #0
+
+    // unset-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
+    // set: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
+}