-
Notifications
You must be signed in to change notification settings - Fork 13.4k
add const_allocate intrinsic #79594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add const_allocate intrinsic #79594
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
528355c
add const_allocate intrisic
vn-ki b5b811a
review comments
vn-ki a6c4cbd
review comment and one more test
vn-ki 1b7fe09
add comment and bless some tests
vn-ki 899a59e
rename MemoryKind::Heap to ConstHeap; bless test
vn-ki bc6eb6f
move intrinsic to CTFE, add FIXME
vn-ki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.