Skip to content

Commit 65f66ec

Browse files
nnethercoteLegNeato
authored andcommitted
Update compiletest to edition 2024.
Again, all the unsafe operations within unsafe functions now need explicit `unsafe` marking.
1 parent bb12b30 commit 65f66ec

23 files changed

+157
-77
lines changed

tests/compiletests/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Runner {
109109
.iter()
110110
.map(|dir| format!("-L dependency={}", dir.display()))
111111
.fold(String::new(), |a, b| b + " " + &a),
112-
"--edition 2021",
112+
"--edition 2024",
113113
&*format!("--extern noprelude:core={}", deps.core.display()),
114114
&*format!(
115115
"--extern noprelude:compiler_builtins={}",

tests/compiletests/ui/atomic/atomic_operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub unsafe fn test_cuda_atomic_floats() {
1717

1818
// Block-scoped atomic float
1919
let block_atomic = BlockAtomicF32::new(1.5);
20-
let _old = block_atomic.fetch_add(0.5, Ordering::Relaxed);
20+
let _old = unsafe { block_atomic.fetch_add(0.5, Ordering::Relaxed) };
2121

2222
// System-scoped atomic float
2323
let system_atomic = SystemAtomicF32::new(0.0);
@@ -29,7 +29,7 @@ pub unsafe fn test_cuda_atomic_floats() {
2929

3030
// Test block-scoped f64
3131
let block_f64 = BlockAtomicF64::new(2.718);
32-
let _old = block_f64.fetch_sub(0.5, Ordering::Relaxed);
32+
let _old = unsafe { block_f64.fetch_sub(0.5, Ordering::Relaxed) };
3333

3434
// Test bitwise operations on floats
3535
let _old = atomic_f32.fetch_and(3.14, Ordering::Relaxed);

tests/compiletests/ui/core/ops/range_contains.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ fn has_two_decimal_digits(x: u32) -> bool {
88

99
#[kernel]
1010
pub unsafe fn main(i: u32, o: *mut u32) {
11-
*o = has_two_decimal_digits(i) as u32;
11+
unsafe {
12+
*o = has_two_decimal_digits(i) as u32;
13+
}
1214
}

tests/compiletests/ui/dis/simple_add.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use cuda_std::kernel;
77

88
#[kernel]
99
pub unsafe fn simple_add_kernel(a: *const f32, b: *const f32, c: *mut f32) {
10-
let sum = *a + *b;
11-
*c = sum;
10+
unsafe {
11+
let sum = *a + *b;
12+
*c = sum;
13+
}
1214
}

tests/compiletests/ui/dis/simple_add.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ $L__tmp0:
1919
cvta.to.global.u64 %rd4, %rd3;
2020
cvta.to.global.u64 %rd5, %rd2;
2121
cvta.to.global.u64 %rd6, %rd1;
22-
.loc 1 10 15
22+
.loc 1 11 19
2323
ld.global.f32 %f1, [%rd6];
24-
.loc 1 10 20
24+
.loc 1 11 24
2525
ld.global.f32 %f2, [%rd5];
26-
.loc 1 10 15
26+
.loc 1 11 19
2727
add.f32 %f3, %f1, %f2;
2828
$L__tmp1:
29-
.loc 1 11 5
29+
.loc 1 12 9
3030
st.global.f32 [%rd4], %f3;
3131
$L__tmp2:
32-
.loc 1 12 2
32+
.loc 1 14 2
3333
ret;
3434
$L__tmp3:
3535
$L__func_end0:

tests/compiletests/ui/glam/mat3_vec3_multiply.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ use cuda_std::kernel;
77
#[kernel]
88
pub unsafe fn mat3_vec3_multiply(input: glam::Mat3, output: *mut glam::Vec3) {
99
let vector = input * glam::Vec3::new(1.0, 2.0, 3.0);
10-
*output = vector;
10+
unsafe {
11+
*output = vector;
12+
}
1113
}

tests/compiletests/ui/glam/mat4_operations.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ pub unsafe fn mat4_transform_operations(
1616
) {
1717
// Transform a 3D point (w=1 implied)
1818
let transformed_point = matrix.transform_point3(point);
19-
*result_point = transformed_point;
19+
unsafe {
20+
*result_point = transformed_point;
21+
}
2022

2123
// Transform a 4D vector
2224
let transformed_vector = matrix * vector;
23-
*result_vector = transformed_vector;
25+
unsafe {
26+
*result_vector = transformed_vector;
27+
}
2428

2529
// Calculate determinant
2630
let det = matrix.determinant();
27-
*result_determinant = det;
31+
unsafe {
32+
*result_determinant = det;
33+
}
2834
}
2935

3036
#[kernel]
@@ -39,13 +45,19 @@ pub unsafe fn mat4_construction(
3945
) {
4046
// Create translation matrix
4147
let trans_mat = Mat4::from_translation(translation);
42-
*result_translation = trans_mat;
48+
unsafe {
49+
*result_translation = trans_mat;
50+
}
4351

4452
// Create scale matrix
4553
let scale_mat = Mat4::from_scale(scale);
46-
*result_scale = scale_mat;
54+
unsafe {
55+
*result_scale = scale_mat;
56+
}
4757

4858
// Create rotation matrix
4959
let rot_mat = Mat4::from_axis_angle(axis, angle_radians);
50-
*result_rotation = rot_mat;
60+
unsafe {
61+
*result_rotation = rot_mat;
62+
}
5163
}

tests/compiletests/ui/glam/vec3_operations.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ pub unsafe fn vec3_basic_ops(
1515
) {
1616
// Vector addition
1717
let sum = a + b;
18-
*result_add = sum;
18+
unsafe {
19+
*result_add = sum;
20+
}
1921

2022
// Dot product
2123
let dot = a.dot(b);
22-
*result_dot = dot;
24+
unsafe {
25+
*result_dot = dot;
26+
}
2327

2428
// Cross product
2529
let cross = a.cross(b);
26-
*result_cross = cross;
30+
unsafe {
31+
*result_cross = cross;
32+
}
2733
}
2834

2935
#[kernel]
@@ -34,9 +40,13 @@ pub unsafe fn vec3_normalization(
3440
) {
3541
// Get length
3642
let len = input.length();
37-
*result_length = len;
43+
unsafe {
44+
*result_length = len;
45+
}
3846

3947
// Normalize
4048
let normalized = input.normalize();
41-
*result_normalized = normalized;
49+
unsafe {
50+
*result_normalized = normalized;
51+
}
4252
}

tests/compiletests/ui/hello_world.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ use cuda_std::kernel;
44

55
#[kernel]
66
pub unsafe fn add_one(x: *mut f32) {
7-
*x = *x + 1.0;
7+
unsafe {
8+
*x = *x + 1.0;
9+
}
810
}

tests/compiletests/ui/lang/consts/constant_memory_overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ static BIG_ARRAY_3: [u32; ARRAY_SIZE] = [333u32; ARRAY_SIZE];
1717

1818
#[kernel]
1919
pub unsafe fn test_kernel(out: *mut u32) {
20-
*out = BIG_ARRAY_1[0] + BIG_ARRAY_2[0] + BIG_ARRAY_3[0];
20+
unsafe { *out = BIG_ARRAY_1[0] + BIG_ARRAY_2[0] + BIG_ARRAY_3[0] };
2121
}

0 commit comments

Comments
 (0)