Skip to content

Commit 1bfad01

Browse files
committed
fix rtsan_nonblocking_async lint closure ICE
1 parent 2636cb4 commit 1bfad01

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,18 @@ fn check_result(
468468
})
469469
}
470470

471-
// warn for nonblocking async fn.
471+
// warn for nonblocking async functions, blocks and closures.
472472
// This doesn't behave as expected, because the executor can run blocking code without the sanitizer noticing.
473473
if codegen_fn_attrs.sanitizers.rtsan_setting == RtsanSetting::Nonblocking
474474
&& let Some(sanitize_span) = interesting_spans.sanitize
475-
// async function
476-
&& (tcx.asyncness(did).is_async() || (tcx.is_closure_like(did.into())
475+
// async fn
476+
&& (tcx.asyncness(did).is_async()
477477
// async block
478-
&& (tcx.coroutine_is_async(did.into())
479-
// async closure
480-
|| tcx.coroutine_is_async(tcx.coroutine_for_closure(did)))))
478+
|| tcx.is_coroutine(did.into())
479+
// async closure
480+
|| (tcx.is_closure_like(did.into())
481+
&& tcx.hir_node_by_def_id(did).expect_closure().kind
482+
!= rustc_hir::ClosureKind::Closure))
481483
{
482484
let hir_id = tcx.local_def_id_to_hir_id(did);
483485
tcx.node_span_lint(

tests/ui/sanitize-attr/invalid-sanitize.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ fn test() {
3737
#[sanitize(realtime = "nonblocking")] //~ WARN: the async executor can run blocking code, without realtime sanitizer catching it [rtsan_nonblocking_async]
3838
async || {}
3939
};
40+
41+
let _regular_closure = {
42+
#[sanitize(realtime = "nonblocking")] // no warning on a regular closure
43+
|| 0
44+
};
4045
}

0 commit comments

Comments
 (0)