oToToT created this revision. oToToT added reviewers: sammccall, rsmith, ilya-biryukov. oToToT added projects: clang, clang-tools-extra. Herald added subscribers: usaxena95, kadircet, arphaman. oToToT requested review of this revision. Herald added subscribers: cfe-commits, sstefan1, MaskRay. Herald added a reviewer: jdoerfert.
As proposed in D97109 <https://reviews.llvm.org/D97109>, I tried to make target creation consistent in `clang` and `clangd` by replacing the original procedure with a single function introduced in D97493 <https://reviews.llvm.org/D97493>. This also helps `clangd` works with CUDA, OpenMP, etc. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98128 Files: clang-tools-extra/clangd/Compiler.cpp clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/PrecompiledPreamble.cpp
Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -365,17 +365,9 @@ 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 || Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -1149,18 +1149,9 @@ // otherwise be dropped. 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 +1559,9 @@ 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 +2177,11 @@ 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() == Index: clang-tools-extra/clangd/Compiler.cpp =================================================================== --- clang-tools-extra/clangd/Compiler.cpp +++ clang-tools-extra/clangd/Compiler.cpp @@ -118,9 +118,7 @@ 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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits