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

Add DerefOfRawPointer and CallToFunctionWith to THIR unsafeck #85306

Closed

Conversation

LeSeulArtichaut
Copy link
Contributor

@LeSeulArtichaut LeSeulArtichaut commented May 14, 2021

Extends THIR unsafeck to check for two more cases of unsafe operations: dereferences of raw pointers and calls to functions with #[target_feature] (RFC 2396). The check for the latter is pretty much copy-pasted from the existing MIR equivalent.

This will clash with #83842 and #85273 which are arguably more important, let's maybe focus on getting those merged first, this can wait.
r? @nikomatsakis
cc rust-lang/project-thir-unsafeck#7

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2021
@bors

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

r=me modulo the question below

@@ -148,11 +152,28 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
ExprKind::Call { fun, ty: _, args: _, from_hir_call: _, fn_span: _ } => {
if self.thir[fun].ty.fn_sig(self.tcx).unsafety() == hir::Unsafety::Unsafe {
self.requires_unsafe(expr.span, CallToUnsafeFunction);
} else if let &ty::FnDef(func_did, _) = self.thir[fun].ty.kind() {
Copy link
Contributor

Choose a reason for hiding this comment

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

as far as I know, target features 1.1 is not stable #69098 -- is this instability enforced at the declaration site? I guess probably so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the check is here:

if !tcx.features().target_feature_11 {
let mut err = feature_err(
&tcx.sess.parse_sess,
sym::target_feature_11,
attr.span,
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
);
err.span_label(tcx.def_span(id), "not an `unsafe` function");
err.emit();

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 21, 2021

📌 Commit d7787bb has been approved by nikomatsakis

@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 May 21, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 21, 2021
…komatsakis

Add DerefOfRawPointer and CallToFunctionWith to THIR unsafeck

Extends THIR unsafeck to check for two more cases of unsafe operations: dereferences of raw pointers and calls to functions with `#[target_feature]` (RFC 2396). The check for the latter is pretty much copy-pasted from the existing MIR equivalent.

This will clash with rust-lang#83842 and rust-lang#85273 which are arguably more important, let's maybe focus on getting those merged first, this can wait.
r? `@nikomatsakis`
cc rust-lang/project-thir-unsafeck#7
@LeSeulArtichaut LeSeulArtichaut deleted the thir-unsafeck branch May 21, 2021 16:24
@LeSeulArtichaut
Copy link
Contributor Author

Whoops

@LeSeulArtichaut LeSeulArtichaut restored the thir-unsafeck branch May 21, 2021 16:26
@LeSeulArtichaut LeSeulArtichaut deleted the thir-unsafeck branch May 21, 2021 16:26
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 21, 2021
…komatsakis

Check for more things in THIR unsafeck

Reunion of rust-lang#85306, rust-lang#85381 and rust-lang#85419 with conflicts resolved.
r? `@nikomatsakis`
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants