Skip to content

Commit 24788ba

Browse files
committed
Fix tests
1 parent 765274b commit 24788ba

File tree

13 files changed

+88
-28
lines changed

13 files changed

+88
-28
lines changed

src/asm.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,8 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
537537
}
538538
if dest.is_none() && options.contains(InlineAsmOptions::NORETURN) {
539539
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
540-
let builtin_unreachable: RValue<'gcc> = unsafe {
541-
std::mem::transmute(builtin_unreachable)
542-
};
540+
let builtin_unreachable: RValue<'gcc> =
541+
unsafe { std::mem::transmute(builtin_unreachable) };
543542
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
544543
}
545544

src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10041004
}
10051005
}
10061006

1007-
let val = if let Some(_) = place.val.llextra {
1007+
let val = if place.val.llextra.is_some() {
10081008
// FIXME: Merge with the `else` below?
10091009
OperandValue::Ref(place.val)
10101010
} else if place.layout.is_gcc_immediate() {
@@ -1672,7 +1672,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16721672
_instance: Option<Instance<'tcx>>,
16731673
) -> RValue<'gcc> {
16741674
// FIXME(antoyo): remove when having a proper API.
1675-
let gcc_func = unsafe { std::mem::transmute(func) };
1675+
let gcc_func = unsafe { std::mem::transmute::<RValue<'gcc>, Function<'gcc>>(func) };
16761676
let call = if self.functions.borrow().values().any(|value| *value == gcc_func) {
16771677
self.function_call(func, args, funclet)
16781678
} else {

src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
501501
"rust_eh_personality"
502502
};
503503
let func = self.declare_func(name, self.type_i32(), &[], true);
504-
unsafe { std::mem::transmute(func) }
504+
unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) }
505505
}
506506
};
507507
// TODO(antoyo): apply target cpu attributes.

src/int.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
8383
} else {
8484
let a_size = a_type.get_size();
8585
let b_size = b_type.get_size();
86-
if a_size > b_size {
87-
let b = self.context.new_cast(self.location, b, a_type);
88-
a >> b
89-
} else if a_size < b_size {
90-
let a = self.context.new_cast(self.location, a, b_type);
91-
a >> b
92-
} else {
93-
a >> b
86+
match a_size.cmp(&b_size) {
87+
std::cmp::Ordering::Less => {
88+
let a = self.context.new_cast(self.location, a, b_type);
89+
a >> b
90+
}
91+
std::cmp::Ordering::Equal => a >> b,
92+
std::cmp::Ordering::Greater => {
93+
let b = self.context.new_cast(self.location, b, a_type);
94+
a >> b
95+
}
9496
}
9597
}
9698
} else if a_type.is_vector() && a_type.is_vector() {
@@ -648,14 +650,16 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
648650
} else {
649651
let a_size = a_type.get_size();
650652
let b_size = b_type.get_size();
651-
if a_size > b_size {
652-
let b = self.context.new_cast(self.location, b, a_type);
653-
a << b
654-
} else if a_size < b_size {
655-
let a = self.context.new_cast(self.location, a, b_type);
656-
a << b
657-
} else {
658-
a << b
653+
match a_size.cmp(&b_size) {
654+
std::cmp::Ordering::Less => {
655+
let a = self.context.new_cast(self.location, a, b_type);
656+
a << b
657+
}
658+
std::cmp::Ordering::Equal => a << b,
659+
std::cmp::Ordering::Greater => {
660+
let b = self.context.new_cast(self.location, b, a_type);
661+
a << b
662+
}
659663
}
660664
}
661665
} else if a_type.is_vector() && a_type.is_vector() {

src/intrinsic/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
130130
let llval = match name {
131131
_ if simple.is_some() => {
132132
// FIXME(antoyo): remove this cast when the API supports function.
133-
let func = unsafe { std::mem::transmute(simple.expect("simple")) };
133+
let func = unsafe {
134+
std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(simple.expect("simple"))
135+
};
134136
self.call(
135137
self.type_void(),
136138
None,
@@ -675,7 +677,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
675677
let step3 = self.or(left, right);
676678

677679
// Fourth step.
678-
if width == 8 { step3 } else { self.gcc_bswap(step3, width) }
680+
if width == 8 {
681+
step3
682+
} else {
683+
self.gcc_bswap(step3, width)
684+
}
679685
}
680686
128 => {
681687
// TODO(antoyo): find a more efficient implementation?
@@ -1194,7 +1200,7 @@ fn codegen_gnu_try<'gcc>(
11941200
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None);
11951201
});
11961202

1197-
let func = unsafe { std::mem::transmute(func) };
1203+
let func = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) };
11981204

