Skip to content

Prevent ICE in autodiff validation by emitting user-friendly errors #138231

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

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Changes from 1 commit
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
Next Next commit
Prevent ICE in autodiff validation by emitting user-friendly errors
  • Loading branch information
Sa4dUs committed Mar 2, 2025
commit 6b29bb6680e0df3bbcd8e9defdf0ad142e80cdf0
10 changes: 8 additions & 2 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,19 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
}
}

// Validate input and return activities
let mut msg = "".to_string();
for &input in &arg_activities {
if !valid_input_activity(mode, input) {
span_bug!(attr.span(), "Invalid input activity {} for {} mode", input, mode);
msg = format!("Invalid input activity {} for {} mode", input, mode);
}
}
if !valid_ret_activity(mode, ret_activity) {
span_bug!(attr.span(), "Invalid return activity {} for {} mode", ret_activity, mode);
msg = format!("Invalid return activity {} for {} mode", ret_activity, mode);
}
if msg != "".to_string() {
tcx.dcx().struct_span_err(attr.span(), msg).with_note("invalid activity").emit();
return Some(AutoDiffAttrs::error());
}

Some(AutoDiffAttrs { mode, ret_activity, input_activity: arg_activities })
Expand Down
Loading