Skip to content

Commit

Permalink
test(std): Add codegen test for array::from_fn optimization
Browse files Browse the repository at this point in the history
This commit adds a new test file 'array-from_fn.rs' to the codegen test suite.
The test checks the behavior of std::array::from_fn under different optimization levels:

1. At opt-level=0 (debug build), it verifies that the core::array::Guard
   is present in the generated code.
2. At opt-level=s (size optimization), it ensures that the Guard is
   optimized out.

This test helps ensure that the compiler correctly optimizes array::from_fn
calls in release builds while maintaining safety checks in debug builds.
  • Loading branch information
cblh committed Aug 10, 2024
1 parent bca0c5f commit 3dc083d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/codegen/array-from_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ revisions: NORMAL OPT
//@ [NORMAL] compile-flags: -C opt-level=0 -C debuginfo=2
//@ [OPT] compile-flags: -C opt-level=s -C debuginfo=0

#![crate_type = "lib"]
#![feature(array_from_fn)]

#[no_mangle]
pub fn iota() -> [u8; 16] {
// OPT-NOT: core..array..Guard
// NORMAL: core..array..Guard
std::array::from_fn(|i| i as _)
}

0 comments on commit 3dc083d

Please sign in to comment.