-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix handling of ZST in win64 ABI on windows-msvc targets #135204
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use std::str::FromStr; | ||
use std::{fmt, iter}; | ||
|
||
pub use rustc_abi::{Reg, RegKind}; | ||
pub use rustc_abi::{ExternAbi, Reg, RegKind}; | ||
use rustc_macros::HashStable_Generic; | ||
use rustc_span::Symbol; | ||
|
||
use crate::abi::{ | ||
self, AddressSpace, Align, BackendRepr, HasDataLayout, Pointer, Size, TyAbiInterface, | ||
TyAndLayout, | ||
}; | ||
use crate::spec::abi::Abi as SpecAbi; | ||
use crate::spec::{self, HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi}; | ||
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi}; | ||
|
||
mod aarch64; | ||
mod amdgpu; | ||
|
@@ -627,20 +626,20 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> { | |
#[derive(Copy, Clone, Debug, HashStable_Generic)] | ||
pub enum AdjustForForeignAbiError { | ||
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs. | ||
Unsupported { arch: Symbol, abi: spec::abi::Abi }, | ||
Unsupported { arch: Symbol, abi: ExternAbi }, | ||
} | ||
|
||
impl<'a, Ty> FnAbi<'a, Ty> { | ||
pub fn adjust_for_foreign_abi<C>( | ||
&mut self, | ||
cx: &C, | ||
abi: spec::abi::Abi, | ||
abi: ExternAbi, | ||
) -> Result<(), AdjustForForeignAbiError> | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt, | ||
{ | ||
if abi == spec::abi::Abi::X86Interrupt { | ||
if abi == ExternAbi::X86Interrupt { | ||
if let Some(arg) = self.args.first_mut() { | ||
arg.pass_by_stack_offset(None); | ||
} | ||
|
@@ -651,12 +650,10 @@ impl<'a, Ty> FnAbi<'a, Ty> { | |
match &spec.arch[..] { | ||
"x86" => { | ||
let (flavor, regparm) = match abi { | ||
spec::abi::Abi::Fastcall { .. } | spec::abi::Abi::Vectorcall { .. } => { | ||
ExternAbi::Fastcall { .. } | ExternAbi::Vectorcall { .. } => { | ||
(x86::Flavor::FastcallOrVectorcall, None) | ||
} | ||
spec::abi::Abi::C { .. } | ||
| spec::abi::Abi::Cdecl { .. } | ||
| spec::abi::Abi::Stdcall { .. } => { | ||
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } | ExternAbi::Stdcall { .. } => { | ||
(x86::Flavor::General, cx.x86_abi_opt().regparm) | ||
} | ||
_ => (x86::Flavor::General, None), | ||
|
@@ -666,8 +663,10 @@ impl<'a, Ty> FnAbi<'a, Ty> { | |
x86::compute_abi_info(cx, self, opts); | ||
} | ||
"x86_64" => match abi { | ||
spec::abi::Abi::SysV64 { .. } => x86_64::compute_abi_info(cx, self), | ||
spec::abi::Abi::Win64 { .. } => x86_win64::compute_abi_info(cx, self), | ||
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self), | ||
ExternAbi::Win64 { .. } | ExternAbi::Vectorcall { .. } => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the one actual change in this file: we treat |
||
x86_win64::compute_abi_info(cx, self) | ||
} | ||
_ => { | ||
if cx.target_spec().is_like_windows { | ||
x86_win64::compute_abi_info(cx, self) | ||
|
@@ -701,7 +700,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { | |
"sparc" => sparc::compute_abi_info(cx, self), | ||
"sparc64" => sparc64::compute_abi_info(cx, self), | ||
"nvptx64" => { | ||
if cx.target_spec().adjust_abi(abi, self.c_variadic) == spec::abi::Abi::PtxKernel { | ||
if cx.target_spec().adjust_abi(abi, self.c_variadic) == ExternAbi::PtxKernel { | ||
nvptx64::compute_ptx_kernel_abi_info(cx, self) | ||
} else { | ||
nvptx64::compute_abi_info(self) | ||
|
@@ -730,7 +729,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { | |
Ok(()) | ||
} | ||
|
||
pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: SpecAbi) | ||
pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: ExternAbi) | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout + HasTargetSpec, | ||
|
@@ -821,7 +820,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { | |
// that's how we connect up to LLVM and it's unstable | ||
// anyway, we control all calls to it in libstd. | ||
BackendRepr::Vector { .. } | ||
if abi != SpecAbi::RustIntrinsic && spec.simd_types_indirect => | ||
if abi != ExternAbi::RustIntrinsic && spec.simd_types_indirect => | ||
{ | ||
arg.make_indirect(); | ||
continue; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//@ compile-flags: -Z merge-functions=disabled | ||
|
||
//@ revisions: windows-gnu | ||
//@[windows-gnu] compile-flags: --target x86_64-pc-windows-gnu | ||
//@[windows-gnu] needs-llvm-components: x86 | ||
|
||
//@ revisions: windows-msvc | ||
//@[windows-msvc] compile-flags: --target x86_64-pc-windows-msvc | ||
//@[windows-msvc] needs-llvm-components: x86 | ||
|
||
// Also test what happens when using a Windows ABI on Linux. | ||
//@ revisions: linux | ||
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu | ||
//@[linux] needs-llvm-components: x86 | ||
|
||
#![feature(no_core, lang_items, rustc_attrs, abi_vectorcall)] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
// Make sure the argument is always passed when explicitly requesting a Windows ABI. | ||
// Our goal here is to match clang: <https://clang.godbolt.org/z/Wr4jMWq3P>. | ||
|
||
// CHECK: define win64cc void @pass_zst_win64(ptr {{[^,]*}}) | ||
#[no_mangle] | ||
extern "win64" fn pass_zst_win64(_: ()) {} | ||
RalfJung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK: define x86_vectorcallcc void @pass_zst_vectorcall(ptr {{[^,]*}}) | ||
#[no_mangle] | ||
extern "vectorcall" fn pass_zst_vectorcall(_: ()) {} | ||
|
||
// windows-gnu: define void @pass_zst_fastcall(ptr {{[^,]*}}) | ||
// windows-msvc: define void @pass_zst_fastcall(ptr {{[^,]*}}) | ||
#[no_mangle] | ||
#[cfg(windows)] // "fastcall" is not valid on 64bit Linux | ||
extern "fastcall" fn pass_zst_fastcall(_: ()) {} | ||
|
||
// The sysv64 ABI ignores ZST. | ||
|
||
// CHECK: define x86_64_sysvcc void @pass_zst_sysv64() | ||
#[no_mangle] | ||
extern "sysv64" fn pass_zst_sysv64(_: ()) {} | ||
|
||
// For `extern "C"` functions, ZST are ignored on Linux put passed on Windows. | ||
|
||
// linux: define void @pass_zst_c() | ||
// windows-msvc: define void @pass_zst_c(ptr {{[^,]*}}) | ||
// windows-gnu: define void @pass_zst_c(ptr {{[^,]*}}) | ||
#[no_mangle] | ||
extern "C" fn pass_zst_c(_: ()) {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.