Skip to content

Commit a2f499f

Browse files
committed
Fix tests
1 parent b4f83c6 commit a2f499f

File tree

11 files changed

+59
-56
lines changed

11 files changed

+59
-56
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

locales/en-US.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ codegen_gcc_invalid_monomorphization_unsupported_cast =
6060
6161
codegen_gcc_invalid_monomorphization_unsupported_operation =
6262
invalid monomorphization of `{$name}` intrinsic: unsupported operation on `{$in_ty}` with element `{$in_elem}`
63+
64+
codegen_gcc_invalid_minimum_alignment =
65+
invalid minimum global alignment: {$err}

patches/0022-core-Disable-not-compiling-tests.patch

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ new file mode 100644
1818
index 0000000..46fd999
1919
--- /dev/null
2020
+++ b/library/core/tests/Cargo.toml
21-
@@ -0,0 +1,8 @@
21+
@@ -0,0 +1,12 @@
2222
+[package]
2323
+name = "core"
2424
+version = "0.0.0"
@@ -27,37 +27,18 @@ index 0000000..46fd999
2727
+[lib]
2828
+name = "coretests"
2929
+path = "lib.rs"
30-
diff --git a/library/core/tests/num/flt2dec/mod.rs b/library/core/tests/num/flt2dec/mod.rs
31-
index a35897e..f0bf645 100644
32-
--- a/library/core/tests/num/flt2dec/mod.rs
33-
+++ b/library/core/tests/num/flt2dec/mod.rs
34-
@@ -13,7 +13,6 @@ mod strategy {
35-
mod dragon;
36-
mod grisu;
37-
}
38-
-mod random;
39-
40-
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
41-
match decode(v).1 {
42-
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
43-
index 6609bc3..241b497 100644
44-
--- a/library/core/tests/slice.rs
45-
+++ b/library/core/tests/slice.rs
46-
@@ -1209,6 +1209,7 @@ fn brute_force_rotate_test_1() {
47-
}
48-
}
49-
50-
+/*
51-
#[test]
52-
#[cfg(not(target_arch = "wasm32"))]
53-
fn sort_unstable() {
54-
@@ -1394,6 +1395,7 @@ fn partition_at_index() {
55-
v.select_nth_unstable(0);
56-
assert!(v == [0xDEADBEEF]);
57-
}
58-
+*/
59-
60-
#[test]
61-
#[should_panic(expected = "index 0 greater than length of slice")]
30+
+
31+
+[dependencies]
32+
+rand = { version = "0.8.5", default-features = false }
33+
+rand_xorshift = { version = "0.3.0", default-features = false }
34+
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
35+
index 42a26ae..5ac1042 100644
36+
--- a/library/core/tests/lib.rs
37+
+++ b/library/core/tests/lib.rs
38+
@@ -1,3 +1,4 @@
39+
+#![cfg(test)]
40+
#![feature(alloc_layout_extra)]
41+
#![feature(array_chunks)]
42+
#![feature(array_methods)]
6243
--
6344
2.21.0 (Apple Git-122)

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-02-28"
2+
channel = "nightly-2023-03-02"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/builder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12281228

12291229
#[cfg(feature="master")]
12301230
fn resume(&mut self, exn0: RValue<'gcc>, _exn1: RValue<'gcc>) {
1231-
// TODO(antoyo): check if this is normal that we need to dereference the value.
1232-
// NOTE: the type is wrong, so in order to get a pointer for parameter, cast it to a
1233-
// pointer of pointer that is later dereferenced.
1234-
let exn_type = exn0.get_type().make_pointer();
1231+
let exn_type = exn0.get_type();
12351232
let exn = self.context.new_cast(None, exn0, exn_type);
1236-
let exn = exn.dereference(None).to_rvalue();
12371233
let unwind_resume = self.context.get_target_builtin_function("__builtin_unwind_resume");
12381234
self.llbb().add_eval(None, self.context.new_call(None, unwind_resume, &[exn]));
12391235
self.unreachable();

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
3636
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
3737
let context = &cx.context;
3838
let byte_type = context.new_type::<u8>();
39-
let typ = context.new_array_type(None, byte_type, bytes.len() as i32);
39+
let typ = context.new_array_type(None, byte_type, bytes.len() as u64);
4040
let elements: Vec<_> =
4141
bytes.iter()
4242
.map(|&byte| context.new_rvalue_from_int(byte_type, byte as i32))

src/consts.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRan
1313

1414
use crate::base;
1515
use crate::context::CodegenCx;
16+
use crate::errors::InvalidMinimumAlignment;
1617
use crate::type_of::LayoutGccExt;
1718

1819
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -30,6 +31,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
3031
}
3132
}
3233

