-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Aarch64 call abi does not zeroext (and one cannot assume it does so) #97800
Merged
bors
merged 10 commits into
rust-lang:master
from
pnkfelix:issue-97463-fix-aarch64-call-abi-does-not-zeroext
Sep 16, 2022
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7913b85
unit tests that inspect LLVM output directly. This relies on a human …
pnkfelix b2777ab
End-to-end regression test for 97463.
pnkfelix 8ae5a55
fix issue 97463 using change suggested by nbdd0121.
pnkfelix dfdb017
experiment: trying to encode the end-to-end test as a ui test via rus…
pnkfelix 99c0f91
fix typo, thanks wesley
pnkfelix 9bf3d5a
Ignore test on wasm
wesleywiser 59cc718
Update codegen tests to accommodate the potential presence/absence of…
pnkfelix ed9b12d
rustdoc doesn't like bare urls
wesleywiser d73614a
Do not run run-make test tied to unix-style `$(CC)` on MSVC host.
pnkfelix a2de75a
fix typo in comment noted by bjorn3.
pnkfelix 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
End-to-end regression test for 97463.
incorporated review feedback, with comment explaining why this is calling CC instead of COMPILE_OBJ or NATIVE_STATICLIB. As drive-by, removed some other unnecessary commands from the recipe.
- Loading branch information
commit b2777aba757dd92042932d79309132bd953e130d
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/test/run-make-fulldeps/issue-97463-abi-param-passing/Makefile
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,12 @@ | ||
-include ../tools.mk | ||
|
||
# The issue exercised by this test, rust-lang/rust#97463, explicitly needs `-O` | ||
# flags (like `-O3`) to reproduce. Thus, we call $(CC) instead of nicer | ||
# alternatives provided by tools.mk like using `COMPILE_OBJ` or using a | ||
# `NATIVE_STATICLIB` dependency. | ||
|
||
all: | ||
$(CC) -c -O3 -o $(TMPDIR)/bad.o bad.c | ||
$(AR) rcs $(TMPDIR)/libbad.a $(TMPDIR)/bad.o | ||
$(RUSTC) param_passing.rs -L$(TMPDIR) -lbad -C opt-level=3 | ||
$(call RUN,param_passing) |
24 changes: 24 additions & 0 deletions
24
src/test/run-make-fulldeps/issue-97463-abi-param-passing/bad.c
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,24 @@ | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
|
||
struct bloc { | ||
uint16_t a; | ||
uint16_t b; | ||
uint16_t c; | ||
}; | ||
|
||
uint16_t c_read_value(uint32_t a, uint32_t b, uint32_t c) { | ||
struct bloc *data = malloc(sizeof(struct bloc)); | ||
|
||
data->a = a & 0xFFFF; | ||
data->b = b & 0xFFFF; | ||
data->c = c & 0xFFFF; | ||
|
||
printf("C struct: a = %u, b = %u, c = %u\n", | ||
(unsigned) data->a, (unsigned) data->b, (unsigned) data->c); | ||
printf("C function returns %u\n", (unsigned) data->b); | ||
|
||
return data->b; /* leak data */ | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/run-make-fulldeps/issue-97463-abi-param-passing/param_passing.rs
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,38 @@ | ||
// NOTE: Exposing the bug encoded in this test is sensitive to | ||
// LLVM optimization choices. See additional note below for an | ||
// example. | ||
|
||
#[link(name = "bad")] | ||
extern "C" { | ||
pub fn c_read_value(a: u32, b: u32, c: u32) -> u16; | ||
} | ||
|
||
fn main() { | ||
const C1: usize = 0x327b23c6; | ||
const C2: usize = C1 & 0xFFFF; | ||
|
||
let r1: usize = 0x0; | ||
let r2: usize = C1; | ||
let r3: usize = 0x0; | ||
let value: u16 = unsafe { c_read_value(r1 as u32, r2 as u32, r3 as u32) }; | ||
|
||
// NOTE: as an example of the sensitivity of this test to optimization choices, | ||
// uncommenting this block of code makes the bug go away on pnkfeix's machine. | ||
pnkfelix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// (But observing via `dbg!` doesn't hide the bug. At least sometimes.) | ||
/* | ||
println!("{}", value); | ||
println!("{}", value as usize); | ||
println!("{}", usize::from(value)); | ||
println!("{}", (value as usize) & 0xFFFF); | ||
*/ | ||
|
||
let d1 = value; | ||
let d2 = value as usize; | ||
let d3 = usize::from(value); | ||
let d4 = (value as usize) & 0xFFFF; | ||
|
||
let d = (&d1, &d2, &d3, &d4); | ||
let d_ = (d1, d2, d3, d4); | ||
|
||
assert_eq!(((&(C2 as u16), &C2, &C2, &C2), (C2 as u16, C2, C2, C2)), (d, d_)); | ||
} |
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.
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.
We have a test setup for ABI tests with
auxiliary/rust_test_helpers.c
andui/abi
. Can that mechanism be used instead?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.
let me go inspect that.
(whatever it is, it will need to use
-O
to replicate the problems here...)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.
auxiliary/rust_test_helpers.c
doesn't currently include<stdlib.h>
, which is "needed" here if we want to reproduce the original test faithfully, in that it callsmalloc
. (And given how sensitive reproducing the failure is to small changes, I'm inclined to assume thatmalloc
is a necessity.)@nagisa do you know offhand if we are deliberately trying to avoid introducing a dependence from
rust_test_helpers.c
uponstdlib.h
and/ormalloc
itself, perhaps to ensure we can compile the file on esoteric targets that do not have that available? Just curious.I'll keep moving forward with trying to move this test into
auxiliary/rust_test_helpers.c
, under the assumption that we can add such a dependence. But given the amount of work I put into getting the codegen tests working, I'm sort of inclined to just live with a run-make test here, if I encounter any hurdles on the way...