Skip to content

Commit 524b2e2

Browse files
authored
Fix bug in validate_cast_and_convert_metadata (#376)
Previously, `validate_cast_and_convert_metadata` incorrectly assumed that, for slice DSTs, the trailing slice element would always have an alignment at least as large as the outer type's alignment, and so there would never be any padding added after the trailing slice. In this commit, we rewrite `validate_cast_and_convert_metadata` to no longer assume this behavior. While we're here, we add the `test_validate_rust_layout` test, which validates many of our assumptions about Rust's type layout against the standard library to help catch mismatches like this in the future.
1 parent e70c25f commit 524b2e2

7 files changed

Lines changed: 960 additions & 204 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ jobs:
150150
if: contains(matrix.target, 'i686')
151151

152152
- name: Run tests
153-
run: ./cargo.sh +${{ matrix.toolchain }} test --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose
153+
run: |
154+
./cargo.sh +${{ matrix.toolchain }} test \
155+
--package ${{ matrix.crate }} \
156+
--target ${{ matrix.target }} \
157+
${{ matrix.features }} \
158+
--verbose
154159
# Only run tests when targetting x86 (32- or 64-bit) - we're executing on
155160
# x86_64, so we can't run tests for any non-x86 target.
156161
#
@@ -163,14 +168,24 @@ jobs:
163168
# Run under both the stacked borrows model (default) and under the tree
164169
# borrows model to ensure we're compliant with both.
165170
for EXTRA_FLAGS in "" "-Zmiri-tree-borrows"; do
166-
# Skip the `ui` test since it invokes the compiler, which we can't do from
167-
# Miri (and wouldn't want to do anyway).
171+
# On `--skip ui`: Skip the `ui` test since it invokes the compiler,
172+
# which we can't do from Miri (and wouldn't want to do anyway).
173+
#
174+
# On `matrix.features == '--all-features': We mark tests which are
175+
# particularly expensive to run under Miri as
176+
# `#[cfg_attr(miri, ignore)]`. We want to run them once per
177+
# toolchain/target combination, but not once per feature set so we
178+
# keep the expensive computation to a minimum.
179+
#
180+
# TODO(#391): Optimize these tests.
168181
MIRIFLAGS="$MIRIFLAGS $EXTRA_FLAGS" ./cargo.sh +${{ matrix.toolchain }} \
169182
miri test \
170183
--package ${{ matrix.crate }} \
171184
--target ${{ matrix.target }} \
172185
${{ matrix.features }} \
173-
-- --skip ui
186+
-- --skip ui \
187+
${{ matrix.features == '--all-features' && '--ignored' || '' }}
188+
174189
done
175190
# Only nightly has a working Miri, so we skip installing on all other
176191
# toolchains.

cargo.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function lookup-version {
5555
esac
5656
}
5757

58+
function get-rustflags {
59+
[ "$1" == nightly ] && echo "--cfg __INTERNAL_USE_ONLY_NIGHLTY_FEATURES_IN_TESTS"
60+
}
61+
5862
case "$1" in
5963
# cargo.sh --version <toolchain-name>
6064
--version)
@@ -67,14 +71,14 @@ case "$1" in
6771
for toolchain in msrv stable nightly; do
6872
echo "[cargo.sh] running with toolchain: $toolchain" >&2
6973
TOOLCHAIN="$(lookup-version $toolchain)"
70-
cargo "+$TOOLCHAIN" ${@:2}
74+
RUSTFLAGS="$(get-rustflags $toolchain)" cargo "+$TOOLCHAIN" ${@:2}
7175
done
7276
exit 0
7377
;;
7478
# cargo.sh +<toolchain-name> [...]
7579
+*)
7680
TOOLCHAIN="$(lookup-version ${1:1})"
77-
cargo "+$TOOLCHAIN" ${@:2}
81+
RUSTFLAGS="$(get-rustflags ${1:1})" cargo "+$TOOLCHAIN" ${@:2}
7882
;;
7983
*)
8084
print-usage-and-exit

0 commit comments

Comments
 (0)