diff options
| author | Xiang Fan <sfanxiang@gmail.com> | 2019-06-06 08:39:20 +0800 |
|---|---|---|
| committer | Xiang Fan <sfanxiang@gmail.com> | 2019-09-28 04:45:08 +0800 |
| commit | f71e0daa29b232d8f689f77fecb84dcb87fce6da (patch) | |
| tree | 7e450a5f114b0973aad2b5b7799bc7f54c6776c7 /src/test/codegen/repeat-trusted-len.rs | |
| parent | a37fe2de697bb1a9d304e4e811836e125f944cd5 (diff) | |
| download | rust-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/repeat-trusted-len.rs')
| -rw-r--r-- | src/test/codegen/repeat-trusted-len.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/test/codegen/repeat-trusted-len.rs b/src/test/codegen/repeat-trusted-len.rs index 87f29f6047c..40399e8f76f 100644 --- a/src/test/codegen/repeat-trusted-len.rs +++ b/src/test/codegen/repeat-trusted-len.rs @@ -14,6 +14,10 @@ pub fn helper(_: usize) { // CHECK-LABEL: @repeat_take_collect #[no_mangle] pub fn repeat_take_collect() -> Vec<u8> { -// CHECK: call void @llvm.memset.p0i8.[[USIZE]](i8* {{(nonnull )?}}align 1 %{{[0-9]+}}, i8 42, [[USIZE]] 100000, i1 false) +// FIXME: At the time of writing LLVM transforms this loop into a single +// `store` and then a `memset` with size = 99999. The correct check should be: +// call void @llvm.memset.p0i8.[[USIZE]](i8* {{(nonnull )?}}align 1 %{{[a-z0-9.]+}}, i8 42, [[USIZE]] 100000, i1 false) + +// CHECK: call void @llvm.memset.p0i8.[[USIZE]](i8* {{(nonnull )?}}align 1 %{{[a-z0-9.]+}}, i8 42, [[USIZE]] 99999, i1 false) iter::repeat(42).take(100000).collect() } |
