Skip to content

Commit 91571ce

Browse files
avanhattadpaco-aws
authored andcommitted
Codegen the rest of std lib and add a regression script
Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
1 parent 73b9fbc commit 91571ce

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

compiler/rustc_codegen_llvm/src/gotoc/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ impl<'tcx> GotocCtx<'tcx> {
102102
// https://github.com/model-checking/rmc/issues/202
103103
"fmt::ArgumentV1::<'a>::as_usize" => true,
104104
// https://github.com/model-checking/rmc/issues/204
105-
x if x.ends_with("__getit") => true,
105+
name if name.ends_with("__getit") => true,
106106
// https://github.com/model-checking/rmc/issues/205
107107
"panic::Location::<'a>::caller" => true,
108108
// https://github.com/model-checking/rmc/issues/207
109109
"core::slice::<impl [T]>::split_first" => true,
110+
// https://github.com/model-checking/rmc/issues/281
111+
name if name.starts_with("bridge::client") => true,
112+
// https://github.com/model-checking/rmc/issues/282
113+
"bridge::closure::Closure::<'a, A, R>::call" => true,
110114
_ => false,
111115
}
112116
}

compiler/rustc_codegen_llvm/src/gotoc/typ.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ impl<'tcx> GotocCtx<'tcx> {
10341034

10351035
/// Check if the mir type already is a vtable fat pointer.
10361036
pub fn is_vtable_fat_pointer(&self, mir_type: Ty<'tcx>) -> bool {
1037-
pointee_type(mir_type).map_or(false, |p| self.use_vtable_fat_pointer(p))
1037+
self.is_ref_of_unsized(mir_type)
1038+
&& self.use_vtable_fat_pointer(pointee_type(mir_type).unwrap())
10381039
}
10391040
}

scripts/rmc-regression.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ check-cbmc-viewer-version.py --major 2 --minor 5
2222
# Standalone rmc tests, expected tests, and cargo tests
2323
./x.py build -i --stage 1 library/std ${EXTRA_X_PY_BUILD_ARGS}
2424
./x.py test -i --stage 1 cbmc firecracker prusti smack expected cargo-rmc
25+
26+
# Check codegen for the standard library
27+
$SCRIPT_DIR/std-lib-regression.sh

scripts/std-lib-regression.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
5+
# Test for platform
6+
platform=`uname -sp`
7+
if [[ $platform != "Linux x86_64" ]]; then
8+
echo "Codegen script only works on Linux x86 platform"
9+
exit 0
10+
fi
11+
12+
# Get RMC root
13+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
14+
RMC_DIR=$SCRIPT_DIR/..
15+
16+
# Log output
17+
STD_LIB_LOG="/tmp/SizeAndAlignOfDstTest/log.txt"
18+
19+
# Use a unit test that requires mutex and cell
20+
echo "Starting RMC codegen for the Rust standard library"
21+
cd /tmp
22+
if [ -d SizeAndAlignOfDstTest ]; then rm -rf SizeAndAlignOfDstTest; fi
23+
cargo new SizeAndAlignOfDstTest
24+
cd SizeAndAlignOfDstTest
25+
cp $RMC_DIR/src/test/cbmc/SizeAndAlignOfDst/main_fail.rs src/main.rs
26+
rustup component add rust-src --toolchain nightly > /dev/null 2>&1
27+
RUSTFLAGS="-Z trim-diagnostic-paths=no -Z codegen-backend=gotoc --cfg=rmc" RUSTC=rmc-rustc cargo +nightly build -Z build-std --target x86_64-unknown-linux-gnu 2> $STD_LIB_LOG
28+
29+
# For now, we expect a linker error, but no modules should fail with a compiler
30+
# panic.
31+
#
32+
# With https://github.com/model-checking/rmc/issues/109, this check can be
33+
# removed to just allow the success of the previous line to determine the
34+
# success of this script (with no $STD_LIB_LOG needed)
35+
RESULT=$?
36+
if grep -q "error: internal compiler error: unexpected panic" $STD_LIB_LOG; then
37+
echo "Panic on building standard library"
38+
cat $STD_LIB_LOG
39+
exit 1
40+
else
41+
echo "Successful RMC codegen for the Rust standard library"
42+
fi

0 commit comments

Comments
 (0)