diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -377,6 +377,8 @@ /// @name AuxTarget Info /// { + bool hasAuxTarget() const { return AuxTarget != nullptr; } + TargetInfo *getAuxTarget() const { return AuxTarget.get(); } /// Replace the current AuxTarget. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -104,8 +104,10 @@ if (!hasTarget()) return false; - // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation. - if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice || + // Check whether AuxTarget exists, if not, then create TargetInfo for the + // other side of CUDA/OpenMP/SYCL compilation. + if (!hasAuxTarget() && + (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice || getLangOpts().SYCLIsDevice) && !getFrontendOpts().AuxTriple.empty()) { auto TO = std::make_shared();