Skip to content

Commit

Permalink
[AVR] Reject invalid LDD instruction with explicit error
Browse files Browse the repository at this point in the history
We should reject "ldd Rn, X" with explicit error message
rather than "llvm_unreachable" in llvm's release build.

Fixes #62012

Reviewed By: Miss_Grape

Differential Revision: https://reviews.llvm.org/D147877
  • Loading branch information
benshi001 committed Apr 10, 2023
1 parent a3d5ec5 commit 6e57f68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ unsigned AVRMCCodeEmitter::encodeMemri(const MCInst &MI, unsigned OpNo,

switch (RegOp.getReg()) {
default:
llvm_unreachable("Expected either Y or Z register");
Ctx.reportError(MI.getLoc(), "Expected either Y or Z register");
return 0;
case AVR::R31R30:
RegBit = 0;
break; // Z register
Expand All @@ -164,7 +165,7 @@ unsigned AVRMCCodeEmitter::encodeMemri(const MCInst &MI, unsigned OpNo,
Fixups.push_back(MCFixup::create(0, OffsetOp.getExpr(),
MCFixupKind(AVR::fixup_6), MI.getLoc()));
} else {
llvm_unreachable("invalid value for offset");
llvm_unreachable("Invalid value for offset");
}

return (RegBit << 6) | OffsetBits;
Expand Down
9 changes: 8 additions & 1 deletion llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llc < %s -march=avr -no-integrated-as 2>&1 | FileCheck %s
; RUN: not llc < %s -march=avr -mcpu=avr6 -filetype=obj -no-integrated-as 2>&1 \
; RUN: | FileCheck %s

define void @foo(i16 %a) {
; CHECK: error: invalid operand in inline asm: 'jl ${0:l}'
Expand All @@ -13,3 +14,9 @@ define void @foo1() {
call i16 asm sideeffect ";; ${0:C}", "=d"()
ret void
}

define void @foo2() {
; CHECK: error: expected either Y or Z register
call void asm sideeffect "ldd r24, X+2", ""()
ret void
}

0 comments on commit 6e57f68

Please sign in to comment.