[llvm] c45695e - [Metadata] Fix `addAnnotationMetadata` when appending a string tuple to an existing MDTuple.

Zain Jaffal via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 9 06:21:30 PDT 2023


Author: Zain Jaffal
Date: 2023-06-09T14:21:17+01:00
New Revision: c45695ef46570409717ca53820e1b0f0e59792a1

URL: https://github.com/llvm/llvm-project/commit/c45695ef46570409717ca53820e1b0f0e59792a1
DIFF: https://github.com/llvm/llvm-project/commit/c45695ef46570409717ca53820e1b0f0e59792a1.diff

LOG: [Metadata] Fix `addAnnotationMetadata` when appending a string tuple to an existing MDTuple.

Currently if the MD_Annotation node containd a string node when we add a
string tuple node the string will not be preserved. This change fixes
that issue.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D152448

Added: 
    

Modified: 
    llvm/lib/IR/Metadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index e2a89e2b6300b..c153ffb71a73b 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -1551,8 +1551,10 @@ void Instruction::addAnnotationMetadata(SmallVector<StringRef> Annotations) {
   if (Existing) {
     auto *Tuple = cast<MDTuple>(Existing);
     for (auto &N : Tuple->operands()) {
-      if (isa<MDString>(N.get()))
+      if (isa<MDString>(N.get())) {
+        Names.push_back(N);
         continue;
+      }
       auto *MDAnnotationTuple = cast<MDTuple>(N);
       if (any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](auto &Op) {
             return AnnotationsSet.contains(cast<MDString>(Op)->getString());


        


More information about the llvm-commits mailing list