Skip to content

c-variadic: more precise compatibility check in const-eval#155832

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:c-variadic-ub-check
Open

c-variadic: more precise compatibility check in const-eval#155832
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:c-variadic-ub-check

Conversation

@folkertdev
Copy link
Copy Markdown
Contributor

tracking issue: #44930

This came up in the stabilization report discussion #155697 (comment).

As a reminder, this is what C says (in section 7.16.1.1 of the C23 standard.

If type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:

  • both types are pointers to qualified or unqualified versions of compatible types;
  • one type is compatible with a signed integer type, the other type is compatible with the
    corresponding unsigned integer type, and the value is representable in both types;
  • one type is pointer to qualified or unqualified void and the other is a pointer to a qualified or
    unqualified character type;
  • or, the type of the next argument is nullptr_t and type is a pointer type that has the same representation and alignment requirements as a pointer to a character type

I think the last rule is not relevant for us, we don't really have an equivalent of nullptr_t as far as I know.

r? RalfJung
cc @tgross35

@folkertdev folkertdev added the F-c_variadic `#![feature(c_variadic)]` label Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

Comment on lines +824 to +827
match int_ty {
IntTy::Isize => match self.data_layout().pointer_size().bits() {
16 => validate_cast::<i16, u16>(scalar.to_i16()?, callee_ty)?,
32 => validate_cast::<i32, u32>(scalar.to_i32()?, callee_ty)?,
Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there some way to check whether a lossless conversion between integer types is possible in the const-eval API that I'm missing?

View changes since the review

Copy link
Copy Markdown
Contributor Author

@folkertdev folkertdev Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the changes here are all in const-eval, what (if anything) should be tested in Miri?

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the c-variadic-ub-check branch from d15adf3 to 6aedccd Compare April 26, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-c_variadic `#![feature(c_variadic)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants