Skip to content

Loop match lint level #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

folkertdev
Copy link
Collaborator

As far as I can tell, just using the hir id of the LoopMatch is sufficient, and it does not really make sense to store that value separately if we can just retrieve it from the builder.

@folkertdev folkertdev requested a review from bjorn3 March 19, 2025 11:37
@folkertdev folkertdev force-pushed the loop-match-lint-level branch from 53238e3 to 75f16f9 Compare March 19, 2025 11:38
normally this is he HirID of the match, but we don't have that, so instead use the HirId of the `LoopMatch`. The match arm already have their own lint level
@folkertdev folkertdev force-pushed the loop-match-lint-level branch from 75f16f9 to ccf1f40 Compare March 20, 2025 11:07
@folkertdev folkertdev merged commit b4952ca into trifectatechfoundation:loop_match_attr Mar 20, 2025
1 check passed
folkertdev pushed a commit that referenced this pull request Mar 21, 2025
Emit function declarations for functions with `#[linkage="extern_weak"]`

Currently, when declaring an extern weak function in Rust, we use the following syntax:
```rust
unsafe extern "C" {
   #[linkage = "extern_weak"]
   static FOO: Option<unsafe extern "C" fn() -> ()>;
}
```
This allows runtime-checking the extern weak symbol through the Option.

When emitting LLVM-IR, the Rust compiler currently emits this static as an i8, and a pointer that is initialized with the value of the global i8 and represents the nullabilty e.g.
```
`@FOO` = extern_weak global i8
`@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO`
```

This approach does not work well with CFI, where we need to attach CFI metadata to a concrete function declaration, which was pointed out in rust-lang#115199.

This change switches to emitting a proper function declaration instead of a global i8. This allows CFI to work for extern_weak functions. Example:
```
`@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO`
...
declare !type !61 !type !62 !type !63 !type !64 extern_weak void `@FOO(double)` unnamed_addr #6
```

We keep initializing the Rust internal symbol with the function declaration, which preserves the correct behavior for runtime checking the Option.

r? `@rcvalle`

cc `@jakos-sec`

try-job: test-various
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants