Skip to content

Preserve explicit register names in inline asm diagnostics - #160068

Open
qaijuang wants to merge 2 commits into
rust-lang:mainfrom
qaijuang:fix-asm-register-alias-diagnostic
Open

qaijuang wants to merge 2 commits into
rust-lang:mainfrom
qaijuang:fix-asm-register-alias-diagnostic

Conversation

@qaijuang

@qaijuang qaijuang commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This PR adds diagnostic-only metadata directly to each register-bearing HIR operand, and replaces #117912 AST lookup with the new HIR metadata.

Fixes #159409

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@qaijuang
qaijuang marked this pull request as ready for review July 28, 2026 13:17
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 28, 2026
@qaijuang
qaijuang force-pushed the fix-asm-register-alias-diagnostic branch from 77c0f58 to d33866e Compare July 28, 2026 13:47

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_ => None,
};
let reg_str = |idx| -> &str {
// HIR asm doesn't preserve the original alias string of the explicit register,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason it shouldn't, instead of this scheme of re-adding it in metadata?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't see or find any reason why it shouldn't

@workingjubilee workingjubilee Aug 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May I see how the PR looks like in that form instead, then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be duplicating the InlineAsmRegOrRegClass type and impl in HiR, is it acceptable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The exact HiR impl

/// Stores explicit register name from source
/// for diagnostics only.
#[derive(Debug, Clone, Copy, StableHash)]
pub enum InlineAsmRegOrRegClass {
    Reg { reg: asm::InlineAsmReg, source_name: Option<Symbol> },
    RegClass(asm::InlineAsmRegClass),
}

impl InlineAsmRegOrRegClass {
    // For `rustc_mir_build` and `clippy_utils`
    pub fn as_target(self) -> asm::InlineAsmRegOrRegClass {
        match self {
            Self::Reg { reg, .. } => asm::InlineAsmRegOrRegClass::Reg(reg),
            Self::RegClass(reg_class) => asm::InlineAsmRegOrRegClass::RegClass(reg_class),
        }
    }

    // For `rustc_ast_lowering`
    pub fn reg_class(self) -> asm::InlineAsmRegClass {
        self.as_target().reg_class()
    }

    // For `rustc_ast_lowering`
    pub fn source_name(self) -> Option<Symbol> {
        match self {
            Self::Reg { source_name, .. } => source_name,
            Self::RegClass(_) => None,
        }
    }
}

// For `rustc_hir_pretty`
impl fmt::Display for InlineAsmRegOrRegClass {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.as_target().fmt(f)
    }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either variants seems fine to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@workingjubilee let me know the direction we are taking.

@qaijuang

qaijuang commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@hanna-kruppe

Copy link
Copy Markdown
Contributor

@rustbot reroll

@qaijuang

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned mu001999 and unassigned dingxiangfei2009 Sep 16, 2026
@mu001999

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned chenyukang and unassigned mu001999 Sep 16, 2026
@chenyukang

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned jieyouxu and unassigned chenyukang Sep 16, 2026
@Amanieu

Amanieu commented Sep 18, 2026

Copy link
Copy Markdown
Member

r? Amanieu

@rustbot rustbot assigned Amanieu and unassigned jieyouxu Sep 18, 2026

@Amanieu Amanieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

r=me after the minor nit is addressed

View changes since this review

Comment on lines +404 to +408
let Some(reg1_name) = op.explicit_reg_name() else {
unreachable!("{op:?} has no source register name");
};
let Some(reg2_name) = op2.explicit_reg_name() else {
unreachable!("{op2:?} has no source register name");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just use .expect here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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.

asm! xmm16-31 register usage is reported as zmm on i686 targets in diagnostic

9 participants