[llvm] [ms] [llvm-ml] Allow PTR casting of registers to their own size (PR #132751)
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 24 14:58:14 PDT 2025
================
@@ -2601,9 +2631,20 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
return Error(Start, "rip can only be used as a base register");
// A Register followed by ':' is considered a segment override
if (Tok.isNot(AsmToken::Colon)) {
- if (PtrInOperand)
- return Error(Start, "expected memory operand after 'ptr', "
- "found register operand instead");
+ if (PtrInOperand) {
+ if (!Parser.isParsingMasm())
+ return Error(Start, "expected memory operand after 'ptr', "
+ "found register operand instead");
+
+ // If we are parsing MASM, we are allowed to cast registers to their own
+ // sizes, but not to other types.
+ if (RegSizeInBits(*getContext().getRegisterInfo(), RegNo) != Size)
+ return Error(
+ Start,
+ "cannot cast register '" +
+ StringRef(getContext().getRegisterInfo()->getName(RegNo)) +
+ "' to '" + SizeStr + "'; size does not match");
----------------
compnerd wrote:
I wonder if the size class in the diagnostic message is helpful. I don't think that
```
cannot cast register 'AL' to 'word'; size does not match
```
is particularly helpful. Perhaps something more along the lines of:
```
8-bit GPR 'AX' cannot be used as a 32-bit GPR
```
https://github.com/llvm/llvm-project/pull/132751
More information about the llvm-commits
mailing list