llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nuri Amari (NuriAmari)

<details>
<summary>Changes</summary>

Prior to this patch, when using -fthinlto-index= the ObjCARCContractPass isn't 
run prior to CodeGen, and instruction selection fails on IR containing arc 
intrinsics.

The pass would normally be added here: 
https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1352
 Since because we are using an index file, we return early above after 
`runThinLTOBackend`:
https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1333-L1339


---
Full diff: https://github.com/llvm/llvm-project/pull/92331.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+3) 
- (added) clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll (+19) 


``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 90985c08fe7f8..03dd1df281d80 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1289,6 +1289,9 @@ static void runThinLTOBackend(
     };
     break;
   default:
+    Conf.PreCodeGenPassesHook = [](legacy::PassManager &Pm) {
+      Pm.add(createObjCARCContractPass());
+    };
     Conf.CGFileType = getCodeGenFileType(Action);
     break;
   }
diff --git a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll 
b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
new file mode 100644
index 0000000000000..7d0247555b5c8
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
@@ -0,0 +1,19 @@
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,_use_arc,px
+
+; RUN: %clang_cc1 -triple x86_64-apple-darwin \
+; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+; RUN:   -o %t.native.o -x ir %t.o
+
+target datalayout = 
"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-darwin"
+
+define void @use_arc(ptr %a, ptr %b) {
+  call void (...) @llvm.objc.clang.arc.use(i8* %a, i8* %b) nounwind
+  ret void
+}
+
+declare void @llvm.objc.clang.arc.use(...) nounwind

``````````

</details>


https://github.com/llvm/llvm-project/pull/92331
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to