[clang] Check AuxTarget exists when creating target in CompilerInstance
authoroToToT <ty1208chiang@gmail.com>
Wed, 7 Apr 2021 12:58:48 +0000 (20:58 +0800)
committeroToToT <ty1208chiang@gmail.com>
Wed, 7 Apr 2021 12:58:48 +0000 (20:58 +0800)
D97493 separate target creation out to a single function
`CompilerInstance::createTarget`. However, it would overwrite AuxTarget
even if it has been set.
As @kadircet recommended in D98128, this patch check the existence of
AuxTarget and not overwrite it when it has been set.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D100024

clang/lib/Frontend/CompilerInstance.cpp

index b2ec18d..b76baae 100644 (file)
@@ -104,8 +104,10 @@ bool CompilerInstance::createTarget() {
   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 (!getAuxTarget() &&
+      (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
        getLangOpts().SYCLIsDevice) &&
       !getFrontendOpts().AuxTriple.empty()) {
     auto TO = std::make_shared<TargetOptions>();