[PATCH] D137360: [Linker] Remove nocallback attribute while linking

Gulfem Savrun Yeniceri via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 20:44:04 PST 2022


gulfem updated this revision to Diff 482700.
gulfem added a comment.

1. Drop memory(inaccessiblemem) attributes as well, and added test cases for them
2. Added a test case for testing intrinsics
3. Added a test case for a nocallback declaration without a definition being linked in


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137360/new/

https://reviews.llvm.org/D137360

Files:
  llvm/lib/Linker/LinkModules.cpp
  llvm/test/Linker/Inputs/drop-attribute.ll
  llvm/test/Linker/drop-attribute.ll


Index: llvm/test/Linker/drop-attribute.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/drop-attribute.ll
@@ -0,0 +1,37 @@
+; RUN: llvm-link %s %p/Inputs/drop-attribute.ll -S -o - | FileCheck %s
+
+; Test case that checks that memory(inaccessiblemem) and nocallback attributes are dropped during linking.
+
+; CHECK: define i32 @main()
+define i32 @main() {
+entry:
+  call void @test_inaccessiblemem_read()
+  call void @test_inaccessiblemem_write()
+  call void @test_inaccessiblemem_readwrite()
+  call float @llvm.sqrt.f32(float undef)
+  call void @test_nocallback_declaration_definition_not_linked_in()
+  call void @test_nocallback_declaration_definition_linked_in()
+  ret i32 0
+}
+
+; CHECK: declare void @test_inaccessiblemem_read(){{$}}
+declare void @test_inaccessiblemem_read() memory(inaccessiblemem: read)
+
+; CHECK: declare void @test_inaccessiblemem_write(){{$}}
+declare void @test_inaccessiblemem_write() memory(inaccessiblemem: write)
+
+; CHECK: declare void @test_inaccessiblemem_readwrite(){{$}}
+declare void @test_inaccessiblemem_readwrite() memory(inaccessiblemem: readwrite)
+
+; CHECK: ; Function Attrs: nofree nosync nounwind speculatable willreturn
+; CHECK-NEXT: declare float @llvm.sqrt.f32(float) #0
+declare float @llvm.sqrt.f32(float) nocallback
+
+; CHECK: declare void @test_nocallback_declaration_definition_not_linked_in(){{$}}
+declare void @test_nocallback_declaration_definition_not_linked_in() nocallback
+
+declare void @test_nocallback_declaration_definition_linked_in() nocallback
+
+; CHECK: define void @test_nocallback_declaration_definition_linked_in()
+; CHECK: entry:
+; CHECK-NEXT: ret void
Index: llvm/test/Linker/Inputs/drop-attribute.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/Inputs/drop-attribute.ll
@@ -0,0 +1,4 @@
+define void @test_nocallback_declaration_definition_linked_in() {
+entry:
+  ret void
+}
Index: llvm/lib/Linker/LinkModules.cpp
===================================================================
--- llvm/lib/Linker/LinkModules.cpp
+++ llvm/lib/Linker/LinkModules.cpp
@@ -379,8 +379,20 @@
        GV.hasAvailableExternallyLinkage()))
     return false;
 
-  if (GV.isDeclaration())
+  // Drop memory (inaccessiblemem) and nocallback attributes while linking
+  // because they are only valid on the module level.
+  // - memory (inaccessiblemem) function attributes are generated internally per
+  // module semantics.
+  // - nocallback function attribute is treated as a hint on the module level.
+  if (GV.isDeclaration()) {
+    if (auto *F = dyn_cast<Function>(&GV)) {
+      if (!F->doesNotAccessMemory() && F->onlyAccessesInaccessibleMemory())
+        F->removeFnAttr(llvm::Attribute::Memory);
+      if (F->hasFnAttribute(llvm::Attribute::NoCallback))
+        F->removeFnAttr(llvm::Attribute::NoCallback);
+    }
     return false;
+  }
 
   LinkFrom ComdatFrom = LinkFrom::Dst;
   if (const Comdat *SC = GV.getComdat()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137360.482700.patch
Type: text/x-patch
Size: 3030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221214/f76f4843/attachment.bin>


More information about the llvm-commits mailing list