Skip to content
Merged
8 changes: 2 additions & 6 deletions example/example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(no_core, unboxed_closures)]
#![no_core]
#![allow(dead_code)]
#![allow(dead_code, unnecessary_transmutes)]

extern crate mini_core;

Expand All @@ -11,11 +11,7 @@ fn abc(a: u8) -> u8 {
}

fn bcd(b: bool, a: u8) -> u8 {
if b {
a * 2
} else {
a * 3
}
if b { a * 2 } else { a * 3 }
}

fn call() {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2025-04-17"
channel = "nightly-2025-04-25"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
8 changes: 4 additions & 4 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
let mut input_registers = vec![];

for op in rust_operands {
if let InlineAsmOperandRef::In { reg, .. } = *op {
if let ConstraintOrRegister::Register(reg_name) = reg_to_gcc(reg) {
input_registers.push(reg_name);
}
if let InlineAsmOperandRef::In { reg, .. } = *op
&& let ConstraintOrRegister::Register(reg_name) = reg_to_gcc(reg)
{
input_registers.push(reg_name);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}

pub fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
if value.get_type() == self.bool_type.make_pointer() {
if let Some(pointee) = typ.get_pointee() {
if pointee.dyncast_vector().is_some() {
panic!()
}
}
if value.get_type() == self.bool_type.make_pointer()
&& let Some(pointee) = typ.get_pointee()
&& pointee.dyncast_vector().is_some()
{
panic!()
}
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
// SIMD builtins require a constant value.
Expand Down
8 changes: 4 additions & 4 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);

let global = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
if let Some(global) = self.get_declared_value(sym) {
if self.val_ty(global) != self.type_ptr_to(gcc_type) {
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
}
if let Some(global) = self.get_declared_value(sym)
&& self.val_ty(global) != self.type_ptr_to(gcc_type)
{
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
}

let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
Expand Down
17 changes: 9 additions & 8 deletions src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ fn make_mir_scope<'gcc, 'tcx>(
return;
};

if let Some(ref vars) = *variables {
if !vars.contains(scope) && scope_data.inlined.is_none() {
// Do not create a DIScope if there are no variables defined in this
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
debug_context.scopes[scope] = parent_scope;
instantiated.insert(scope);
return;
}
if let Some(ref vars) = *variables
&& !vars.contains(scope)
&& scope_data.inlined.is_none()
{
// Do not create a DIScope if there are no variables defined in this
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
debug_context.scopes[scope] = parent_scope;
instantiated.insert(scope);
return;
}

let loc = cx.lookup_debug_loc(scope_data.span.lo());
Expand Down
14 changes: 6 additions & 8 deletions src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
});
features.extend(feats);

if diagnostics {
if let Some(f) = check_tied_features(sess, &featsmap) {
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
features: f,
span: None,
missing_features: None,
});
}
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
features: f,
span: None,
missing_features: None,
});
}

features
Expand Down
25 changes: 11 additions & 14 deletions src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
m_len == v_len,
InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
);
// TODO: also support unsigned integers.
match *m_elem_ty.kind() {
ty::Int(_) => {}
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
_ => return_error!(InvalidMonomorphization::MaskWrongElementType {
span,
name,
ty: m_elem_ty
}),
}
return Ok(bx.vector_select(args[0].immediate(), args[1].immediate(), args[2].immediate()));
}
Expand Down Expand Up @@ -991,19 +996,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
assert_eq!(pointer_count - 1, ptr_count(element_ty0));
assert_eq!(underlying_ty, non_ptr(element_ty0));

// The element type of the third argument must be a signed integer type of any width:
// The element type of the third argument must be an integer type of any width:
// TODO: also support unsigned integers.
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
match *element_ty2.kind() {
ty::Int(_) => (),
_ => {
require!(
false,
InvalidMonomorphization::ThirdArgElementType {
span,
name,
expected_element: element_ty2,
third_arg: arg_tys[2]
}
InvalidMonomorphization::MaskWrongElementType { span, name, ty: element_ty2 }
);
}
}
Expand Down Expand Up @@ -1109,17 +1110,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
assert_eq!(underlying_ty, non_ptr(element_ty0));

// The element type of the third argument must be a signed integer type of any width:
// TODO: also support unsigned integers.
match *element_ty2.kind() {
ty::Int(_) => (),
_ => {
require!(
false,
InvalidMonomorphization::ThirdArgElementType {
span,
name,
expected_element: element_ty2,
third_arg: arg_tys[2]
}
InvalidMonomorphization::MaskWrongElementType { span, name, ty: element_ty2 }
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#![warn(rust_2018_idioms)]
#![warn(unused_lifetimes)]
#![deny(clippy::pattern_type_mismatch)]
#![allow(clippy::needless_lifetimes)]
#![allow(clippy::needless_lifetimes, clippy::uninlined_format_args)]

// Some "regular" crates we want to share with rustc
extern crate object;
Expand Down
14 changes: 7 additions & 7 deletions src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ fn uncached_gcc_type<'gcc, 'tcx>(
let mut name = with_no_trimmed_paths!(layout.ty.to_string());
if let (&ty::Adt(def, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants)
&& def.is_enum()
&& !def.variants().is_empty()
{
if def.is_enum() && !def.variants().is_empty() {
write!(&mut name, "::{}", def.variant(index).name).unwrap();
}
write!(&mut name, "::{}", def.variant(index).name).unwrap();
}
if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants)
Expand Down Expand Up @@ -264,10 +264,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
}

fn immediate_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
if let BackendRepr::Scalar(ref scalar) = self.backend_repr {
if scalar.is_bool() {
return cx.type_i1();
}
if let BackendRepr::Scalar(ref scalar) = self.backend_repr
&& scalar.is_bool()
{
return cx.type_i1();
}
self.gcc_type(cx)
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lang_tests_common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! The common code for `tests/lang_tests_*.rs`
#![allow(clippy::uninlined_format_args)]

use std::env::{self, current_dir};
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down
21 changes: 16 additions & 5 deletions tests/run/ptr_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//
// Run-time:
// status: 0
// stdout: 1
// stdout: 10
// 10
// 42
// 1

#![feature(no_core)]
#![no_std]
Expand All @@ -12,15 +15,23 @@
extern crate mini_core;
use mini_core::*;

static mut ONE: usize = 1;

fn make_array() -> [u8; 3] {
[42, 10, 5]
fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
(
a as u8, a as u16, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
b as u32,
)
}

static mut ONE: usize = 1;

#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
let (a, b, c, d, e, f, g, h, i, j) = int_cast(10, 42);
unsafe {
libc::printf(b"%d\n\0" as *const u8 as *const i8, c);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, d);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, j);

let ptr = ONE as *mut usize;
let value = ptr as usize;
libc::printf(b"%ld\n\0" as *const u8 as *const i8, value);
Expand Down