-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expand successful-promotion test a bit
- Loading branch information
Showing
1 changed file
with
18 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
// run-pass | ||
// revisions: noopt opt opt_with_overflow_checks | ||
//[noopt]compile-flags: -C opt-level=0 | ||
//[opt]compile-flags: -O | ||
//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O | ||
|
||
// compile-flags: -O | ||
// build-pass | ||
#[allow(arithmetic_overflow)] | ||
|
||
fn foo(_: &'static [&'static str]) {} | ||
fn bar(_: &'static [&'static str; 3]) {} | ||
const fn baz_i32(_: &'static i32) {} | ||
const fn baz_u32(_: &'static u32) {} | ||
const fn assert_static<T>(_: &'static T) {} | ||
|
||
const fn fail() -> i32 { 1/0 } | ||
const C: i32 = { | ||
// Promoted that fails to evaluate in dead code -- this must work | ||
// (for backwards compatibility reasons). | ||
if false { | ||
baz_i32(&fail()); | ||
assert_static(&fail()); | ||
} | ||
42 | ||
}; | ||
|
||
fn main() { | ||
foo(&["a", "b", "c"]); | ||
bar(&["d", "e", "f"]); | ||
assert_static(&["a", "b", "c"]); | ||
assert_static(&["d", "e", "f"]); | ||
assert_eq!(C, 42); | ||
|
||
// make sure that these do not cause trouble despite overflowing | ||
baz_u32(&(0-1)); | ||
baz_i32(&-i32::MIN); | ||
assert_static(&(0-1)); | ||
assert_static(&-i32::MIN); | ||
|
||
// div-by-non-0 is okay | ||
baz_i32(&(1/1)); | ||
baz_i32(&(1%1)); | ||
assert_static(&(1/1)); | ||
assert_static(&(1%1)); | ||
|
||
// in-bounds array access is okay | ||
baz_i32(&([1,2,3][0] + 1)); | ||
assert_static(&([1,2,3][0] + 1)); | ||
assert_static(&[[1,2][1]]); | ||
|
||
// Top-level projections do not get promoted, so no error here. | ||
// Top-level projections are not part of the promoted, so no error here. | ||
if false { | ||
#[allow(unconditional_panic)] | ||
baz_i32(&[1,2,3][4]); | ||
assert_static(&[1,2,3][4]); | ||
} | ||
} |