Index: clang/test/Driver/clang-offload-bundler.c =================================================================== --- clang/test/Driver/clang-offload-bundler.c +++ clang/test/Driver/clang-offload-bundler.c @@ -183,6 +183,10 @@ // RUN: diff %t.empty %t.res.tgt1 // RUN: diff %t.empty %t.res.tgt2 +// Check that we can extract target parts without providing host triple. +// RUN: clang-offload-bundler -type=s -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.s -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 + // // Check binary bundle/unbundle. The content that we have before bundling must be the same we have after unbundling. // @@ -221,6 +225,10 @@ // RUN: diff %t.empty %t.res.tgt1 // RUN: diff %t.empty %t.res.tgt2 +// Check that we can extract target parts without providing host triple. +// RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.unordered.ast -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 + // // Check object bundle/unbundle. The content should be bundled into an ELF // section (we are using a PowerPC little-endian host which uses ELF). We @@ -256,6 +264,10 @@ // RUN: diff %t.empty %t.res.tgt1 // RUN: diff %t.empty %t.res.tgt2 +// Check that we can extract target parts without providing host triple. +// RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.o -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 + // Some code so that we can create a binary out of this file. int A = 0; void test_func(void) { Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp =================================================================== --- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -833,7 +833,6 @@ // Read all the bundles that are in the work list. If we find no bundles we // assume the file is meant for the host target. - bool FoundHostBundle = false; while (!Worklist.empty()) { StringRef CurTriple = FH.get()->ReadBundleStart(Input); @@ -859,10 +858,6 @@ FH.get()->ReadBundle(OutputFile, Input); FH.get()->ReadBundleEnd(Input); Worklist.erase(Output); - - // Record if we found the host bundle. - if (hasHostKind(CurTriple)) - FoundHostBundle = true; } // If no bundles were found, assume the input file is the host bundle and @@ -884,12 +879,6 @@ return false; } - // If we found elements, we emit an error if none of those were for the host. - if (!FoundHostBundle) { - errs() << "error: Can't find bundle for the host target\n"; - return true; - } - // If we still have any elements in the worklist, create empty files for them. for (auto &E : Worklist) { std::error_code EC; @@ -988,7 +977,9 @@ ++Index; } - if (HostTargetNum != 1) { + // Host triple is not really needed for unbundling operation, so do not + // treat missing host triple as error if we do unbundling. + if ((Unbundle && HostTargetNum > 1) || (!Unbundle && HostTargetNum != 1)) { Error = true; errs() << "error: expecting exactly one host target but got " << HostTargetNum << ".\n";