Skip to content

Add CFI tests for return types and never type#159950

Open
Darksonn wants to merge 1 commit into
rust-lang:mainfrom
Darksonn:cfi-return-types
Open

Add CFI tests for return types and never type#159950
Darksonn wants to merge 1 commit into
rust-lang:mainfrom
Darksonn:cfi-return-types

Conversation

@Darksonn

@Darksonn Darksonn commented Jul 26, 2026

Copy link
Copy Markdown
Member

In a few different conversations, the CFI types of various functions has come up. First, the CFI type of returning ! came up in #159446 (comment), where we found that it doesn't have the same CFI type as returning (), which it probably should.

Then in #159935, I wanted to make sure that this does not change the CFI type of functions when *mut c_void appears as an argument. Luckily it does not since it's a lang item, but there's no test for this case.

Thus, add tests for all of these cases and a few others.

AI assistance was involved with writing the test.

Verifies that LLVM emits correct CFI type metadata identifiers for
functions returning `()`, `!`, `*mut c_void`, `*const c_void`, `*mut ()`,
`*mut u8`, and `*mut i8`:
- `_ZTSFvvE` (`fn()`)
- `_ZTSFu5nevervE` (`fn() -> !`)
- `_ZTSFPvS_E` (`fn(*mut c_void) -> *mut c_void` and `fn(*mut ()) -> *mut ()`)
- `_ZTSFPKvS0_E` (`fn(*const c_void) -> *const c_void`)
- `_ZTSFPu2u8S0_E` (`fn(*mut u8) -> *mut u8`)
- `_ZTSFPu2i8S0_E` (`fn(*mut i8) -> *mut i8`)
@Darksonn Darksonn added the A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation label Jul 26, 2026
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in tests/codegen-llvm/sanitizer

cc @rcvalle

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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. labels Jul 26, 2026
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 16 candidates

@Darksonn Darksonn mentioned this pull request Jul 26, 2026
@mejrs

mejrs commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

I'm not familiar with this...

r? @folkertdev perhaps?

@rustbot rustbot assigned folkertdev and unassigned mejrs Jul 26, 2026

@folkertdev folkertdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, locking in the current state seems useful

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8e0f2e9 has been approved by folkertdev

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…rtdev

Add CFI tests for return types and never type

In a few different conversations, the CFI types of various functions has come up. First, the CFI type of returning `!` came up in rust-lang#159446 (comment), where we found that it doesn't have the same CFI type as returning `()`, which it probably should.

Then in rust-lang#159935, I wanted to make sure that this does not change the CFI type of functions when `*mut c_void` appears as an argument. Luckily it does not since it's a lang item, but there's no test for this case.

Thus, add tests for all of these cases and a few others.

AI assistance was involved with writing the test.
rust-bors Bot pushed a commit that referenced this pull request Jul 26, 2026
…uwer

Rollup of 28 pull requests

Successful merges:

 - #159638 (bootstrap: Split the `Step` trait into multiple traits)
 - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations)
 - #159837 (line-tables-only test: check that the line number matches the function name)
 - #159946 (Update Enzyme submodule to imporve llvm-cov)
 - #159962 (miri subtree update)
 - #156570 (tests: extend remap-path-prefix-std to all stdlib rlibs)
 - #159617 (Fix up `#[linkage]` target checking)
 - #159633 (Improve workings of attribute suggestions)
 - #159733 (std: Switch implementations of `thread_local!` for WASI)
 - #159783 (Check unsafe impls on safe EIIs)
 - #159810 (Add tuple never coercion collection regression test)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159846 (Implement `str::copy_from_str`)
 - #159849 (rustc_parse: Stop returning `Option` from statement parsing)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159875 (More cleanup in `rustc_attr_parsing`)
 - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide)
 - #159891 (Split multiline derives into std/rustc macros)
 - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups)
 - #159895 (rustc-dev-guide subtree update)
 - #159902 (Clarify that the expected runtime symbols signature is for the current target only)
 - #159914 (Fix error in diagnostic on_unmatched_args)
 - #159917 (spare capacity mut constification)
 - #159918 (rename abort_unwind → abort_on_unwind)
 - #159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.)
 - #159936 (Minor `rustc_ast::ast` doc cleanups)
 - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
 - #159950 (Add CFI tests for return types and never type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler 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