about summary refs log tree commit diff
path: root/src/test/codegen/vec-optimizes-away.rs
diff options
context:
space:
mode:
authorXiang Fan <sfanxiang@gmail.com>2019-06-06 08:39:20 +0800
committerXiang Fan <sfanxiang@gmail.com>2019-09-28 04:45:08 +0800
commitf71e0daa29b232d8f689f77fecb84dcb87fce6da (patch)
tree7e450a5f114b0973aad2b5b7799bc7f54c6776c7 /src/test/codegen/vec-optimizes-away.rs
parenta37fe2de697bb1a9d304e4e811836e125f944cd5 (diff)
downloadrust-f71e0daa29b232d8f689f77fecb84dcb87fce6da.tar.gz
rust-f71e0daa29b232d8f689f77fecb84dcb87fce6da.zip
Add llvm.sideeffect to potential infinite loops and recursions
LLVM assumes that a thread will eventually cause side effect. This is
not true in Rust if a loop or recursion does nothing in its body,
causing undefined behavior even in common cases like `loop {}`.
Inserting llvm.sideeffect fixes the undefined behavior.

As a micro-optimization, only insert llvm.sideeffect when jumping back
in blocks or calling a function.

A patch for LLVM is expected to allow empty non-terminate code by
default and fix this issue from LLVM side.

https://github.com/rust-lang/rust/issues/28728
Diffstat (limited to 'src/test/codegen/vec-optimizes-away.rs')
-rw-r--r--src/test/codegen/vec-optimizes-away.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/codegen/vec-optimizes-away.rs b/src/test/codegen/vec-optimizes-away.rs
index ebede0908c6..08d0332651c 100644
--- a/src/test/codegen/vec-optimizes-away.rs
+++ b/src/test/codegen/vec-optimizes-away.rs
@@ -8,6 +8,6 @@
 pub fn sum_me() -> i32 {
     // CHECK-LABEL: @sum_me
     // CHECK-NEXT: {{^.*:$}}
-    // CHECK-NEXT: ret i32 6
+    // CHECK: ret i32 6
     vec![1, 2, 3].iter().sum::<i32>()
 }