34+
fn set_global_alignment<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, gv: LValue<'gcc>, mut align: Align) {
35+
// The target may require greater alignment for globals than the type does.
36+
// Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
37+
// which can force it to be smaller. Rust doesn't support this yet.
38+
if let Some(min) = cx.sess().target.min_global_align {
39+
match Align::from_bits(min) {
40+
Ok(min) => align = align.max(min),
41+
Err(err) => {
42+
cx.sess().emit_err(InvalidMinimumAlignment { err });
43+
}
44+
}
45+
}
46+
gv.set_alignment(align.bytes() as i32);
47+
}
48+
3349
impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
3450
fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
3551
// TODO(antoyo): implement a proper rvalue comparison in libgccjit instead of doing the
@@ -81,7 +97,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
8197
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
8298
let gcc_type = self.layout_of(ty).gcc_type(self);
8399

84-
// TODO(antoyo): set alignment.
100+
set_global_alignment(self, global, self.align_of(ty));
85101

86102
let value = self.bitcast_if_needed(value, gcc_type);
87103
global.global_set_initializer_rvalue(value);

src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,9 @@ pub(crate) struct UnwindingInlineAsm {
221221
#[primary_span]
222222
pub span: Span,
223223
}
224+
225+
#[derive(Diagnostic)]
226+
#[diag(codegen_gcc_invalid_minimum_alignment)]
227+
pub(crate) struct InvalidMinimumAlignment {
228+
pub err: String,
229+
}

src/type_.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::convert::TryInto;
2-
31
use gccjit::{RValue, Struct, Type};
42
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
53
use rustc_codegen_ssa::common::TypeKind;
@@ -202,23 +200,17 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
202200
value.get_type()
203201
}
204202

205-
fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
206-
if let Some(struct_type) = ty.is_struct() {
203+
fn type_array(&self, ty: Type<'gcc>, len: u64) -> Type<'gcc> {
204+
// TODO: remove this as well?
205+
/*if let Some(struct_type) = ty.is_struct() {
207206
if struct_type.get_field_count() == 0 {
208207
// NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
209208
// size of usize::MAX in test_binary_search, we workaround this by setting the size to
210209
// zero for ZSTs.
211210
// FIXME(antoyo): fix gccjit API.
212211
len = 0;
213212
}
214-
}
215-
216-
// NOTE: see note above. Some other test uses usize::MAX.
217-
if len == u64::MAX {
218-
len = 0;
219-
}
220-
221-
let len: i32 = len.try_into().expect("array len");
213+
}*/
222214

223215
self.context.new_array_type(None, ty, len)
224216
}

src/type_of.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::bug;
66
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
77
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
88
use rustc_middle::ty::print::with_no_trimmed_paths;
9-
use rustc_target::abi::{self, Abi, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants};
9+
use rustc_target::abi::{self, Abi, Align, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants};
1010
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
1111

1212
use crate::abi::{FnAbiGccExt, GccType};
@@ -50,6 +50,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
5050
}
5151
}
5252

53+
impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
54+
pub fn align_of(&self, ty: Ty<'tcx>) -> Align {
55+
self.layout_of(ty).align.abi
56+
}
57+
}
58+
5359
fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout<'tcx>, defer: &mut Option<(Struct<'gcc>, TyAndLayout<'tcx>)>) -> Type<'gcc> {
5460
match layout.abi {
5561
Abi::Scalar(_) => bug!("handled elsewhere"),

0 commit comments

Comments
 (0)