[llvm] 6e57f68 - [AVR] Reject invalid LDD instruction with explicit error

Ben Shi via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 9 19:34:55 PDT 2023


Author: Ben Shi
Date: 2023-04-10T10:34:45+08:00
New Revision: 6e57f68e41c92936b9ef3a4e6fb286e8805a9fbc

URL: https://github.com/llvm/llvm-project/commit/6e57f68e41c92936b9ef3a4e6fb286e8805a9fbc
DIFF: https://github.com/llvm/llvm-project/commit/6e57f68e41c92936b9ef3a4e6fb286e8805a9fbc.diff

LOG: [AVR] Reject invalid LDD instruction with explicit error

We should reject "ldd Rn, X" with explicit error message
rather than "llvm_unreachable" in llvm's release build.

Fixes https://github.com/llvm/llvm-project/issues/62012

Reviewed By: Miss_Grape

Differential Revision: https://reviews.llvm.org/D147877

Added: 
    

Modified: 
    llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
    llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
index c8bb410e48829..9edd8bb0d10f6 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
@@ -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
@@ -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;

diff  --git a/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll b/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll
index 98b0709fcc3e0..8d27c54392d90 100644
--- a/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll
+++ b/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll
@@ -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}'
@@ -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
+}


        


More information about the llvm-commits mailing list