You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[no_mangle]pubunsafeexternfnmemset(muts:*mutu8,c:c_int,n:usize) -> *mutu8{let end = s.add(n);let c = c asu8;while s != end {*s = c;
s = s.add(1);}
end.sub(n)}
LLVM misoptimizes this function into an infinite recursion because it recognizes that the inner loop can be replaced by a call to memset. Normally this optimization is disabled inside functions called memset but since the body of the function is moved to a function with rust abi, this check doesn't work.
The text was updated successfully, but these errors were encountered:
Confirmed here on stable, beta, and nightly using libc 0.2.4. I rewrote your function to use offset instead of "add", along with a relatively minimal test case.
externcrate libc;#[no_mangle]pubunsafeexternfnmemset(muts:*mutu8,c: libc::c_int,n:usize) -> *mutu8{let end = s.offset(n asisize);let c = c asu8;while s != end {*s = c;
s = s.offset(1);}
s
}fnmain(){letmut arr = [0u8;32];unsafe{memset(&mut arr[0],1, arr.len());}assert_eq!(arr,[1u8;32]);}
Consider the following code:
LLVM misoptimizes this function into an infinite recursion because it recognizes that the inner loop can be replaced by a call to memset. Normally this optimization is disabled inside functions called
memset
but since the body of the function is moved to a function with rust abi, this check doesn't work.The text was updated successfully, but these errors were encountered: