Uh oh!
There was an error while loading. Please reload this page.
Add a lint to catch clashing extern fn declarations. - #70946
Conversation
jumbatm
commented
Apr 9, 2020
Just as a reminder, per #69390 (comment), this PR should go through a crater-check run before merging (which should also let us see if changing the lint to be |
eddyb
commented
Apr 9, 2020
r? @nagisa cc @hanna-kruppe (LGTM at a glance though) |
This is missing a test (and I think lint will fail to correctly handle) for two two not clashing declarations that use independently declared types. That is: mod one {#[repr(C)]structBanana{weight:u64}extern"C"{fnweigh_banana(count:*constBanana) -> u64;}}mod two {#[repr(C)]structBanana{weight:u64}// note: distinct type// For a weirder corner case (may still be valid depending on how C code is written):// #[repr(C)] struct Banana { weight: u64, some_optional_field: u64 }extern"C"{fnweigh_banana(count:*constBanana) -> u64;}} |
01e6771 to
9c08571Compareextern declarations.extern fn declarations.Uh oh!
There was an error while loading. Please reload this page.
bjorn3
commented
Apr 19, 2020
Should this also check across multiple crates? |
jumbatm
commented
Apr 19, 2020
Current thinking is no, because two crates may bind to the same extern function with signatures that are different, but compatible under that language or ABI. |
bors
commented
Apr 26, 2020
☔ The latest upstream changes (presumably #71566) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
May 9, 2020
☔ The latest upstream changes (presumably #72036) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
May 16, 2020
☔ The latest upstream changes (presumably #72276) made this pull request unmergeable. Please resolve the merge conflicts. |
6022d63 to
42e75ebComparerust-highfive
commented
May 17, 2020
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
42e75eb to
8f6f3d6Comparejumbatm
commented
May 18, 2020
Hey @nagisa, this is ready for re-review. |
This overall LGTM now. I think it does get the balance right. Can you please clean up the commits/history a little? Squashing some together, especially those that refer to rustfmt, etc would be ideal. r=me once that's done. |
8f6f3d6 to
337abf1Comparenagisa
commented
May 20, 2020
@bors r+ |
bors
commented
May 20, 2020
📌 Commit 337abf1 has been approved by |
bors
commented
May 20, 2020
🌲 The tree is currently closed for pull requests below priority 9000, this pull request will be tested once the tree is reopened |
jumbatm
commented
May 20, 2020
Should we do a crater-check run first? Given this fixes a soundness issue, I'd like to make this lint Deny by default, but want to see if it'd break any existing crates. |
Add a lint to catch clashing `extern` fn declarations. Closesrust-lang#69390. Adds lint `clashing_extern_decl` to detect when, within a single crate, an extern function of the same name is declared with different types. Because two symbols of the same name cannot be resolved to two different functions at link time, and one function cannot possibly have two types, a clashing extern declaration is almost certainly a mistake. This lint does not run between crates because a project may have dependencies which both rely on the same extern function, but declare it in a different (but valid) way. For example, they may both declare an opaque type for one or more of the arguments (which would end up distinct types), or use types that are valid conversions in the language the extern fn is defined in. In these cases, we can't say that the clashing declaration is incorrect. r? @eddyb
This lint checks that all declarations for extern fns of the same name are declared with the same types.
- Allow ClashingExternDecl for lint-dead-code-3 - Update test case for rust-lang#5791 - Update test case for rust-lang#1866 - Update extern-abi-from-macro test case
e1eee56 to
556b7baComparejumbatm
commented
Jun 20, 2020
Hey @nagisa, can I get another review? Fingers crossed this can get merged soon. |
nagisa
commented
Jun 20, 2020
@bors r+ |
bors
commented
Jun 20, 2020
📌 Commit 556b7ba has been approved by |
bors
commented
Jun 20, 2020
⌛ Testing commit 556b7ba with merge 4399d4f09c61ea4b3a9070ddc591ab4d72a563d9... |
bors
commented
Jun 20, 2020
💥 Test timed out |
Dylan-DPC-zz
commented
Jun 20, 2020
going to retry again @bors retry |
bors
commented
Jun 21, 2020
bors
commented
Jun 21, 2020
☀️ Test successful - checks-azure |
The lint doesn't follow the lint naming conventions - https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#lints. It should preferably be renamed |
Closes#69390.
Adds lint
clashing_extern_declto detect when, within a single crate, an extern function of the same name is declared with different types. Because two symbols of the same name cannot be resolved to two different functions at link time, and one function cannot possibly have two types, a clashing extern declaration is almost certainly a mistake.This lint does not run between crates because a project may have dependencies which both rely on the same extern function, but declare it in a different (but valid) way. For example, they may both declare an opaque type for one or more of the arguments (which would end up distinct types), or use types that are valid conversions in the language the extern fn is defined in. In these cases, we can't say that the clashing declaration is incorrect.
r? @eddyb