oToToT updated this revision to Diff 325186.
oToToT added a comment.

re-upload diff with full context, sorry for that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97109/new/

https://reviews.llvm.org/D97109

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp


Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===================================================================
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -370,12 +370,33 @@
   if (!Clang->hasTarget())
     return BuildPreambleError::CouldntCreateTargetInfo;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+       Clang->getLangOpts().SYCLIsDevice) &&
+      !Clang->getFrontendOpts().AuxTriple.empty()) {
+    auto TO = std::make_shared<TargetOptions>();
+    TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+    if (Clang->getFrontendOpts().AuxTargetCPU)
+      TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+    if (Clang->getFrontendOpts().AuxTargetFeatures)
+      TO->FeaturesAsWritten =
+          Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+    TO->HostTriple = Clang->getTarget().getTriple().str();
+    Clang->setAuxTarget(
+        TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
   // Inform the target of the language options.
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
   // created. This complexity should be lifted elsewhere.
   Clang->getTarget().adjust(Clang->getLangOpts());
 
+  if (auto *Aux = Clang->getAuxTarget())
+    Clang->getTarget().setAuxTarget(Aux);
+
   if (Clang->getFrontendOpts().Inputs.size() != 1 ||
       Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
           InputKind::Source ||
Index: clang-tools-extra/clangd/Compiler.cpp
===================================================================
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -123,6 +123,33 @@
   if (!Clang->hasTarget())
     return nullptr;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+       Clang->getLangOpts().SYCLIsDevice) &&
+      !Clang->getFrontendOpts().AuxTriple.empty()) {
+    auto TO = std::make_shared<TargetOptions>();
+    TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+    if (Clang->getFrontendOpts().AuxTargetCPU)
+      TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+    if (Clang->getFrontendOpts().AuxTargetFeatures)
+      TO->FeaturesAsWritten =
+          Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+    TO->HostTriple = Clang->getTarget().getTriple().str();
+    Clang->setAuxTarget(
+        TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
+  // Inform the target of the language options.
+  //
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  Clang->getTarget().adjust(Clang->getLangOpts());
+
+  if (auto *Aux = Clang->getAuxTarget())
+    Clang->getTarget().setAuxTarget(Aux);
+
   // RemappedFileBuffers will handle the lifetime of the Buffer pointer,
   // release it.
   Buffer.release();


Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===================================================================
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -370,12 +370,33 @@
   if (!Clang->hasTarget())
     return BuildPreambleError::CouldntCreateTargetInfo;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+       Clang->getLangOpts().SYCLIsDevice) &&
+      !Clang->getFrontendOpts().AuxTriple.empty()) {
+    auto TO = std::make_shared<TargetOptions>();
+    TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+    if (Clang->getFrontendOpts().AuxTargetCPU)
+      TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+    if (Clang->getFrontendOpts().AuxTargetFeatures)
+      TO->FeaturesAsWritten =
+          Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+    TO->HostTriple = Clang->getTarget().getTriple().str();
+    Clang->setAuxTarget(
+        TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
   // Inform the target of the language options.
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
   // created. This complexity should be lifted elsewhere.
   Clang->getTarget().adjust(Clang->getLangOpts());
 
+  if (auto *Aux = Clang->getAuxTarget())
+    Clang->getTarget().setAuxTarget(Aux);
+
   if (Clang->getFrontendOpts().Inputs.size() != 1 ||
       Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
           InputKind::Source ||
Index: clang-tools-extra/clangd/Compiler.cpp
===================================================================
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -123,6 +123,33 @@
   if (!Clang->hasTarget())
     return nullptr;
 
+  // Correctly set AuxTarget. The code is borrowed from
+  // `CompilerInstance::ExecuteAction(FrontendAction &)` inside
+  // "clang/lib/Frontend/CompilerInstance.cpp"
+  if ((Clang->getLangOpts().CUDA || Clang->getLangOpts().OpenMPIsDevice ||
+       Clang->getLangOpts().SYCLIsDevice) &&
+      !Clang->getFrontendOpts().AuxTriple.empty()) {
+    auto TO = std::make_shared<TargetOptions>();
+    TO->Triple = llvm::Triple::normalize(Clang->getFrontendOpts().AuxTriple);
+    if (Clang->getFrontendOpts().AuxTargetCPU)
+      TO->CPU = Clang->getFrontendOpts().AuxTargetCPU.getValue();
+    if (Clang->getFrontendOpts().AuxTargetFeatures)
+      TO->FeaturesAsWritten =
+          Clang->getFrontendOpts().AuxTargetFeatures.getValue();
+    TO->HostTriple = Clang->getTarget().getTriple().str();
+    Clang->setAuxTarget(
+        TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), TO));
+  }
+
+  // Inform the target of the language options.
+  //
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  Clang->getTarget().adjust(Clang->getLangOpts());
+
+  if (auto *Aux = Clang->getAuxTarget())
+    Clang->getTarget().setAuxTarget(Aux);
+
   // RemappedFileBuffers will handle the lifetime of the Buffer pointer,
   // release it.
   Buffer.release();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to