[llvm] [AVR] Fix compile warning AVR InstPrinter (PR #146264)
Tom Vijlbrief via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 29 03:18:34 PDT 2025
https://github.com/tomtor created https://github.com/llvm/llvm-project/pull/146264
Fix the only compile time warning for AVR (default flags):
```
/home/tom/src/rust/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp: In member function ‘void
llvm::AVRInstPrinter::printOperand(const llvm::MCInst*, unsigned int, llvm::raw_ostream&)’:
/home/tom/src/rust/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp:104:24: warning: possibly
dangling reference to a temporary [-Wdangling-reference]
104 | const MCOperandInfo &MOI = this->MII.get(MI->getOpcode()).operands()[OpNo];
| ^~~
/home/tom/src/rust/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp:104:76: note: the tempora
ry was destroyed at the end of the full expression ‘(&(&((llvm::AVRInstPrinter*)this)->llvm::AVRInstPrinter::
<anonymous>.llvm::MCInstPrinter::MII)->llvm::MCInstrInfo::get(MI->llvm::MCInst::getOpcode()))->llvm::MCInstrD
esc::operands().llvm::ArrayRef<llvm::MCOperandInfo>::operator[](((size_t)OpNo))’
104 | const MCOperandInfo &MOI = this->MII.get(MI->getOpcode()).operands()[OpNo];
| ^
```
>From af45aa3e564f5a1774e3403d16c9479136ad7ce9 Mon Sep 17 00:00:00 2001
From: Tom Vijlbrief <tvijlbrief at gmail.com>
Date: Sun, 29 Jun 2025 12:13:06 +0200
Subject: [PATCH] Fix compile warning AVR InstPrinter
---
llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
index 1e4b2e27a1837..df63b4448945e 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
@@ -100,7 +100,7 @@ const char *AVRInstPrinter::getPrettyRegisterName(MCRegister Reg,
void AVRInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O) {
- const MCOperandInfo &MOI = this->MII.get(MI->getOpcode()).operands()[OpNo];
+ const MCOperandInfo MOI = this->MII.get(MI->getOpcode()).operands()[OpNo];
if (MOI.RegClass == AVR::ZREGRegClassID) {
// Special case for the Z register, which sometimes doesn't have an operand
// in the MCInst.
More information about the llvm-commits
mailing list