[llvm] [TableGen] Fix a potential crash when operand doesn't appear in the instruction pattern (PR #87663)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 12:54:33 PDT 2024


https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/87663

>From 1441265b8e5cf06317ceedd0f9affe138f0ee10e Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Thu, 4 Apr 2024 15:54:23 -0400
Subject: [PATCH] [TableGen] Fix a potential crash when operand doesn't appear
 in the instruction pattern

We have a check of whether an operand is in the instruction pattern, and emit an
error if it is not, but we simply continue execution, including directly
dereferencing a point-like object `InVal`, which will be just created when
accessing the map. It contains a `nullptr` so dereferencing it causes crash.
This is a very trivial fix.
---
 llvm/lib/Target/AMDGPU/VOP3PInstructions.td       | 4 ++--
 llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/VOP3PInstructions.td b/llvm/lib/Target/AMDGPU/VOP3PInstructions.td
index a7d63fdb2e04c8..c929506601c067 100644
--- a/llvm/lib/Target/AMDGPU/VOP3PInstructions.td
+++ b/llvm/lib/Target/AMDGPU/VOP3PInstructions.td
@@ -564,9 +564,9 @@ class VOPProfileSMFMAC<VOPProfile P, RegisterOperand _DstRC,
   : VOPProfileMAI<P, _DstRC, _DstRC, _SrcARC> {
   let Src1RC64 = _SrcBRC;
   let Src2VT = DstVT;
-  let Asm64 = " $vdst, $src0, $src1, $idx$cbsz$abid";
+  let Asm64 = " $vdst, $src0, $src1, $idx$cbsz$abid$clamp";
   let Outs64 = (outs DstRC:$vdst);
-  let Ins64 = (ins Src0RC64:$src0, Src1RC64:$src1, VRegSrc_32:$idx, CBSZ:$cbsz, ABID:$abid, Src2RC64:$src2);
+  let Ins64 = (ins Src0RC64:$src0, Src1RC64:$src1, VRegSrc_32:$idx, CBSZ:$cbsz, ABID:$abid, clampmod:$clamp, Src2RC64:$src2);
 }
 
 def VOPProfileMAI_F32_F32_X4    : VOPProfileMAI<VOP_V4F32_F32_F32_V4F32,       AISrc_128_f32,  ADst_128>;
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 076d0427a85971..61402615d9316c 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -3872,6 +3872,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
       }
       I.error("Operand $" + OpName +
               " does not appear in the instruction pattern");
+      continue;
     }
     TreePatternNodePtr InVal = InstInputs[OpName];
     InstInputs.erase(OpName); // It occurred, remove from map.



More information about the llvm-commits mailing list