[PATCH] D152372: change checking for auto-init metadata to use `equalsStr` instead of casing MDOperand nodes.

Zain Jaffal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 07:11:58 PDT 2023


zjaffal created this revision.
zjaffal added reviewers: serge-sans-paille, nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
zjaffal requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Since `MD_annotation` metadata now supports having mutliple strings in the annotation node. casing Operand to string directly will cause a crash. When checking if `MDOperand` equals str you can use `equalsStr` method.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152372

Files:
  llvm/lib/Transforms/Utils/MoveAutoInit.cpp


Index: llvm/lib/Transforms/Utils/MoveAutoInit.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MoveAutoInit.cpp
+++ llvm/lib/Transforms/Utils/MoveAutoInit.cpp
@@ -40,9 +40,7 @@
 static bool hasAutoInitMetadata(const Instruction &I) {
   return I.hasMetadata(LLVMContext::MD_annotation) &&
          any_of(I.getMetadata(LLVMContext::MD_annotation)->operands(),
-                [](const MDOperand &Op) {
-                  return cast<MDString>(Op.get())->getString() == "auto-init";
-                });
+                [](const MDOperand &Op) { return Op.equalsStr("auto-init"); });
 }
 
 static std::optional<MemoryLocation> writeToAlloca(const Instruction &I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152372.529291.patch
Type: text/x-patch
Size: 720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/d3a6f3ed/attachment.bin>


More information about the llvm-commits mailing list