diff options
Diffstat (limited to 'llvm/lib/Transforms/IPO/MergeFunctions.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/MergeFunctions.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp index c19cf71..c8c011d 100644 --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -662,6 +662,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); + } +} + // Replace G with a simple tail call to bitcast(F). Also (unless // MergeFunctionsPDI holds) replace direct uses of G with bitcast(F), // delete G. Under MergeFunctionsPDI, we use G itself for creating @@ -740,6 +747,9 @@ void MergeFunctions::writeThunk(Function *F, Function *G) { } else { NewG->copyAttributesFrom(G); NewG->takeName(G); + // Ensure CFI type metadata is propagated to the new function. + copyMetadataIfPresent(G, NewG, "type"); + copyMetadataIfPresent(G, NewG, "kcfi_type"); removeUsers(G); G->replaceAllUsesWith(NewG); G->eraseFromParent(); @@ -815,6 +825,9 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) { F->getAddressSpace(), "", F->getParent()); NewF->copyAttributesFrom(F); NewF->takeName(F); + // Ensure CFI type metadata is propagated to the new function. + copyMetadataIfPresent(F, NewF, "type"); + copyMetadataIfPresent(F, NewF, "kcfi_type"); removeUsers(F); F->replaceAllUsesWith(NewF); |