Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/rustc_codegen_spirv-types/src/target_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum TargetSpecVersion {
Rustc_1_94_0,
/// rustc 1.97.0 removed "allows-weak-linkage" key
Rustc_1_97_0,
/// rustc 1.99.0 didn't change anything upstream, we just made i128 be aligned to 16 to match most CPU platforms
Rustc_1_99_0,
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -72,7 +74,9 @@ impl TargetSpecVersion {
/// Returns the version of the target spec required for a certain rustc version. May return `None` if the version
/// is old enough to not need target specs.
pub fn from_rustc_version(rustc_version: Version) -> Self {
if rustc_version >= Version::new(1, 97, 0) {
if rustc_version >= Version::new(1, 99, 0) {
Rustc_1_99_0
} else if rustc_version >= Version::new(1, 97, 0) {
Rustc_1_97_0
} else if rustc_version >= Version::new(1, 94, 0) {
Rustc_1_94_0
Expand All @@ -99,6 +103,11 @@ impl TargetSpecVersion {
} else {
r#""allows-weak-linkage": false,"#
};
let data_layout = if self >= Rustc_1_99_0 {
"e-m:e-p:32:32:32-i64:64-i128:128-n8:16:32:64"
} else {
"e-m:e-p:32:32:32-i64:64-n8:16:32:64"
};
let os_crt_static_respected = if self >= Rustc_1_85_0 {
r#""crt-static-respected": true,"#
} else {
Expand All @@ -111,7 +120,7 @@ impl TargetSpecVersion {
"arch": "spirv",
"crt-objects-fallback": "false",
"crt-static-allows-dylibs": true,
"data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64",
"data-layout": "{data_layout}",
"dll-prefix": "",
"dll-suffix": ".spv.json",
"dynamic-linking": true,
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl SpirvTarget {
llvm_target: self.target().into(),
metadata: Default::default(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32:32-i64:64-n8:16:32:64".into(),
data_layout: "e-m:e-p:32:32:32-i64:64-i128:128-n8:16:32:64".into(),
arch: Arch::Other(SPIRV_ARCH.into()),
options: o,
}
Expand Down
21 changes: 21 additions & 0 deletions tests/compiletests/ui/arch/native_alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// build-pass

use spirv_std::spirv;

#[spirv(fragment)]
pub fn main() {
const _: () = {
assert!(align_of::<i8>() == 1);
assert!(align_of::<i16>() == 2);
assert!(align_of::<i32>() == 4);
assert!(align_of::<i64>() == 8);
assert!(align_of::<i128>() == 16);
assert!(align_of::<isize>() == 4);
assert!(align_of::<u8>() == 1);
assert!(align_of::<u16>() == 2);
assert!(align_of::<u32>() == 4);
assert!(align_of::<u64>() == 8);
assert!(align_of::<u128>() == 16);
assert!(align_of::<usize>() == 4);
};
}
Loading