-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
c-variadic: fix for sparc64 #155660
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
+136
−2
Merged
c-variadic: fix for sparc64 #155660
Changes from all commits
Commits
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
File renamed without changes.
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,112 @@ | ||
| //@ add-minicore | ||
| //@ assembly-output: emit-asm | ||
| // | ||
| //@ revisions: SPARC SPARC64 | ||
| //@ [SPARC] compile-flags: -Copt-level=3 --target sparc-unknown-linux-gnu | ||
| //@ [SPARC] needs-llvm-components: sparc | ||
| //@ [SPARC64] compile-flags: -Copt-level=3 --target sparc64-unknown-linux-gnu | ||
| //@ [SPARC64] needs-llvm-components: sparc | ||
| #![feature(c_variadic, no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)] | ||
| #![no_core] | ||
| #![crate_type = "lib"] | ||
|
|
||
| // Check that the assembly that rustc generates matches what clang emits. | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[lang = "va_arg_safe"] | ||
| pub unsafe trait VaArgSafe {} | ||
|
|
||
| unsafe impl VaArgSafe for i32 {} | ||
| unsafe impl VaArgSafe for i64 {} | ||
| unsafe impl VaArgSafe for f64 {} | ||
| unsafe impl<T> VaArgSafe for *const T {} | ||
|
|
||
| #[repr(transparent)] | ||
| struct VaListInner { | ||
| ptr: *const c_void, | ||
| } | ||
|
|
||
| #[repr(transparent)] | ||
| #[lang = "va_list"] | ||
| pub struct VaList<'a> { | ||
| inner: VaListInner, | ||
| _marker: PhantomData<&'a mut ()>, | ||
| } | ||
|
|
||
| #[rustc_intrinsic] | ||
| #[rustc_nounwind] | ||
| pub const unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| unsafe extern "C" fn read_f64(ap: &mut VaList<'_>) -> f64 { | ||
| // CHECK-LABEL: read_f64 | ||
| // | ||
| // SPARC: ld [%o0], %o1 | ||
| // SPARC-NEXT: add %o1, 8, %o2 | ||
| // SPARC-NEXT: st %o2, [%o0] | ||
| // SPARC-NEXT: ld [%o1+4], %o0 | ||
| // SPARC-NEXT: add %sp, 96, %o2 | ||
| // SPARC-NEXT: or %o2, 4, %o2 | ||
| // SPARC-NEXT: st %o0, [%o2] | ||
| // SPARC-NEXT: ld [%o1], %o0 | ||
| // SPARC-NEXT: st %o0, [%sp+96] | ||
| // SPARC-NEXT: ldd [%sp+96], %f0 | ||
| // SPARC-NEXT: retl | ||
| // SPARC-NEXT: add %sp, 104, %sp | ||
| // | ||
| // SPARC64: ldx [%o0], %o1 | ||
| // SPARC64-NEXT: add %o1, 8, %o2 | ||
| // SPARC64-NEXT: stx %o2, [%o0] | ||
| // SPARC64-NEXT: retl | ||
| // SPARC64-NEXT: ldd [%o1], %f0 | ||
| va_arg(ap) | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| unsafe extern "C" fn read_i32(ap: &mut VaList<'_>) -> i32 { | ||
| // CHECK-LABEL: read_i32 | ||
| // | ||
| // SPARC: ld [%o0], %o1 | ||
| // SPARC-NEXT: add %o1, 4, %o2 | ||
| // SPARC-NEXT: st %o2, [%o0] | ||
| // SPARC-NEXT: retl | ||
| // SPARC-NEXT: ld [%o1], %o0 | ||
| // | ||
| // SPARC64: ldx [%o0], %o1 | ||
| // SPARC64-NEXT: add %o1, 8, %o2 | ||
| // SPARC64-NEXT: stx %o2, [%o0] | ||
| // SPARC64-NEXT: retl | ||
| // SPARC64-NEXT: ldsw [%o1+4], %o0 | ||
| va_arg(ap) | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| unsafe extern "C" fn read_i64(ap: &mut VaList<'_>) -> i64 { | ||
| // CHECK-LABEL: read_i64 | ||
| // | ||
| // SPARC: ld [%o0], %o1 | ||
| // SPARC-NEXT: add %o1, 4, %o2 | ||
| // SPARC-NEXT: st %o2, [%o0] | ||
| // SPARC-NEXT: ld [%o1], %o2 | ||
| // SPARC-NEXT: add %o1, 8, %o3 | ||
| // SPARC-NEXT: st %o3, [%o0] | ||
| // SPARC-NEXT: ld [%o1+4], %o1 | ||
| // SPARC-NEXT: retl | ||
| // SPARC-NEXT: mov %o2, %o0 | ||
| // | ||
| // SPARC64: ldx [%o0], %o1 | ||
| // SPARC64-NEXT: add %o1, 8, %o2 | ||
| // SPARC64-NEXT: stx %o2, [%o0] | ||
| // SPARC64-NEXT: retl | ||
| // SPARC64-NEXT: ldx [%o1], %o0 | ||
| va_arg(ap) | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| unsafe extern "C" fn read_ptr(ap: &mut VaList<'_>) -> *const u8 { | ||
| // SPARC: read_ptr = read_i32 | ||
| // SPARC64: read_ptr = read_i64 | ||
| va_arg(ap) | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified this with https://godbolt.org/z/qrM37rY6n and we match it exactly.
Interestingly using LLVM IR directly will miscompile
va_arg.View changes since the review