[clang] [compiler-rt] [llvm] [HIP] support 128 bit int division (PR #71978)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 5 07:38:09 PST 2023


================
@@ -937,27 +938,105 @@ bool CodeGenAction::loadLinkModules(CompilerInstance &CI) {
 
   for (const CodeGenOptions::BitcodeFileToLink &F :
        CI.getCodeGenOpts().LinkBitcodeFiles) {
-    auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename);
-    if (!BCBuf) {
+
+    auto BCBufOrErr = CI.getFileManager().getBufferForFile(F.Filename);
+    if (!BCBufOrErr) {
       CI.getDiagnostics().Report(diag::err_cannot_open_file)
-          << F.Filename << BCBuf.getError().message();
+          << F.Filename << BCBufOrErr.getError().message();
       LinkModules.clear();
       return true;
     }
 
+    auto &BCBuf = *BCBufOrErr;
+
     Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
-        getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
-    if (!ModuleOrErr) {
-      handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
+        getOwningLazyBitcodeModule(std::move(BCBuf), *VMContext);
+
+    if (ModuleOrErr) {
+      LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
+                             F.Internalize, F.LinkFlags});
+      continue;
+    } else {
+      // If parsing as bitcode failed, clear the error and try to parse as an
+      // archive.
+      handleAllErrors(ModuleOrErr.takeError(),
+                      [&](const llvm::ErrorInfoBase &EIB) {});
+
+      Expected<std::unique_ptr<llvm::object::Binary>> BinOrErr =
+          llvm::object::createBinary(BCBuf->getMemBufferRef(), VMContext);
+
+      if (!BinOrErr) {
+        handleAllErrors(BinOrErr.takeError(),
+                        [&](const llvm::ErrorInfoBase &EIB) {
+                          CI.getDiagnostics().Report(diag::err_cannot_open_file)
+                              << F.Filename << EIB.message();
+                        });
+        LinkModules.clear();
+        return true;
+      }
+
+      std::unique_ptr<llvm::object::Binary> &Bin = *BinOrErr;
+
+      if (Bin->isArchive()) {
----------------
yxsamliu wrote:

will do

https://github.com/llvm/llvm-project/pull/71978


More information about the cfe-commits mailing list