[clang-tools-extra] 14a7296 - [clang][clangd] Avoid inconsistent target creation
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 6 08:24:45 PDT 2021
Author: oToToT
Date: 2021-04-06T23:23:34+08:00
New Revision: 14a7296c0120913e949739e4e90ea5a5f1bd8af1
URL: https://github.com/llvm/llvm-project/commit/14a7296c0120913e949739e4e90ea5a5f1bd8af1
DIFF: https://github.com/llvm/llvm-project/commit/14a7296c0120913e949739e4e90ea5a5f1bd8af1.diff
LOG: [clang][clangd] Avoid inconsistent target creation
As proposed in D97109, I tried to make target creation consistent in `clang` and `clangd` by replacing the original procedure with a single function introduced in D97493.
This also helps `clangd` works with CUDA, OpenMP, etc.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D98128
Added:
Modified:
clang-tools-extra/clangd/Compiler.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index bcae67d82050..0a1e43d80864 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -118,9 +118,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
VFS = VFSWithRemapping;
Clang->createFileManager(VFS);
- Clang->setTarget(TargetInfo::CreateTargetInfo(
- Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
- if (!Clang->hasTarget())
+ if (!Clang->createTarget())
return nullptr;
// RemappedFileBuffers will handle the lifetime of the Buffer pointer,
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index e7a87dc6b23c..988090a8b1b1 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1150,17 +1150,9 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
Clang->setDiagnostics(&getDiagnostics());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(
- Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
- if (!Clang->hasTarget())
+ if (!Clang->createTarget())
return true;
- // 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());
-
assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
@@ -1568,17 +1560,9 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
Clang->setDiagnostics(&AST->getDiagnostics());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(
- Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
- if (!Clang->hasTarget())
+ if (!Clang->createTarget())
return nullptr;
- // 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());
-
assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
@@ -2194,19 +2178,11 @@ void ASTUnit::CodeComplete(
ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(
- Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
- if (!Clang->hasTarget()) {
+ if (!Clang->createTarget()) {
Clang->setInvocation(nullptr);
return;
}
- // 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());
-
assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 77b93713ce68..af82ab3f5558 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -365,17 +365,9 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
Clang->setDiagnostics(&Diagnostics);
// Create the target instance.
- Clang->setTarget(TargetInfo::CreateTargetInfo(
- Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
- if (!Clang->hasTarget())
+ if (!Clang->createTarget())
return BuildPreambleError::CouldntCreateTargetInfo;
- // 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 (Clang->getFrontendOpts().Inputs.size() != 1 ||
Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
InputKind::Source ||
More information about the cfe-commits
mailing list