[PATCH] D85469: [CodeGen] Check the number of operands before accessing the first one

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 12:51:02 PDT 2020


phosek created this revision.
phosek added reviewers: MaskRay, pcc.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
phosek requested review of this revision.

After D72899 <https://reviews.llvm.org/D72899>, it's possible to use empty associated symbol which will
get lowered to sh_link set to 0. However, if the operand is missing
altogether, getLinkedToSymbol is going to fail. Avoid the failure
by checking the number of arguments first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85469

Files:
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp


Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -534,6 +534,9 @@
   if (!MD)
     return nullptr;
 
+  if (!MD->getNumOperands())
+    return nullptr;
+
   const MDOperand &Op = MD->getOperand(0);
   if (!Op.get())
     return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85469.283708.patch
Type: text/x-patch
Size: 424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200806/f42f5181/attachment-0001.bin>


More information about the llvm-commits mailing list