Skip to content
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

some fixes for clashing_extern_declarations lint #130301

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

RalfJung
Copy link
Member

There were two issues with the clashing_extern_declarations lint:

  • It would accept non-repr(C) structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with -Zrandomize-layout, this can really happen).
  • It would accept two types as compatible if compare_layouts returns true, but that function actually just compared the ABI, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (Abi::Aggregate), so this missed a lot of cases.

We don't currently have a clear spec for what we want to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.

@rustbot
Copy link
Collaborator

rustbot commented Sep 13, 2024

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

@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. labels Sep 13, 2024
@RalfJung RalfJung force-pushed the clashing_extern_declarations branch 2 times, most recently from 795ee23 to e842eec Compare September 13, 2024 09:34
b_layout,
a_layout == b_layout
);
Ok(a_layout == b_layout)
Copy link
Member Author

@RalfJung RalfJung Sep 13, 2024

Choose a reason for hiding this comment

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

I ended up removing this logic entirely. It is never sound to do this, and none of the tests relied on this, so the motivation is unclear.

If this warns for too many real-world cases, people will tell us. :)

@RalfJung RalfJung force-pushed the clashing_extern_declarations branch from e842eec to f362a59 Compare September 13, 2024 09:51
@@ -311,9 +311,9 @@ fn structurally_same_type_impl<'tcx>(
},
)
}
(Array(a_ty, a_const), Array(b_ty, b_const)) => {
// For arrays, we also check the constness of the type.
Copy link
Member

Choose a reason for hiding this comment

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

"the constness" 💀

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah...

@compiler-errors
Copy link
Member

Thanks for fixing this and I agree with the changes, even if they cause the lint to fire more aggressively it's like... objectively more correct.

@bors r+

@bors
Copy link
Contributor

bors commented Sep 13, 2024

📌 Commit f362a59 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors 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 Sep 13, 2024
@compiler-errors compiler-errors self-assigned this Sep 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7d36bfa into rust-lang:master Sep 13, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2024
Rollup merge of rust-lang#130301 - RalfJung:clashing_extern_declarations, r=compiler-errors

some fixes for clashing_extern_declarations lint

There were two issues with the clashing_extern_declarations lint:
- It would accept non-`repr(C)` structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with `-Zrandomize-layout`, this can really happen).
- It would accept two types as compatible if `compare_layouts` returns `true`, but that function actually just compared the *ABI*, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (`Abi::Aggregate`), so this missed a *lot* of cases.

We don't currently have a clear spec for what we *want* to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.
@RalfJung RalfJung deleted the clashing_extern_declarations branch September 15, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants