[llvm] 711bf7d - [Attributor][FIX] Don't crash on internalizing linkonce_odr hidden functions

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 21:41:02 PDT 2020


Author: Johannes Doerfert
Date: 2020-09-07T23:38:09-05:00
New Revision: 711bf7dcf9546fefe18d32a5772d48e7b5166f08

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

LOG: [Attributor][FIX] Don't crash on internalizing linkonce_odr hidden functions

The CloneFunctionInto has implicit requirements with regards to the
linkage and visibility of the function. We now update these after we did
the CloneFunctionInto on the copy with the same linkage and visibility
as the original.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/test/Transforms/Attributor/internalize.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index ac9b48a53763..32420e847129 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1481,9 +1481,8 @@ static Function *internalizeFunction(Function &F) {
   FunctionType *FnTy = F.getFunctionType();
 
   // create a copy of the current function
-  Function *Copied =
-      Function::Create(FnTy, GlobalValue::PrivateLinkage, F.getAddressSpace(),
-                       F.getName() + ".internalized");
+  Function *Copied = Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(),
+                                      F.getName() + ".internalized");
   ValueToValueMapTy VMap;
   auto *NewFArgIt = Copied->arg_begin();
   for (auto &Arg : F.args()) {
@@ -1496,6 +1495,11 @@ static Function *internalizeFunction(Function &F) {
   // Copy the body of the original function to the new one
   CloneFunctionInto(Copied, &F, VMap, /* ModuleLevelChanges */ false, Returns);
 
+  // Set the linakage and visibility late as CloneFunctionInto has some implicit
+  // requirements.
+  Copied->setVisibility(GlobalValue::DefaultVisibility);
+  Copied->setLinkage(GlobalValue::PrivateLinkage);
+
   // Copy metadata
   SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
   F.getAllMetadata(MDs);

diff  --git a/llvm/test/Transforms/Attributor/internalize.ll b/llvm/test/Transforms/Attributor/internalize.ll
index 25f16474e834..3e485382e9be 100644
--- a/llvm/test/Transforms/Attributor/internalize.ll
+++ b/llvm/test/Transforms/Attributor/internalize.ll
@@ -148,3 +148,14 @@ define void @unused_arg_caller() {
   call void @unused_arg(i8 0)
   ret void
 }
+
+; Don't crash on linkonce_odr hidden functions
+define linkonce_odr hidden void @__clang_call_terminate() {
+; CHECK_DISABLED-LABEL: define {{[^@]+}}@__clang_call_terminate() {
+; CHECK_DISABLED-NEXT:    call void @__clang_call_terminate()
+; CHECK_DISABLED-NEXT:    unreachable
+;
+  call void @__clang_call_terminate()
+  unreachable
+}
+


        


More information about the llvm-commits mailing list