11991205
// Note that no invoke is used here because by definition this function
12001206
// can't panic (that's what it's catching).
@@ -1268,7 +1274,7 @@ fn gen_fn<'a, 'gcc, 'tcx>(
12681274
// FIXME(eddyb) find a nicer way to do this.
12691275
cx.linkage.set(FunctionType::Internal);
12701276
let func = cx.declare_fn(name, fn_abi);
1271-
let func_val = unsafe { std::mem::transmute(func) };
1277+
let func_val = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) };
12721278
cx.set_frame_pointer_type(func_val);
12731279
cx.apply_target_cpu_attr(func_val);
12741280
let block = Builder::append_block(cx, func_val, "entry-block");

src/intrinsic/simd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_codegen_ssa::errors::InvalidMonomorphization;
1313
use rustc_codegen_ssa::mir::operand::OperandRef;
1414
use rustc_codegen_ssa::mir::place::PlaceRef;
1515
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
16+
#[cfg(feature = "master")]
1617
use rustc_hir as hir;
1718
use rustc_middle::mir::BinOp;
1819
use rustc_middle::span_bug;

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,10 @@ impl WriteBackendMethods for GccCodegenBackend {
413413
back::write::codegen(cgcx, dcx, module, config)
414414
}
415415

416-
fn prepare_thin(_module: ModuleCodegen<Self::Module>, _emit_summary: bool) -> (String, Self::ThinBuffer) {
416+
fn prepare_thin(
417+
_module: ModuleCodegen<Self::Module>,
418+
_emit_summary: bool,
419+
) -> (String, Self::ThinBuffer) {
417420
unimplemented!();
418421
}
419422

src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
8181
// TODO(antoyo): use inline attribute from there in linkage.set() above.
8282

8383
self.functions.borrow_mut().insert(symbol_name.to_string(), decl);
84-
self.function_instances.borrow_mut().insert(instance, unsafe { std::mem::transmute(decl) });
84+
self.function_instances.borrow_mut().insert(instance, decl);
8585
}
8686
}

tests/run/array.rs

+11
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ impl Sub for i16 {
205205
}
206206
}
207207

208+
#[track_caller]
209+
#[lang = "panic_const_add_overflow"]
210+
pub fn panic_const_add_overflow() -> ! {
211+
panic("attempt to add with overflow");
212+
}
213+
214+
#[track_caller]
215+
#[lang = "panic_const_sub_overflow"]
216+
pub fn panic_const_sub_overflow() -> ! {
217+
panic("attempt to subtract with overflow");
218+
}
208219

209220
/*
210221
* Code

tests/run/assign.rs

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ impl Add for isize {
120120
}
121121
}
122122

123+
#[track_caller]
124+
#[lang = "panic_const_add_overflow"]
125+
pub fn panic_const_add_overflow() -> ! {
126+
panic("attempt to add with overflow");
127+
}
128+
123129
/*
124130
* Code
125131
*/

tests/run/closure.rs

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ pub fn panic(_msg: &'static str) -> ! {
189189
}
190190
}
191191

192+
#[track_caller]
193+
#[lang = "panic_const_add_overflow"]
194+
pub fn panic_const_add_overflow() -> ! {
195+
panic("attempt to add with overflow");
196+
}
197+
192198
/*
193199
* Code
194200
*/

tests/run/mut_ref.rs

+6
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ impl Add for isize {
122122
}
123123
}
124124

125+
#[track_caller]
126+
#[lang = "panic_const_add_overflow"]
127+
pub fn panic_const_add_overflow() -> ! {
128+
panic("attempt to add with overflow");
129+
}
130+
125131
/*
126132
* Code
127133
*/

tests/run/operations.rs

+18
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ impl Mul for isize {
207207
}
208208
}
209209

210+
#[track_caller]
211+
#[lang = "panic_const_add_overflow"]
212+
pub fn panic_const_add_overflow() -> ! {
213+
panic("attempt to add with overflow");
214+
}
215+
216+
#[track_caller]
217+
#[lang = "panic_const_sub_overflow"]
218+
pub fn panic_const_sub_overflow() -> ! {
219+
panic("attempt to subtract with overflow");
220+
}
221+
222+
#[track_caller]
223+
#[lang = "panic_const_mul_overflow"]
224+
pub fn panic_const_mul_overflow() -> ! {
225+
panic("attempt to multiply with overflow");
226+
}
227+
210228
/*
211229
* Code
212230
*/

0 commit comments

Comments
 (0)