From 159e2a804d908edc92966f0485881eb78778c92d Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 12 Jan 2023 17:21:55 +0800 Subject: [PATCH] [AVR] Fix a bug in AsmPrinter when printing inline-asm operands Fixes https://github.com/llvm/llvm-project/issues/58878 Reviewed By: aykevl, Miss_Grape Differential Revision: https://reviews.llvm.org/D141589 --- llvm/lib/Target/AVR/AVRAsmPrinter.cpp | 4 ++-- llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp index 897a45e..61f39c5 100644 --- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp +++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp @@ -128,8 +128,8 @@ bool AVRAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, assert(BytesPerReg <= 2 && "Only 8 and 16 bit regs are supported."); unsigned RegIdx = ByteNumber / BytesPerReg; - assert(RegIdx < NumOpRegs && "Multibyte index out of range."); - + if (RegIdx >= NumOpRegs) + return true; Reg = MI->getOperand(OpNum + RegIdx).getReg(); if (BytesPerReg == 2) { 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 8a3dcfc..98b0709 100644 --- a/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll +++ b/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll @@ -8,3 +8,8 @@ define void @foo(i16 %a) { ret void } +define void @foo1() { + ; CHECK: error: invalid operand in inline asm: ';; ${0:C}' + call i16 asm sideeffect ";; ${0:C}", "=d"() + ret void +} -- 2.7.4