aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/MergeFunctions.cpp
diff options
context:
space:
mode:
authorOskar Wirga <oskar.wirga@gmail.com>2024-04-10 15:37:27 -0700
committerGitHub <noreply@github.com>2024-04-10 15:37:27 -0700
commita9d4ddd98a0bc495126027122fdca751b6841ceb (patch)
treeff9feb6411d442e0d83bee882fca741e2dd4ae55 /llvm/lib/Transforms/IPO/MergeFunctions.cpp
parentd8f1e5d2894f7f4edc2e85e63def456c7f430f34 (diff)
downloadllvm-a9d4ddd98a0bc495126027122fdca751b6841ceb.zip
llvm-a9d4ddd98a0bc495126027122fdca751b6841ceb.tar.gz
llvm-a9d4ddd98a0bc495126027122fdca751b6841ceb.tar.bz2
[MergeFuncs/CFI] Ensure all type metadata is propogated for CFI (#88218)
I noticed that we weren't propagating ALL type metadata that was attached to CFI functions: # BEFORE ``` ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !dbg !62311 !type !34028 !type !34029 !type !34030 ... fn merging ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !type !34028 ``` # AFTER ``` ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !dbg !62311 !type !34028 !type !34029 !type !34030 ... fn merging ; Function Attrs: minsize nounwind optsize ssp uwtable(sync) define internal void @foo(ptr nocapture noundef readonly %0) #0 !type !type !34028 !type !34029 !type !34030 ``` This patch makes sure that the entire vector of metadata is copied over.
Diffstat (limited to 'llvm/lib/Transforms/IPO/MergeFunctions.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index 05a3b16..b50a700 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -712,11 +712,13 @@ static bool canCreateThunkFor(Function *F) {
return true;
}
-/// Copy metadata from one function to another.
-static void copyMetadataIfPresent(Function *From, Function *To, StringRef Key) {
- if (MDNode *MD = From->getMetadata(Key)) {
- To->setMetadata(Key, MD);
- }
+/// Copy all metadata of a specific kind from one function to another.
+static void copyMetadataIfPresent(Function *From, Function *To,
+ StringRef Kind) {
+ SmallVector<MDNode *, 4> MDs;
+ From->getMetadata(Kind, MDs);
+ for (MDNode *MD : MDs)
+ To->addMetadata(Kind, *MD);
}
// Replace G with a simple tail call to bitcast(F). Also (unless