-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #79594 - vn-ki:const-eval-intrinsic, r=oli-obk
add const_allocate intrinsic r? `@oli-obk` fixes #75390
- Loading branch information
Showing
28 changed files
with
424 additions
and
141 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
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
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
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
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
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
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
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
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
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
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
17 changes: 17 additions & 0 deletions
17
src/test/ui/consts/const-eval/heap/alloc_intrinsic_errors.rs
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const FOO: i32 = foo(); | ||
const fn foo() -> i32 { | ||
unsafe { | ||
let _ = intrinsics::const_allocate(4, 3) as * mut i32; | ||
//~^ error: any use of this value will cause an error [const_err] | ||
} | ||
1 | ||
|
||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/consts/const-eval/heap/alloc_intrinsic_errors.stderr
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/alloc_intrinsic_errors.rs:10:17 | ||
| | ||
LL | const FOO: i32 = foo(); | ||
| ----------------------- | ||
... | ||
LL | let _ = intrinsics::const_allocate(4, 3) as * mut i32; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| align has to be a power of 2, `3` is not a power of 2 | ||
| inside `foo` at $DIR/alloc_intrinsic_errors.rs:10:17 | ||
| inside `FOO` at $DIR/alloc_intrinsic_errors.rs:7:18 | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
src/test/ui/consts/const-eval/heap/alloc_intrinsic_nontransient.rs
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// run-pass | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const FOO: &i32 = foo(); | ||
|
||
const fn foo() -> &'static i32 { | ||
let t = unsafe { | ||
let i = intrinsics::const_allocate(4, 4) as * mut i32; | ||
*i = 20; | ||
i | ||
}; | ||
unsafe { &*t } | ||
} | ||
fn main() { | ||
assert_eq!(*FOO, 20) | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/consts/const-eval/heap/alloc_intrinsic_nontransient_fail.rs
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const FOO: *const i32 = foo(); | ||
//~^ ERROR untyped pointers are not allowed in constant | ||
|
||
const fn foo() -> &'static i32 { | ||
let t = unsafe { | ||
let i = intrinsics::const_allocate(4, 4) as * mut i32; | ||
*i = 20; | ||
i | ||
}; | ||
unsafe { &*t } | ||
} | ||
fn main() { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/consts/const-eval/heap/alloc_intrinsic_nontransient_fail.stderr
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: untyped pointers are not allowed in constant | ||
--> $DIR/alloc_intrinsic_nontransient_fail.rs:7:1 | ||
| | ||
LL | const FOO: *const i32 = foo(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
src/test/ui/consts/const-eval/heap/alloc_intrinsic_transient.rs
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// run-pass | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const FOO: i32 = foo(); | ||
|
||
const fn foo() -> i32 { | ||
let t = unsafe { | ||
let i = intrinsics::const_allocate(4, 4) as * mut i32; | ||
*i = 20; | ||
i | ||
}; | ||
unsafe { *t } | ||
} | ||
fn main() { | ||
assert_eq!(FOO, 20); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/consts/const-eval/heap/alloc_intrinsic_uninit.rs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// compile-test | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) }; | ||
//~^ error: it is undefined behavior to use this value | ||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/consts/const-eval/heap/alloc_intrinsic_uninit.stderr
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/alloc_intrinsic_uninit.rs:8:1 | ||
| | ||
LL | const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .<deref>, but expected initialized plain (non-pointer) bytes | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
10 changes: 10 additions & 0 deletions
10
src/test/ui/consts/const-eval/heap/alloc_intrinsic_untyped.rs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32}; | ||
//~^ error: untyped pointers are not allowed in constant | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/consts/const-eval/heap/alloc_intrinsic_untyped.stderr
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: untyped pointers are not allowed in constant | ||
--> $DIR/alloc_intrinsic_untyped.rs:7:1 | ||
| | ||
LL | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32}; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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
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,21 +1,18 @@ | ||
error[E0080]: evaluation of constant value failed | ||
error: any use of this value will cause an error | ||
--> $DIR/unwind-abort.rs:5:5 | ||
| | ||
LL | panic!() | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:5:5 | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/unwind-abort.rs:8:15 | ||
| | ||
| ^^^^^^^^ | ||
| | | ||
| the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:5:5 | ||
| inside `foo` at $SRC_DIR/std/src/macros.rs:LL:COL | ||
| inside `_` at $DIR/unwind-abort.rs:8:15 | ||
... | ||
LL | const _: () = foo(); | ||
| --------------^^^^^- | ||
| | | ||
| referenced constant has errors | ||
| -------------------- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Oops, something went wrong.