-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously GEP on zero-sized arrays, would fail. This change fixes arrays to instead emit runtime arrays. I do not know if this will lead to any runtime cost, but it fixes all the compile errors.
- Loading branch information
1 parent
1932353
commit 4f9b334
Showing
9 changed files
with
81 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// build-fail | ||
#![cfg_attr(target_arch = "spirv", no_std)] | ||
use spirv_std::spirv; | ||
|
||
#[spirv(compute(threads(1, 1, 1)))] | ||
pub fn compute() { | ||
let array = [0; 0]; | ||
let x = array[0]; | ||
} |
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 @@ | ||
error: this operation will panic at runtime | ||
--> $DIR/array_0.rs:8:13 | ||
| | ||
8 | let x = array[0]; | ||
| ^^^^^^^^ index out of bounds: the length is 0 but the index is 0 | ||
| | ||
= note: `#[deny(unconditional_panic)]` on by default | ||
|
||
error: aborting due to 1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// build-pass | ||
#![cfg_attr(target_arch = "spirv", no_std)] | ||
use spirv_std::spirv; | ||
|
||
#[spirv(compute(threads(1, 1, 1)))] | ||
pub fn compute() { | ||
let mut array = [(); 0]; | ||
for i in 0..array.len() { | ||
array[i] = (); | ||
} | ||
} |
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,14 @@ | ||
#![cfg_attr(target_arch = "spirv", no_std)] | ||
use spirv_std::spirv; | ||
|
||
fn example<const LENGTH: usize>() { | ||
let mut array = [0; LENGTH]; | ||
for i in 0..array.len() { | ||
array[i] += i; | ||
} | ||
} | ||
|
||
#[spirv(compute(threads(1, 1, 1)))] | ||
pub fn compute() { | ||
example::<0>(); | ||
} |
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 @@ | ||
// build-fail | ||
|
||
#![cfg_attr(target_arch = "spirv", no_std)] | ||
use spirv_std::spirv; | ||
|
||
#[spirv(compute(threads(1, 1, 1)))] | ||
pub fn compute() { | ||
let mut array = [0; 0]; | ||
array[0] = 1; | ||
} |
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 @@ | ||
error: this operation will panic at runtime | ||
--> $DIR/oob_0_array.rs:9:5 | ||
| | ||
9 | array[0] = 1; | ||
| ^^^^^^^^ index out of bounds: the length is 0 but the index is 0 | ||
| | ||
= note: `#[deny(unconditional_panic)]` on by default | ||
|
||
error: aborting due to 1 previous error | ||
|