From: Michael Liao Date: Thu, 10 Oct 2019 23:05:55 +0000 (+0000) Subject: [tooling] Teach Tooling to understand compilation with offloading. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9813c50f79f295648a22b74d4836aef34ce95dff;p=clang [tooling] Teach Tooling to understand compilation with offloading. Summary: - So far, we only recognize the host compilation with offloading and skip the offloading part. Reviewers: tra, yaxunl Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68660 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374470 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 0aae490609..254cc8b7e8 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -91,7 +91,29 @@ static const llvm::opt::ArgStringList *getCC1Arguments( // We expect to get back exactly one Command job, if we didn't something // failed. Extract that job from the Compilation. const driver::JobList &Jobs = Compilation->getJobs(); - if (Jobs.size() != 1 || !isa(*Jobs.begin())) { + const driver::ActionList &Actions = Compilation->getActions(); + bool OffloadCompilation = false; + if (Jobs.size() > 1) { + for (auto A : Actions){ + // On MacOSX real actions may end up being wrapped in BindArchAction + if (isa(A)) + A = *A->input_begin(); + if (isa(A)) { + // Offload compilation has 2 top-level actions, one (at the front) is + // the original host compilation and the other is offload action + // composed of at least one device compilation. For such case, general + // tooling will consider host-compilation only. For tooling on device + // compilation, device compilation only option, such as + // `--cuda-device-only`, needs specifying. + assert(Actions.size() == 2); + assert(isa(Actions.front())); + OffloadCompilation = true; + break; + } + } + } + if (Jobs.size() == 0 || !isa(*Jobs.begin()) || + (Jobs.size() > 1 && !OffloadCompilation)) { SmallString<256> error_msg; llvm::raw_svector_ostream error_stream(error_msg); Jobs.Print(error_stream, "; ", true); diff --git a/test/Tooling/clang-check-offload.cpp b/test/Tooling/clang-check-offload.cpp new file mode 100644 index 0000000000..154bc04311 --- /dev/null +++ b/test/Tooling/clang-check-offload.cpp @@ -0,0 +1,4 @@ +// RUN: not clang-check "%s" -- -c -x hip -nogpulib 2>&1 | FileCheck %s + +// CHECK: C++ requires +invalid;