[clang] [clang-tools-extra] [lldb] [clang][frontend] Require invocation to construct `CompilerInstance` (PR #137668)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 28 09:59:33 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang-tools-extra/clang-include-fixer/IncludeFixer.cpp clang-tools-extra/clangd/Compiler.cpp clang-tools-extra/include-cleaner/unittests/RecordTest.cpp clang/include/clang/Frontend/CompilerInstance.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/ChainedIncludesSource.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/PrecompiledPreamble.cpp clang/lib/Frontend/Rewrite/FrontendActions.cpp clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp clang/lib/Testing/TestAST.cpp clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp clang/lib/Tooling/Tooling.cpp clang/tools/clang-import-test/clang-import-test.cpp clang/tools/driver/cc1_main.cpp clang/unittests/AST/ExternalASTSourceTest.cpp clang/unittests/Frontend/CodeGenActionTest.cpp clang/unittests/Frontend/CompilerInstanceTest.cpp clang/unittests/Frontend/FrontendActionTest.cpp clang/unittests/Frontend/OutputStreamTest.cpp clang/unittests/Sema/SemaNoloadLookupTest.cpp clang/unittests/Serialization/ForceCheckFileInputTest.cpp clang/unittests/Serialization/LoadSpecLazilyTest.cpp clang/unittests/Serialization/ModuleCacheTest.cpp clang/unittests/Serialization/NoCommentsTest.cpp clang/unittests/Serialization/PreambleInNamedModulesTest.cpp clang/unittests/Serialization/VarDeclConstantInitTest.cpp clang/unittests/Support/TimeProfilerTest.cpp clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp clang/unittests/Tooling/Syntax/TokensTest.cpp clang/unittests/Tooling/Syntax/TreeTestBase.cpp lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 4832478d0..70f9b66b9 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -454,8 +454,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
   PreprocessorOpts.GeneratePreamble = true;
 
   // Create the compiler instance to use for building the precompiled preamble.
-  auto Clang = std::make_unique<CompilerInstance>(
-      std::move(PreambleInvocation), std::move(PCHContainerOps));
+  auto Clang = std::make_unique<CompilerInstance>(std::move(PreambleInvocation),
+                                                  std::move(PCHContainerOps));
 
   // Recover resources if we crash before exiting this method.
   llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance> CICleanup(
diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
index 3c8fc5994..f955845c9 100644
--- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -242,9 +242,9 @@ public:
     (*OS) << '\n';
 
     // Rewrite the contents of the module in a separate compiler instance.
-    CompilerInstance Instance(std::make_shared<CompilerInvocation>(CI.getInvocation()),
-                              CI.getPCHContainerOperations(),
-                              &CI.getModuleCache());
+    CompilerInstance Instance(
+        std::make_shared<CompilerInvocation>(CI.getInvocation()),
+        CI.getPCHContainerOperations(), &CI.getModuleCache());
     Instance.createDiagnostics(
         CI.getVirtualFileSystem(),
         new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index 187528532..0e2c91823 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -242,8 +242,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
                       diag::Severity::Remark, {});
 
   auto Invocation = std::make_shared<CompilerInvocation>();
-  bool Success = CompilerInvocation::CreateFromArgs(*Invocation,
-                                                    Argv, Diags, Argv0);
+  bool Success =
+      CompilerInvocation::CreateFromArgs(*Invocation, Argv, Diags, Argv0);
 
   auto Clang = std::make_unique<CompilerInstance>(std::move(Invocation),
                                                   std::move(PCHOps));
diff --git a/clang/unittests/AST/ExternalASTSourceTest.cpp b/clang/unittests/AST/ExternalASTSourceTest.cpp
index 50df8b5ba..807bab1b3 100644
--- a/clang/unittests/AST/ExternalASTSourceTest.cpp
+++ b/clang/unittests/AST/ExternalASTSourceTest.cpp
@@ -44,8 +44,7 @@ private:
   IntrusiveRefCntPtr<ExternalASTSource> Source;
 };
 
-bool testExternalASTSource(ExternalASTSource *Source,
-                           StringRef FileContents) {
+bool testExternalASTSource(ExternalASTSource *Source, StringRef FileContents) {
 
   auto Invocation = std::make_shared<CompilerInvocation>();
   Invocation->getPreprocessorOpts().addRemappedFile(
@@ -64,7 +63,6 @@ bool testExternalASTSource(ExternalASTSource *Source,
   return Compiler.ExecuteAction(Action);
 }
 
-
 // Ensure that a failed name lookup into an external source only occurs once.
 TEST(ExternalASTSourceTest, FailedLookupOccursOnce) {
   struct TestSource : ExternalASTSource {

``````````

</details>


https://github.com/llvm/llvm-project/pull/137668


More information about the cfe-commits mailing list