Skip to content

Commit dd195ae

Browse files
committed
Fix clippy
1 parent 2514dfe commit dd195ae

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

crates/cust/src/device.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ impl Device {
352352
unsafe {
353353
driver_sys::cuDeviceGetUuid(&mut cu_uuid, self.device).to_result()?;
354354
}
355-
#[allow(clippy::unnecessary_cast)]
356-
let uuid: [u8; 16] = cu_uuid.bytes.map(|byte| byte as u8);
355+
let uuid: [u8; 16] = cu_uuid.bytes;
357356
Ok(uuid)
358357
}
359358

crates/ptx_compiler/src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ impl CompilerFailure {
102102
.to_result()?;
103103
let size = size.assume_init();
104104
let mut vec = Vec::with_capacity(size);
105-
nvptx_compiler_sys::nvPTXCompilerGetErrorLog(
106-
self.handle,
107-
vec.as_mut_ptr() as *mut c_char,
108-
)
109-
.to_result()?;
105+
nvptx_compiler_sys::nvPTXCompilerGetErrorLog(self.handle, vec.as_mut_ptr())
106+
.to_result()?;
110107
vec.set_len(size);
111108
Ok(String::from_utf8_lossy(&vec).to_string())
112109
}
@@ -138,11 +135,8 @@ impl CompiledProgram {
138135
.to_result()?;
139136
let size = size.assume_init();
140137
let mut vec = Vec::with_capacity(size);
141-
nvptx_compiler_sys::nvPTXCompilerGetInfoLog(
142-
self.handle,
143-
vec.as_mut_ptr() as *mut c_char,
144-
)
145-
.to_result()?;
138+
nvptx_compiler_sys::nvPTXCompilerGetInfoLog(self.handle, vec.as_mut_ptr())
139+
.to_result()?;
146140
vec.set_len(size);
147141
Ok(String::from_utf8_lossy(&vec).to_string())
148142
}

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
549549
ty: &'ll Type,
550550
ptr: &'ll Value,
551551
order: AtomicOrdering,
552-
size: Size,
552+
_size: Size,
553553
) -> &'ll Value {
554554
// Since for any A, A | 0 = A, and performing atomics on constant memory is UB in Rust, we can abuse or to perform atomic reads.
555555
self.atomic_rmw(AtomicRmwBinOp::AtomicOr, ptr, self.const_int(ty, 0), order)
@@ -782,7 +782,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
782782
val: &'ll Value,
783783
ptr: &'ll Value,
784784
order: AtomicOrdering,
785-
size: Size,
785+
_size: Size,
786786
) {
787787
// We can exchange *ptr with val, and then discard the result.
788788
self.atomic_rmw(AtomicRmwBinOp::AtomicXchg, ptr, val, order);
@@ -1164,8 +1164,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11641164
// We pack the result, to match the behaviour of proper atomics / emulated thread-local atomics.
11651165
let res = builder.const_undef(res_type);
11661166
let res = builder.insert_value(res, load, 0);
1167-
let res = builder.insert_value(res, compare, 1);
1168-
res
1167+
builder.insert_value(res, compare, 1)
11691168
},
11701169
);
11711170
// Unpack the result
@@ -1190,7 +1189,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11901189
unsafe {
11911190
llvm::LLVMBuildAtomicRMW(
11921191
builder.llbuilder,
1193-
op,
1192+
op.into(),
11941193
dst,
11951194
src,
11961195
crate::llvm::AtomicOrdering::from_generic(order),

crates/rustc_codegen_nvvm/src/llvm.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ unsafe extern "C" {
19601960

19611961
pub fn LLVMBuildAtomicRMW<'a>(
19621962
B: &Builder<'a>,
1963-
Op: AtomicRmwBinOp,
1963+
Op: LLVMAtomicRmwBinOp,
19641964
LHS: &Value,
19651965
RHS: &Value,
19661966
Order: AtomicOrdering,
@@ -1994,3 +1994,38 @@ impl AtomicOrdering {
19941994
}
19951995
}
19961996
}
1997+
1998+
/// FFI-safe mirror of LLVMAtomicRMWBinOp from the LLVM C API.
1999+
#[derive(Copy, Clone)]
2000+
#[repr(C)]
2001+
pub enum LLVMAtomicRmwBinOp {
2002+
AtomicXchg = 0,
2003+
AtomicAdd = 1,
2004+
AtomicSub = 2,
2005+
AtomicAnd = 3,
2006+
AtomicNand = 4,
2007+
AtomicOr = 5,
2008+
AtomicXor = 6,
2009+
AtomicMax = 7,
2010+
AtomicMin = 8,
2011+
AtomicUMax = 9,
2012+
AtomicUMin = 10,
2013+
}
2014+
2015+
impl From<AtomicRmwBinOp> for LLVMAtomicRmwBinOp {
2016+
fn from(op: AtomicRmwBinOp) -> Self {
2017+
match op {
2018+
AtomicRmwBinOp::AtomicXchg => Self::AtomicXchg,
2019+
AtomicRmwBinOp::AtomicAdd => Self::AtomicAdd,
2020+
AtomicRmwBinOp::AtomicSub => Self::AtomicSub,
2021+
AtomicRmwBinOp::AtomicAnd => Self::AtomicAnd,
2022+
AtomicRmwBinOp::AtomicNand => Self::AtomicNand,
2023+
AtomicRmwBinOp::AtomicOr => Self::AtomicOr,
2024+
AtomicRmwBinOp::AtomicXor => Self::AtomicXor,
2025+
AtomicRmwBinOp::AtomicMax => Self::AtomicMax,
2026+
AtomicRmwBinOp::AtomicMin => Self::AtomicMin,
2027+
AtomicRmwBinOp::AtomicUMax => Self::AtomicUMax,
2028+
AtomicRmwBinOp::AtomicUMin => Self::AtomicUMin,
2029+
}
2030+
}
2031+
}

0 commit comments

Comments
 (0)