Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,18 @@ fn check_result(
})
}

// warn for nonblocking async fn.
// warn for nonblocking async functions, blocks and closures.
// This doesn't behave as expected, because the executor can run blocking code without the sanitizer noticing.
if codegen_fn_attrs.sanitizers.rtsan_setting == RtsanSetting::Nonblocking
&& let Some(sanitize_span) = interesting_spans.sanitize
// async function
&& (tcx.asyncness(did).is_async() || (tcx.is_closure_like(did.into())
// async fn
&& (tcx.asyncness(did).is_async()
// async block
&& (tcx.coroutine_is_async(did.into())
// async closure
|| tcx.coroutine_is_async(tcx.coroutine_for_closure(did)))))
|| tcx.is_coroutine(did.into())
// async closure
|| (tcx.is_closure_like(did.into())
&& tcx.hir_node_by_def_id(did).expect_closure().kind
!= rustc_hir::ClosureKind::Closure))
{
let hir_id = tcx.local_def_id_to_hir_id(did);
tcx.node_span_lint(
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/sanitize-attr/invalid-sanitize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ fn test() {
#[sanitize(realtime = "nonblocking")] //~ WARN: the async executor can run blocking code, without realtime sanitizer catching it [rtsan_nonblocking_async]
async || {}
};

let _regular_closure = {
#[sanitize(realtime = "nonblocking")] // no warning on a regular closure
|| 0
};
}
Loading