Skip to content

Commit b85cd8a

Browse files
committed
further tweaks
1 parent 30d9b7d commit b85cd8a

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
820820
let scalar = self.read_scalar(arg_mplace)?;
821821
if scalar.to_int(size)? < 0 {
822822
throw_ub_format!(
823-
"va_arg value mismatch: value `{value}_{caller_ty}` cannot be represented by type {callee_ty}",
823+
"va_arg value mismatch: value `{value}_{caller_ty}` cannot be represented by type `{callee_ty}`",
824824
value = if source_is_signed {
825825
scalar.to_int(size)?.to_string()
826826
} else {

library/core/src/ffi/va_list.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,12 @@ impl<'f> VaList<'f> {
390390
///
391391
/// # Safety
392392
///
393-
/// This function is only sound to call when there is another argument to read, and that
394-
/// argument is a properly initialized value compatible with the type `T`.
393+
/// This function is safe to call only if all of the following conditions are satisfied:
394+
///
395+
/// - There is another c-variadic argument to read.
396+
/// - The actual type of the argument `U` is compatible with `T` (as defined below).
397+
/// - If `U` and `T` are both integer types, then the value passed by the caller must be
398+
/// representable in both types.
395399
///
396400
/// Types `T` and `U` are compatible when:
397401
///
@@ -400,12 +404,6 @@ impl<'f> VaList<'f> {
400404
/// - `T` and `U` are both pointers, and their target types are compatible.
401405
/// - `T` is a pointer to [`c_void`] and `U` is a pointer to [`i8`] or [`u8`], or vice versa.
402406
///
403-
/// When `T` and `U` are integer types of the same size but different signedness,
404-
/// the value that the caller passes must be representable by both `T` and `U`.
405-
///
406-
/// Calling this function with an incompatible type, an invalid value, or when there
407-
/// are no more variable arguments, is unsound.
408-
///
409407
/// [`c_void`]: core::ffi::c_void
410408
#[inline] // Avoid codegen when not used to help backends that don't support VaList.
411409
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]

tests/ui/consts/const-eval/c-variadic-fail.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ unsafe fn read_cast_numeric() {
7070
const { read_as::<isize>(-1 as ConcreteIsize) };
7171

7272
const { read_as::<u32>(-1i32) };
73-
//~^ ERROR va_arg value mismatch: value `-1_i32` cannot be represented by type u32
73+
//~^ ERROR va_arg value mismatch: value `-1_i32` cannot be represented by type `u32`
7474
const { read_as::<u32>(i32::MIN) };
75-
//~^ ERROR va_arg value mismatch: value `-2147483648_i32` cannot be represented by type u32
75+
//~^ ERROR va_arg value mismatch: value `-2147483648_i32` cannot be represented by type `u32`
7676
const { read_as::<i32>(u32::MAX) };
77-
//~^ ERROR va_arg value mismatch: value `4294967295_u32` cannot be represented by type i32
77+
//~^ ERROR va_arg value mismatch: value `4294967295_u32` cannot be represented by type `i32`
7878
const { read_as::<i32>(i32::MAX as u32 + 1) };
79-
//~^ ERROR va_arg value mismatch: value `2147483648_u32` cannot be represented by type i32
79+
//~^ ERROR va_arg value mismatch: value `2147483648_u32` cannot be represented by type `i32`
8080
const { read_as::<i64>(u64::MAX) };
81-
//~^ ERROR va_arg value mismatch: value `18446744073709551615_u64` cannot be represented by type i64
81+
//~^ ERROR va_arg value mismatch: value `18446744073709551615_u64` cannot be represented by type `i64`
8282
const { read_as::<i64>(i64::MAX as u64 + 1) };
83-
//~^ ERROR va_arg value mismatch: value `9223372036854775808_u64` cannot be represented by type i64
83+
//~^ ERROR va_arg value mismatch: value `9223372036854775808_u64` cannot be represented by type `i64`
8484

8585
const { read_as::<i32>(1u64) };
8686
//~^ ERROR va_arg type mismatch: requested `i32` is incompatible with next argument of type `u64`

tests/ui/consts/const-eval/c-variadic-fail.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ LL | const { read_n::<2>(1) }
5454
|
5555
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5656

57-
error[E0080]: va_arg value mismatch: value `-1_i32` cannot be represented by type u32
57+
error[E0080]: va_arg value mismatch: value `-1_i32` cannot be represented by type `u32`
5858
--> $DIR/c-variadic-fail.rs:72:13
5959
|
6060
LL | const { read_as::<u32>(-1i32) };
@@ -82,7 +82,7 @@ LL | const { read_as::<u32>(-1i32) };
8282
|
8383
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8484

85-
error[E0080]: va_arg value mismatch: value `-2147483648_i32` cannot be represented by type u32
85+
error[E0080]: va_arg value mismatch: value `-2147483648_i32` cannot be represented by type `u32`
8686
--> $DIR/c-variadic-fail.rs:74:13
8787
|
8888
LL | const { read_as::<u32>(i32::MIN) };
@@ -110,7 +110,7 @@ LL | const { read_as::<u32>(i32::MIN) };
110110
|
111111
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
112112

113-
error[E0080]: va_arg value mismatch: value `4294967295_u32` cannot be represented by type i32
113+
error[E0080]: va_arg value mismatch: value `4294967295_u32` cannot be represented by type `i32`
114114
--> $DIR/c-variadic-fail.rs:76:13
115115
|
116116
LL | const { read_as::<i32>(u32::MAX) };
@@ -138,7 +138,7 @@ LL | const { read_as::<i32>(u32::MAX) };
138138
|
139139
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
140140

141-
error[E0080]: va_arg value mismatch: value `2147483648_u32` cannot be represented by type i32
141+
error[E0080]: va_arg value mismatch: value `2147483648_u32` cannot be represented by type `i32`
142142
--> $DIR/c-variadic-fail.rs:78:13
143143
|
144144
LL | const { read_as::<i32>(i32::MAX as u32 + 1) };
@@ -166,7 +166,7 @@ LL | const { read_as::<i32>(i32::MAX as u32 + 1) };
166166
|
167167
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
168168

169-
error[E0080]: va_arg value mismatch: value `18446744073709551615_u64` cannot be represented by type i64
169+
error[E0080]: va_arg value mismatch: value `18446744073709551615_u64` cannot be represented by type `i64`
170170
--> $DIR/c-variadic-fail.rs:80:13
171171
|
172172
LL | const { read_as::<i64>(u64::MAX) };
@@ -194,7 +194,7 @@ LL | const { read_as::<i64>(u64::MAX) };
194194
|
195195
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
196196

197-
error[E0080]: va_arg value mismatch: value `9223372036854775808_u64` cannot be represented by type i64
197+
error[E0080]: va_arg value mismatch: value `9223372036854775808_u64` cannot be represented by type `i64`
198198
--> $DIR/c-variadic-fail.rs:82:13
199199
|
200200
LL | const { read_as::<i64>(i64::MAX as u64 + 1) };

0 commit comments

Comments
 (0)